diff options
Diffstat (limited to 'jsonrpc/src/main/java/com/orbekk/rpc/Client.java')
-rw-r--r-- | jsonrpc/src/main/java/com/orbekk/rpc/Client.java | 60 |
1 files changed, 43 insertions, 17 deletions
diff --git a/jsonrpc/src/main/java/com/orbekk/rpc/Client.java b/jsonrpc/src/main/java/com/orbekk/rpc/Client.java index 99abf93..ea63fd7 100644 --- a/jsonrpc/src/main/java/com/orbekk/rpc/Client.java +++ b/jsonrpc/src/main/java/com/orbekk/rpc/Client.java @@ -1,32 +1,58 @@ package com.orbekk.rpc; +import com.googlecode.jsonrpc4j.JsonRpcServer; +import com.orbekk.same.ConnectionManagerImpl; +import com.orbekk.same.SameState; +import com.orbekk.same.SameService; +import com.orbekk.same.SameServiceImpl; import java.net.MalformedURLException; import java.net.URL; - -import com.orbekk.same.SameService; -import com.googlecode.jsonrpc4j.JsonRpcHttpClient; -import com.googlecode.jsonrpc4j.ProxyUtil; +import org.eclipse.jetty.server.Server; public class Client { public static void main(String[] args) { - if (args.length < 2) { - System.err.println("Arguments: networkAddress port"); + if (args.length < 4) { + System.err.println("Arguments: port clientId thisNetworkName " + + "remoteNetworkAddr"); System.exit(1); } - String networkAddress = args[0]; - int port = Integer.parseInt(args[1]); - JsonRpcHttpClient client = null; + int port = Integer.parseInt(args[0]); + String clientId = args[1]; + String networkName = args[2]; + String remoteAddr = args[3]; + + ConnectionManagerImpl connections = new ConnectionManagerImpl(); + + SameState sameState = new SameState(networkName, clientId, + connections); + sameState.start(); + + SameServiceImpl service = new SameServiceImpl(sameState); + JsonRpcServer jsonServer = new JsonRpcServer(service, + SameService.class); + + Server server = new Server(port); + RpcHandler rpcHandler = new RpcHandler(jsonServer, service); + server.setHandler(rpcHandler); + try { - client = new JsonRpcHttpClient(new URL(networkAddress)); - } catch (MalformedURLException e) { + server.start(); + } catch (Exception e) { + System.out.println("Could not start jetty server."); e.printStackTrace(); } - SameService service = ProxyUtil.createProxy( - client.getClass().getClassLoader(), - SameService.class, - client); - service.notifyNetwork("NoNetwork"); - service.participateNetwork("FirstNetwork", port); + + SameService remoteService = connections.getConnection(remoteAddr); + remoteService.notifyNetwork("NoNetwork"); + remoteService.participateNetwork("FirstNetwork", + sameState.getClientId(), "", port); + + try { + server.join(); + } catch (InterruptedException e) { + System.out.println("Interrupt"); + } + } } |