summaryrefslogtreecommitdiff
path: root/same/src/main
diff options
context:
space:
mode:
authorKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-02-06 15:22:13 +0100
committerKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-02-06 15:22:13 +0100
commitc0ea57d3692e587e78c80034b7bc4336a948cd48 (patch)
tree40b03353292d8947e2d76dca9c785eab5829e0a0 /same/src/main
parentb5919a813f1ec6a4b6fe8ca407ec12a107e688e3 (diff)
Support clients in generic App.
Diffstat (limited to 'same/src/main')
-rw-r--r--same/src/main/java/com/orbekk/same/App.java1
-rw-r--r--same/src/main/java/com/orbekk/same/ClientApp.java28
-rw-r--r--same/src/main/java/com/orbekk/same/ClientServiceImpl.java1
-rw-r--r--same/src/main/java/com/orbekk/same/SameController.java20
-rw-r--r--same/src/main/resources/client.properties.example4
-rw-r--r--same/src/main/resources/master.properties.example1
6 files changed, 6 insertions, 49 deletions
diff --git a/same/src/main/java/com/orbekk/same/App.java b/same/src/main/java/com/orbekk/same/App.java
index 2416899..2955311 100644
--- a/same/src/main/java/com/orbekk/same/App.java
+++ b/same/src/main/java/com/orbekk/same/App.java
@@ -13,6 +13,7 @@ public class App {
SameController controller = SameController.create(configuration);
try {
controller.start();
+ controller.joinNetwork(configuration.get("masterUrl"));
controller.join();
} catch (Exception e) {
logger.error("Error in App.", e);
diff --git a/same/src/main/java/com/orbekk/same/ClientApp.java b/same/src/main/java/com/orbekk/same/ClientApp.java
deleted file mode 100644
index 5a57fcd..0000000
--- a/same/src/main/java/com/orbekk/same/ClientApp.java
+++ /dev/null
@@ -1,28 +0,0 @@
-package com.orbekk.same;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.orbekk.same.config.Configuration;
-
-public class ClientApp {
- private Logger logger = LoggerFactory.getLogger(getClass());
-
- public void run(Configuration configuration) {
- String networkName = configuration.get("networkName");
- String masterUrl = configuration.get("masterUrl");
- SameController controller = SameController.create(configuration);
- try {
- controller.start();
- } catch (Exception e) {
- logger.error("Failed to start Same", e);
- }
- controller.joinNetwork(masterUrl);
- controller.join();
- }
-
- public static void main(String[] args) {
- Configuration configuration = Configuration.loadOrDie();
- (new ClientApp()).run(configuration);
- }
-}
diff --git a/same/src/main/java/com/orbekk/same/ClientServiceImpl.java b/same/src/main/java/com/orbekk/same/ClientServiceImpl.java
index 0854458..c503919 100644
--- a/same/src/main/java/com/orbekk/same/ClientServiceImpl.java
+++ b/same/src/main/java/com/orbekk/same/ClientServiceImpl.java
@@ -77,6 +77,7 @@ public class ClientServiceImpl implements DiscoveryListener {
}
public void joinNetwork(String masterUrl) {
+ logger.info("joinNetwork({})", masterUrl);
MasterService master = connections.getMaster(masterUrl);
state.clear();
try {
diff --git a/same/src/main/java/com/orbekk/same/SameController.java b/same/src/main/java/com/orbekk/same/SameController.java
index d898c1d..44e1721 100644
--- a/same/src/main/java/com/orbekk/same/SameController.java
+++ b/same/src/main/java/com/orbekk/same/SameController.java
@@ -99,26 +99,8 @@ public class SameController {
}
}
- 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) {
- boolean hasUrl = tryGetUrl(url);
- if (hasUrl) {
- client.joinNetwork(url + "MasterService.json");
- }
+ client.joinNetwork(url);
}
public ClientServiceImpl getClient() {
diff --git a/same/src/main/resources/client.properties.example b/same/src/main/resources/client.properties.example
index 3afb217..9afff59 100644
--- a/same/src/main/resources/client.properties.example
+++ b/same/src/main/resources/client.properties.example
@@ -1,3 +1,3 @@
-networkName=ClientNetwork
-masterUrl=http://10.0.0.6:10010/
port=10011
+localIp=10.0.0.6
+masterUrl=http://10.0.0.6:10010/MasterService.json
diff --git a/same/src/main/resources/master.properties.example b/same/src/main/resources/master.properties.example
index f168f2c..89a0bec 100644
--- a/same/src/main/resources/master.properties.example
+++ b/same/src/main/resources/master.properties.example
@@ -1,2 +1,3 @@
port=10010
localIp=10.0.0.6
+masterUrl=http://10.0.0.6:10010/MasterService.json