summaryrefslogtreecommitdiff
path: root/same/src/main/java/com/orbekk
diff options
context:
space:
mode:
authorKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-01-26 19:44:44 +0100
committerKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-01-26 19:44:44 +0100
commit70ada562e71093faefe7001b49259f3329c7c959 (patch)
tree60deb4c93eb6d6b6bd0665b28e436a82882f71a5 /same/src/main/java/com/orbekk
parentb175f47fb5e0b92767e47f2bc47043da0258e2d4 (diff)
Client support in SameController.
Diffstat (limited to 'same/src/main/java/com/orbekk')
-rw-r--r--same/src/main/java/com/orbekk/same/SameController.java27
1 files changed, 25 insertions, 2 deletions
diff --git a/same/src/main/java/com/orbekk/same/SameController.java b/same/src/main/java/com/orbekk/same/SameController.java
index fa5ef9f..d7cc747 100644
--- a/same/src/main/java/com/orbekk/same/SameController.java
+++ b/same/src/main/java/com/orbekk/same/SameController.java
@@ -5,11 +5,13 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.googlecode.jsonrpc4j.JsonRpcServer;
+import com.orbekk.net.HttpUtil;
import com.orbekk.paxos.PaxosService;
import com.orbekk.paxos.PaxosServiceImpl;
public class SameController implements UrlReceiver {
private Logger logger = LoggerFactory.getLogger(getClass());
+ private int port;
private Server server;
private MasterServiceImpl master;
private ClientServiceImpl client;
@@ -35,7 +37,7 @@ public class SameController implements UrlReceiver {
JsonRpcServer jsonPaxos = new JsonRpcServer(paxos, PaxosService.class);
Server server = new Server(port);
- SameController controller = new SameController(server, master, client,
+ SameController controller = new SameController(port, server, master, client,
paxos);
RpcHandler rpcHandler = new RpcHandler(controller);
@@ -48,12 +50,15 @@ public class SameController implements UrlReceiver {
}
public SameController(
+ int port,
Server server,
MasterServiceImpl master,
ClientServiceImpl client,
PaxosServiceImpl paxos) {
+ this.port = port;
this.server = server;
this.master = master;
+ this.client = client;
this.paxos = paxos;
}
@@ -85,8 +90,26 @@ public class SameController implements UrlReceiver {
}
}
+ public boolean tryGetUrl(String serverUrl) {
+ int retries = 100;
+ while (client.getUrl() == null && retries > 0) {
+ HttpUtil.sendHttpRequest(serverUrl + "ping?port=" +
+ port);
+ try {
+ Thread.sleep(500);
+ } catch (InterruptedException e) {
+ return false;
+ }
+ retries -= 1;
+ }
+ return client.getUrl() != null;
+ }
+
public void joinNetwork(String url) {
- client.joinNetwork(url + "MasterService.json");
+ boolean hasUrl = tryGetUrl(url);
+ if (hasUrl) {
+ client.joinNetwork(url + "MasterService.json");
+ }
}
@Override