summaryrefslogtreecommitdiffstats
path: root/src/jrummikub/server
diff options
context:
space:
mode:
authorJannis Harder <harder@informatik.uni-luebeck.de>2011-06-22 01:08:54 +0200
committerJannis Harder <harder@informatik.uni-luebeck.de>2011-06-22 01:08:54 +0200
commit63013dc82cc8718e40e9557cfd83991e72d72dae (patch)
treedaea331d0adaa9de3bbfe509e4895b164681efb2 /src/jrummikub/server
parent8c6bf9781f0d1ebab406e403b0b8865f7b06b536 (diff)
downloadJRummikub-63013dc82cc8718e40e9557cfd83991e72d72dae.tar
JRummikub-63013dc82cc8718e40e9557cfd83991e72d72dae.zip
Integrated dedicated server
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@563 72836036-5685-4462-b002-a69064685172
Diffstat (limited to 'src/jrummikub/server')
-rw-r--r--src/jrummikub/server/DedicatedServer.java93
1 files changed, 69 insertions, 24 deletions
diff --git a/src/jrummikub/server/DedicatedServer.java b/src/jrummikub/server/DedicatedServer.java
index e27c74c..ae071f0 100644
--- a/src/jrummikub/server/DedicatedServer.java
+++ b/src/jrummikub/server/DedicatedServer.java
@@ -1,5 +1,6 @@
package jrummikub.server;
+import java.net.BindException;
import java.net.InetAddress;
import org.apache.vysper.mina.TCPEndpoint;
@@ -16,8 +17,8 @@ import org.apache.vysper.xmpp.server.XMPPServer;
* Implements a simple XMPP server with a global server password
*/
public class DedicatedServer {
- String serverPassword;
- String hostName;
+ private volatile String serverPassword;
+ private String hostName;
/**
* Creates a new dedicated server with the specified password
@@ -37,6 +38,25 @@ public class DedicatedServer {
}
/**
+ * Change the current server password
+ *
+ * @param password
+ * the new server password
+ */
+ public void setServerPassword(String password) {
+ serverPassword = password;
+ }
+
+ /**
+ * Get the current server password
+ *
+ * @return the current server password
+ */
+ public String getServerPassword() {
+ return serverPassword;
+ }
+
+ /**
* Getter for host name
*
* @return host name
@@ -46,31 +66,50 @@ public class DedicatedServer {
}
/**
- * Start the server, this blocks
+ * Result of server startup attempt
+ */
+ public enum ServerStatus {
+ /** Server successfully started */
+ STARTED,
+ /** Server already running on this machine */
+ ALREADY_RUNNING,
+ /** Other error */
+ ERROR
+ }
+
+ /**
+ * Start the server
*
- * @throws Exception
- * when there is an error during startup
+ * @return Whether we could start the server
*/
- public void start() throws Exception {
- XMPPServer server = new XMPPServer(hostName);
+ public ServerStatus start() {
+ try {
+ XMPPServer server = new XMPPServer(hostName);
- OpenStorageProviderRegistry providerRegistry = new OpenStorageProviderRegistry();
- providerRegistry.add(new ServerPasswordAuthorization());
- providerRegistry.add(new MemoryRosterManager());
- providerRegistry.add(new InMemoryRoomStorageProvider());
- providerRegistry.add(new InMemoryOccupantStorageProvider());
+ OpenStorageProviderRegistry providerRegistry = new OpenStorageProviderRegistry();
+ providerRegistry.add(new ServerPasswordAuthorization());
+ providerRegistry.add(new MemoryRosterManager());
+ providerRegistry.add(new InMemoryRoomStorageProvider());
+ providerRegistry.add(new InMemoryOccupantStorageProvider());
- server.setStorageProviderRegistry(providerRegistry);
- server.addEndpoint(new TCPEndpoint());
+ server.setStorageProviderRegistry(providerRegistry);
+ server.addEndpoint(new TCPEndpoint());
- server.setTLSCertificateInfo(
- getClass().getResource(
- "/jrummikub/resource/bogus_mina_tls.cert").openStream(),
- "boguspw");
+ server.setTLSCertificateInfo(
+ getClass().getResource(
+ "/jrummikub/resource/bogus_mina_tls.cert")
+ .openStream(), "boguspw");
- server.start();
- MUCModule muc = new MUCModule("play");
- server.addModule(muc);
+ server.start();
+ MUCModule muc = new MUCModule("play");
+ server.addModule(muc);
+ return ServerStatus.STARTED;
+ } catch (BindException e) {
+ return ServerStatus.ALREADY_RUNNING;
+ } catch (Exception e) {
+ e.printStackTrace();
+ return ServerStatus.ERROR;
+ }
}
@@ -95,15 +134,21 @@ public class DedicatedServer {
* Main for a simple command line dedicated server
*
* @param args
- * first argument specifies the server password, it is "jrummikub"
- * when none is specified
+ * first argument specifies the server password, it is
+ * "jrummikub" when none is specified
*/
public static void main(String[] args) {
DedicatedServer server = new DedicatedServer(args.length >= 1 ? args[0]
: "jrummikub");
System.out.println("Server hostname is " + server.getHostName());
try {
- server.start();
+ switch (server.start()) {
+ case ALREADY_RUNNING:
+ System.out.println("Server already running");
+ // fall through
+ case ERROR:
+ System.exit(1);
+ }
} catch (Exception e) {
e.printStackTrace();
}