summaryrefslogtreecommitdiff
path: root/same/src/main
diff options
context:
space:
mode:
authorKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-01-16 20:44:51 +0100
committerKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-01-16 20:44:51 +0100
commitcc712c76ad04b38380028bf1c1abbe31d01c2249 (patch)
treed15245c60c7ffc9358f3070ea08fbb7352a91ffa /same/src/main
parent27cc0e4dcd6281402072f83f1d611a48fa91d782 (diff)
Fix ping discovery.
Diffstat (limited to 'same/src/main')
-rw-r--r--same/src/main/java/com/orbekk/same/ClientApp.java21
-rw-r--r--same/src/main/java/com/orbekk/same/ClientServiceImpl.java8
2 files changed, 23 insertions, 6 deletions
diff --git a/same/src/main/java/com/orbekk/same/ClientApp.java b/same/src/main/java/com/orbekk/same/ClientApp.java
index cc97823..69997ca 100644
--- a/same/src/main/java/com/orbekk/same/ClientApp.java
+++ b/same/src/main/java/com/orbekk/same/ClientApp.java
@@ -5,12 +5,15 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.googlecode.jsonrpc4j.JsonRpcServer;
+import com.orbekk.net.HttpUtil;
public class ClientApp {
private Logger logger = LoggerFactory.getLogger(getClass());
private Server server;
- public void run(int port, String networkName) {
+ public void run(int port, String networkName, String masterUrl) {
+ logger.info("Starting client with port:{}, networkName:{}, masterUrl:{}",
+ new Object[]{port, networkName, masterUrl});
ConnectionManagerImpl connections = new ConnectionManagerImpl();
State state = new State(networkName);
Broadcaster broadcaster =
@@ -30,6 +33,15 @@ public class ClientApp {
logger.error("Could not start jetty server: {}", e);
}
+ while (client.getUrl() == null) {
+ HttpUtil.sendHttpRequest(masterUrl + "ping?port=" + port);
+ try {
+ Thread.sleep(500);
+ } catch (InterruptedException e) {
+ // Ignore interrupt in wait loop.
+ }
+ }
+
try {
server.join();
} catch (InterruptedException e) {
@@ -38,12 +50,13 @@ public class ClientApp {
}
public static void main(String[] args) {
- if (args.length < 1) {
- System.err.println("Usage: port networkName");
+ if (args.length < 3) {
+ System.err.println("Usage: port networkName masterUrl");
System.exit(1);
}
int port = Integer.parseInt(args[0]);
String networkName = args[1];
- (new ClientApp()).run(port, networkName);
+ String masterUrl = args[2];
+ (new ClientApp()).run(port, networkName, masterUrl);
}
}
diff --git a/same/src/main/java/com/orbekk/same/ClientServiceImpl.java b/same/src/main/java/com/orbekk/same/ClientServiceImpl.java
index 915840e..c648abd 100644
--- a/same/src/main/java/com/orbekk/same/ClientServiceImpl.java
+++ b/same/src/main/java/com/orbekk/same/ClientServiceImpl.java
@@ -26,8 +26,12 @@ public class ClientServiceImpl implements ClientService, UrlReceiver {
@Override
public void setUrl(String myUrl) {
- logger.info("My URL is {}.", myUrl);
- this.myUrl = myUrl;
+ this.myUrl = myUrl + "ClientService.json";
+ logger.info("My URL is {}.", this.myUrl);
+ }
+
+ public String getUrl() {
+ return myUrl;
}
State testGetState() {