summaryrefslogtreecommitdiff
path: root/same/src
diff options
context:
space:
mode:
authorKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-02-06 13:24:07 +0100
committerKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-02-06 13:24:07 +0100
commit73bfca1fa99a4b881f5a3c2b19386e86c77da6f9 (patch)
tree5530b3d19f420208d0327bd857056a77863db217 /same/src
parent7a6765d14402c8f7010b02f44021f9020af06497 (diff)
Get rid of UrlReceiver interface.
Diffstat (limited to 'same/src')
-rw-r--r--same/src/main/java/com/orbekk/same/ClientApp.java4
-rw-r--r--same/src/main/java/com/orbekk/same/ClientServiceImpl.java9
-rw-r--r--same/src/main/java/com/orbekk/same/MasterServiceImpl.java9
-rw-r--r--same/src/main/java/com/orbekk/same/SameController.java13
-rw-r--r--same/src/main/java/com/orbekk/same/UrlReceiver.java10
-rw-r--r--same/src/main/java/com/orbekk/same/http/RpcHandler.java69
6 files changed, 3 insertions, 111 deletions
diff --git a/same/src/main/java/com/orbekk/same/ClientApp.java b/same/src/main/java/com/orbekk/same/ClientApp.java
index 3e08567..5a57fcd 100644
--- a/same/src/main/java/com/orbekk/same/ClientApp.java
+++ b/same/src/main/java/com/orbekk/same/ClientApp.java
@@ -1,13 +1,9 @@
package com.orbekk.same;
-import org.eclipse.jetty.server.Server;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.googlecode.jsonrpc4j.JsonRpcServer;
-import com.orbekk.net.HttpUtil;
import com.orbekk.same.config.Configuration;
-import com.orbekk.same.http.RpcHandler;
public class ClientApp {
private Logger logger = LoggerFactory.getLogger(getClass());
diff --git a/same/src/main/java/com/orbekk/same/ClientServiceImpl.java b/same/src/main/java/com/orbekk/same/ClientServiceImpl.java
index 3ba8b04..a870372 100644
--- a/same/src/main/java/com/orbekk/same/ClientServiceImpl.java
+++ b/same/src/main/java/com/orbekk/same/ClientServiceImpl.java
@@ -11,8 +11,7 @@ import org.slf4j.LoggerFactory;
import com.orbekk.util.WorkQueue;
-public class ClientServiceImpl implements UrlReceiver,
- DiscoveryListener {
+public class ClientServiceImpl implements DiscoveryListener {
private Logger logger = LoggerFactory.getLogger(getClass());
private ConnectionManager connections;
private State state;
@@ -71,12 +70,6 @@ public class ClientServiceImpl implements UrlReceiver,
discoveryThread.interrupt();
}
- @Override
- public void setUrl(String myUrl) {
- this.myUrl = myUrl + "ClientService.json";
- logger.info("My URL is {}.", this.myUrl);
- }
-
public String getUrl() {
return myUrl;
}
diff --git a/same/src/main/java/com/orbekk/same/MasterServiceImpl.java b/same/src/main/java/com/orbekk/same/MasterServiceImpl.java
index 6387913..4a842ab 100644
--- a/same/src/main/java/com/orbekk/same/MasterServiceImpl.java
+++ b/same/src/main/java/com/orbekk/same/MasterServiceImpl.java
@@ -8,7 +8,7 @@ import org.slf4j.LoggerFactory;
import com.orbekk.same.State.Component;
-public class MasterServiceImpl implements MasterService, UrlReceiver, Runnable {
+public class MasterServiceImpl implements MasterService, Runnable {
private Logger logger = LoggerFactory.getLogger(getClass());
private final ConnectionManager connections;
private State state;
@@ -111,13 +111,6 @@ public class MasterServiceImpl implements MasterService, UrlReceiver, Runnable {
return updated;
}
- @Override
- public void setUrl(String url) {
- String myUrl = url + "MasterService.json";
- logger.info("Master URL is " + myUrl);
- state.update(".masterUrl", myUrl, 1);
- }
-
boolean _performWork() {
boolean worked = false;
worked |= _sendUpdatedComponents();
diff --git a/same/src/main/java/com/orbekk/same/SameController.java b/same/src/main/java/com/orbekk/same/SameController.java
index 503bfba..4c923d9 100644
--- a/same/src/main/java/com/orbekk/same/SameController.java
+++ b/same/src/main/java/com/orbekk/same/SameController.java
@@ -13,11 +13,10 @@ import com.orbekk.net.HttpUtil;
import com.orbekk.paxos.PaxosService;
import com.orbekk.paxos.PaxosServiceImpl;
import com.orbekk.same.config.Configuration;
-import com.orbekk.same.http.RpcHandler;
import com.orbekk.same.http.ServerBuilder;
import com.orbekk.same.http.StateServlet;
-public class SameController implements UrlReceiver {
+public class SameController {
private Logger logger = LoggerFactory.getLogger(getClass());
private int port;
private Server server;
@@ -119,16 +118,6 @@ public class SameController implements UrlReceiver {
}
}
- @Override
- public void setUrl(String url) {
- if (master != null) {
- master.setUrl(url);
- }
- if (client != null) {
- client.setUrl(url);
- }
- }
-
public ClientServiceImpl getClient() {
return client;
}
diff --git a/same/src/main/java/com/orbekk/same/UrlReceiver.java b/same/src/main/java/com/orbekk/same/UrlReceiver.java
deleted file mode 100644
index 31a0276..0000000
--- a/same/src/main/java/com/orbekk/same/UrlReceiver.java
+++ /dev/null
@@ -1,10 +0,0 @@
-package com.orbekk.same;
-
-/**
- * An interface to get notified of the URL to this computer.
- *
- * This interface is used to reliably obtain the URL of this host.
- */
-public interface UrlReceiver {
- void setUrl(String url);
-}
diff --git a/same/src/main/java/com/orbekk/same/http/RpcHandler.java b/same/src/main/java/com/orbekk/same/http/RpcHandler.java
deleted file mode 100644
index 56970d1..0000000
--- a/same/src/main/java/com/orbekk/same/http/RpcHandler.java
+++ /dev/null
@@ -1,69 +0,0 @@
-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;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import org.eclipse.jetty.server.Request;
-import org.eclipse.jetty.server.handler.AbstractHandler;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class RpcHandler extends AbstractHandler {
- private Logger logger = LoggerFactory.getLogger(getClass());
- private UrlReceiver urlReceiver;
- private Map<String, JsonRpcServer> rpcServers =
- new HashMap<String, JsonRpcServer>();
-
- 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,
- HttpServletRequest request, HttpServletResponse response)
- throws IOException, ServletException {
- logger.info("Handling request to target: " + target);
-
- if (urlReceiver != null) {
- String sameServiceUrl = "http://" + request.getLocalAddr() +
- ":" + request.getLocalPort() + "/";
- urlReceiver.setUrl(sameServiceUrl);
- urlReceiver = null;
- }
-
- if (target.equals("/ping")) {
- int remotePort = Integer.parseInt(request.getParameter("port"));
- String pongUrl = "http://" + request.getRemoteAddr() + ":" +
- 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 {
- JsonRpcServer server = rpcServers.get(target);
- if (server != null) {
- server.handle(request, response);
- baseRequest.setHandled(true);
- }
- }
- }
-}