diff options
Diffstat (limited to 'same/src/main/java/com')
-rw-r--r-- | same/src/main/java/com/orbekk/same/MasterApp.java | 46 |
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); + } +} |