summaryrefslogtreecommitdiff
path: root/same/src
diff options
context:
space:
mode:
Diffstat (limited to 'same/src')
-rw-r--r--same/src/main/java/com/orbekk/same/http/HandlerFactory.java50
-rw-r--r--same/src/main/java/com/orbekk/same/http/RpcHandler.java (renamed from same/src/main/java/com/orbekk/same/RpcHandler.java)5
2 files changed, 53 insertions, 2 deletions
diff --git a/same/src/main/java/com/orbekk/same/http/HandlerFactory.java b/same/src/main/java/com/orbekk/same/http/HandlerFactory.java
new file mode 100644
index 0000000..5d5d34c
--- /dev/null
+++ b/same/src/main/java/com/orbekk/same/http/HandlerFactory.java
@@ -0,0 +1,50 @@
+package com.orbekk.same.http;
+
+import org.eclipse.jetty.server.Handler;
+import org.eclipse.jetty.server.handler.ContextHandler.Context;
+import org.eclipse.jetty.server.handler.HandlerList;
+import org.eclipse.jetty.servlet.ServletContextHandler;
+import org.eclipse.jetty.servlet.ServletHandler;
+import org.eclipse.jetty.servlet.ServletHolder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.googlecode.jsonrpc4j.JsonRpcServer;
+import com.orbekk.paxos.PaxosService;
+import com.orbekk.same.ClientService;
+import com.orbekk.same.MasterService;
+
+public class HandlerFactory {
+ Logger logger = LoggerFactory.getLogger(getClass());
+
+ public Handler createServletHandler() {
+ logger.info("Creating servlet handler.");
+ ServletContextHandler context = new ServletContextHandler(
+ ServletContextHandler.SESSIONS);
+ context.setContextPath("/*");
+ context.addServlet(new ServletHolder(new StateServlet()), "/*");
+ return context;
+ }
+
+ public RpcHandler createRpcHandler(MasterService master,
+ ClientService client, PaxosService paxos) {
+ RpcHandler rpcHandler = new RpcHandler(null);
+ rpcHandler.addRpcServer("/MasterService.json",
+ new JsonRpcServer(master, MasterService.class));
+ rpcHandler.addRpcServer("/ClientService.json",
+ new JsonRpcServer(client, ClientService.class));
+ rpcHandler.addRpcServer("/PaxosService.json",
+ new JsonRpcServer(paxos, PaxosService.class));
+ return rpcHandler;
+ }
+
+ public Handler createMainHandler(RpcHandler rpcHandler,
+ Handler servletHandler) {
+ HandlerList handler = new HandlerList();
+ handler.addHandler(rpcHandler);
+ handler.addHandler(servletHandler);
+
+ return handler;
+ }
+
+}
diff --git a/same/src/main/java/com/orbekk/same/RpcHandler.java b/same/src/main/java/com/orbekk/same/http/RpcHandler.java
index cddb307..56970d1 100644
--- a/same/src/main/java/com/orbekk/same/RpcHandler.java
+++ b/same/src/main/java/com/orbekk/same/http/RpcHandler.java
@@ -1,7 +1,9 @@
-package com.orbekk.same;
+package com.orbekk.same.http;
import com.googlecode.jsonrpc4j.JsonRpcServer;
import com.orbekk.net.HttpUtil;
+import com.orbekk.same.UrlReceiver;
+
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
@@ -15,7 +17,6 @@ import org.slf4j.LoggerFactory;
public class RpcHandler extends AbstractHandler {
private Logger logger = LoggerFactory.getLogger(getClass());
- private JsonRpcServer rpcServer = null;
private UrlReceiver urlReceiver;
private Map<String, JsonRpcServer> rpcServers =
new HashMap<String, JsonRpcServer>();