summaryrefslogtreecommitdiff
path: root/same/src/main/java
diff options
context:
space:
mode:
authorKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-01-16 20:34:44 +0100
committerKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-01-16 20:34:44 +0100
commit27cc0e4dcd6281402072f83f1d611a48fa91d782 (patch)
tree54c020a17e74a4e9fcda1f04b96b39a7678cb941 /same/src/main/java
parent306596d6c7cc65bbdb50d8e1055244103bcd7511 (diff)
Add ClientApp – a server hosting a ClientService.
Diffstat (limited to 'same/src/main/java')
-rw-r--r--same/src/main/java/com/orbekk/same/ClientApp.java49
1 files changed, 49 insertions, 0 deletions
diff --git a/same/src/main/java/com/orbekk/same/ClientApp.java b/same/src/main/java/com/orbekk/same/ClientApp.java
new file mode 100644
index 0000000..cc97823
--- /dev/null
+++ b/same/src/main/java/com/orbekk/same/ClientApp.java
@@ -0,0 +1,49 @@
+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 ClientApp {
+ private Logger logger = LoggerFactory.getLogger(getClass());
+ private Server server;
+
+ public void run(int port, String networkName) {
+ ConnectionManagerImpl connections = new ConnectionManagerImpl();
+ State state = new State(networkName);
+ Broadcaster broadcaster =
+ BroadcasterImpl.getDefaultBroadcastRunner(connections);
+ MasterServiceImpl master = new MasterServiceImpl(state, connections,
+ broadcaster);
+ ClientServiceImpl client = new ClientServiceImpl(state, connections);
+
+ JsonRpcServer jsonServer = new JsonRpcServer(client, ClientService.class);
+ server = new Server(port);
+ RpcHandler rpcHandler = new RpcHandler(jsonServer, client);
+ 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 networkName");
+ System.exit(1);
+ }
+ int port = Integer.parseInt(args[0]);
+ String networkName = args[1];
+ (new ClientApp()).run(port, networkName);
+ }
+}