diff options
author | Kjetil Ørbekk <kjetil.orbekk@gmail.com> | 2012-01-27 14:03:54 +0100 |
---|---|---|
committer | Kjetil Ørbekk <kjetil.orbekk@gmail.com> | 2012-01-27 14:03:54 +0100 |
commit | f1be615e30f4a6832bd0b805e155c0775b624964 (patch) | |
tree | 3c1edc9b91e5bb0f43fcdb2bce93790cf4f9fd2d /same | |
parent | 3d0ddd70342bee8826997e9a2343a5741e243a0d (diff) |
Client answers discovery events.
Diffstat (limited to 'same')
-rw-r--r-- | same/src/main/java/com/orbekk/same/ClientServiceImpl.java | 16 | ||||
-rw-r--r-- | same/src/test/java/com/orbekk/same/ClientServiceImplTest.java | 9 |
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"); + } } |