summaryrefslogtreecommitdiff
path: root/same/src/main/java
diff options
context:
space:
mode:
authorKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-01-16 20:28:19 +0100
committerKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-01-16 20:28:19 +0100
commit3068788fbc82fe69ec28d143efc321a06056fb90 (patch)
treedf5533db352feae3be6a8cbb546ea3343c91b192 /same/src/main/java
parent2ac5ac24a954f5edde530f5895961d8897e3e031 (diff)
Add MasterApp – a MasterService server.
Diffstat (limited to 'same/src/main/java')
-rw-r--r--same/src/main/java/com/orbekk/same/MasterApp.java46
1 files changed, 46 insertions, 0 deletions
diff --git a/same/src/main/java/com/orbekk/same/MasterApp.java b/same/src/main/java/com/orbekk/same/MasterApp.java
new file mode 100644
index 0000000..c4154da
--- /dev/null
+++ b/same/src/main/java/com/orbekk/same/MasterApp.java
@@ -0,0 +1,46 @@
+package com.orbekk.same;
+
+import org.eclipse.jetty.server.Server;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.googlecode.jsonrpc4j.JsonRpcServer;
+
+public class MasterApp {
+ private Logger logger = LoggerFactory.getLogger(getClass());
+ private Server server;
+
+ public void run(int port) {
+ ConnectionManagerImpl connections = new ConnectionManagerImpl();
+ State state = new State("MasterNetwork");
+ Broadcaster broadcaster =
+ BroadcasterImpl.getDefaultBroadcastRunner(connections);
+ MasterServiceImpl master = new MasterServiceImpl(state, connections,
+ broadcaster);
+ JsonRpcServer jsonServer = new JsonRpcServer(master, MasterService.class);
+ server = new Server(port);
+ RpcHandler rpcHandler = new RpcHandler(jsonServer, master);
+ server.setHandler(rpcHandler);
+
+ try {
+ server.start();
+ } catch (Exception e) {
+ logger.error("Could not start jetty server: {}", e);
+ }
+
+ try {
+ server.join();
+ } catch (InterruptedException e) {
+ logger.info("Received exception. Exiting. {}", e);
+ }
+ }
+
+ public static void main(String[] args) {
+ if (args.length < 1) {
+ System.err.println("Usage: port");
+ System.exit(1);
+ }
+ int port = Integer.parseInt(args[0]);
+ (new MasterApp()).run(port);
+ }
+}