summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--same/src/main/java/com/orbekk/same/ClientServiceImpl.java16
-rw-r--r--same/src/test/java/com/orbekk/same/ClientServiceImplTest.java9
2 files changed, 24 insertions, 1 deletions
diff --git a/same/src/main/java/com/orbekk/same/ClientServiceImpl.java b/same/src/main/java/com/orbekk/same/ClientServiceImpl.java
index 8aaaa95..b46dbfb 100644
--- a/same/src/main/java/com/orbekk/same/ClientServiceImpl.java
+++ b/same/src/main/java/com/orbekk/same/ClientServiceImpl.java
@@ -4,7 +4,8 @@ import org.codehaus.jackson.type.TypeReference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class ClientServiceImpl implements ClientService, UrlReceiver {
+public class ClientServiceImpl implements ClientService, UrlReceiver,
+ DiscoveryListener {
private Logger logger = LoggerFactory.getLogger(getClass());
private ConnectionManager connections;
private State state;
@@ -104,4 +105,17 @@ public class ClientServiceImpl implements ClientService, UrlReceiver {
public void setNetworkListener(NetworkNotificationListener listener) {
this.networkListener = listener;
}
+
+ @Override
+ public void discover(String url) {
+ if (!url.equals(myUrl)) {
+ try {
+ connections.getClient(url + "/ClientService.json")
+ .notifyNetwork(state.getDataOf(".networkName"),
+ state.getDataOf(".masterUrl"));
+ } catch (Exception e) {
+ logger.warn("Failed to contact new client {}", url, e);
+ }
+ }
+ }
}
diff --git a/same/src/test/java/com/orbekk/same/ClientServiceImplTest.java b/same/src/test/java/com/orbekk/same/ClientServiceImplTest.java
index 39c0e7c..69e4511 100644
--- a/same/src/test/java/com/orbekk/same/ClientServiceImplTest.java
+++ b/same/src/test/java/com/orbekk/same/ClientServiceImplTest.java
@@ -24,4 +24,13 @@ public class ClientServiceImplTest {
client.notifyNetwork("MyNetwork", "MasterUrl");
verify(listener).notifyNetwork("MyNetwork", "MasterUrl");
}
+
+ @Test public void discover() {
+ client.setState(".masterUrl", "master", 1);
+ ClientServiceImpl mockClient = mock(ClientServiceImpl.class);
+ connections.clientMap.put("mockClient/ClientService.json",
+ mockClient);
+ client.discover("mockClient");
+ verify(mockClient).notifyNetwork("ClientNetwork", "master");
+ }
}