summaryrefslogtreecommitdiff
path: root/same
diff options
context:
space:
mode:
Diffstat (limited to 'same')
-rw-r--r--same/src/main/java/com/orbekk/same/ClientApp.java3
-rw-r--r--same/src/main/java/com/orbekk/same/MasterApp.java3
-rw-r--r--same/src/main/java/com/orbekk/same/RpcHandler.java29
3 files changed, 27 insertions, 8 deletions
diff --git a/same/src/main/java/com/orbekk/same/ClientApp.java b/same/src/main/java/com/orbekk/same/ClientApp.java
index 64fad20..a98b719 100644
--- a/same/src/main/java/com/orbekk/same/ClientApp.java
+++ b/same/src/main/java/com/orbekk/same/ClientApp.java
@@ -27,7 +27,8 @@ public class ClientApp {
JsonRpcServer jsonServer = new JsonRpcServer(client, ClientService.class);
server = new Server(port);
- RpcHandler rpcHandler = new RpcHandler(jsonServer, client);
+ RpcHandler rpcHandler = new RpcHandler(client);
+ rpcHandler.addRpcServer("/ClientService.json", jsonServer);
server.setHandler(rpcHandler);
try {
diff --git a/same/src/main/java/com/orbekk/same/MasterApp.java b/same/src/main/java/com/orbekk/same/MasterApp.java
index ee5f50b..428336c 100644
--- a/same/src/main/java/com/orbekk/same/MasterApp.java
+++ b/same/src/main/java/com/orbekk/same/MasterApp.java
@@ -21,7 +21,8 @@ public class MasterApp {
broadcaster);
JsonRpcServer jsonServer = new JsonRpcServer(master, MasterService.class);
server = new Server(port);
- RpcHandler rpcHandler = new RpcHandler(jsonServer, master);
+ RpcHandler rpcHandler = new RpcHandler(master);
+ rpcHandler.addRpcServer("/MasterService.json", jsonServer);
server.setHandler(rpcHandler);
Thread masterThread = new Thread(master);
diff --git a/same/src/main/java/com/orbekk/same/RpcHandler.java b/same/src/main/java/com/orbekk/same/RpcHandler.java
index 7b2adb3..cddb307 100644
--- a/same/src/main/java/com/orbekk/same/RpcHandler.java
+++ b/same/src/main/java/com/orbekk/same/RpcHandler.java
@@ -3,6 +3,8 @@ package com.orbekk.same;
import com.googlecode.jsonrpc4j.JsonRpcServer;
import com.orbekk.net.HttpUtil;
import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -13,14 +15,24 @@ import org.slf4j.LoggerFactory;
public class RpcHandler extends AbstractHandler {
private Logger logger = LoggerFactory.getLogger(getClass());
- private JsonRpcServer rpcServer;
+ private JsonRpcServer rpcServer = null;
private UrlReceiver urlReceiver;
+ private Map<String, JsonRpcServer> rpcServers =
+ new HashMap<String, JsonRpcServer>();
- public RpcHandler(JsonRpcServer rpcServer,
- UrlReceiver urlReceiver) {
- this.rpcServer = rpcServer;
+ public RpcHandler(UrlReceiver urlReceiver) {
this.urlReceiver = urlReceiver;
}
+
+ /**
+ * Add an RpcServer to this Handler.
+ *
+ * @param url the base url of the service, e.g.
+ * /MyService.json
+ */
+ public void addRpcServer(String url, JsonRpcServer rpcServer) {
+ rpcServers.put(url, rpcServer);
+ }
@Override
public synchronized void handle(String target, Request baseRequest,
@@ -41,11 +53,16 @@ public class RpcHandler extends AbstractHandler {
remotePort + "/pong";
logger.info("Got ping. Sending pong to {}", pongUrl);
HttpUtil.sendHttpRequest(pongUrl);
+ baseRequest.setHandled(true);
} else if (target.equals("/pong")) {
logger.info("Received pong from {}", request.getRemoteAddr());
+ baseRequest.setHandled(true);
} else {
- rpcServer.handle(request, response);
+ JsonRpcServer server = rpcServers.get(target);
+ if (server != null) {
+ server.handle(request, response);
+ baseRequest.setHandled(true);
+ }
}
- baseRequest.setHandled(true);
}
}