summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-01-27 13:47:26 +0100
committerKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-01-27 13:47:26 +0100
commit3d0ddd70342bee8826997e9a2343a5741e243a0d (patch)
treea464317e76395d2177010ebbdd2487c0b52e07c6
parent52c1e7a6643d4a010c5571f565386440e17fe5e6 (diff)
ClientService supports network discovery.
-rw-r--r--same/src/main/java/com/orbekk/same/ClientServiceImpl.java19
-rw-r--r--same/src/main/java/com/orbekk/same/NetworkNotificationListener.java5
-rw-r--r--same/src/test/java/com/orbekk/same/ClientServiceImplTest.java9
3 files changed, 28 insertions, 5 deletions
diff --git a/same/src/main/java/com/orbekk/same/ClientServiceImpl.java b/same/src/main/java/com/orbekk/same/ClientServiceImpl.java
index 43c8b2f..8aaaa95 100644
--- a/same/src/main/java/com/orbekk/same/ClientServiceImpl.java
+++ b/same/src/main/java/com/orbekk/same/ClientServiceImpl.java
@@ -9,7 +9,8 @@ public class ClientServiceImpl implements ClientService, UrlReceiver {
private ConnectionManager connections;
private State state;
private String myUrl = null;
- private StateChangedListener listener;
+ private StateChangedListener stateListener;
+ private NetworkNotificationListener networkListener;
public ClientServiceImpl(State state, ConnectionManager connections) {
this.state = state;
@@ -18,15 +19,19 @@ public class ClientServiceImpl implements ClientService, UrlReceiver {
@Override
public void notifyNetwork(String networkName, String masterUrl) {
- logger.error("NotifyNetwork not yet implemented.");
+ logger.info("NotifyNetwork(networkName={}, masterUrl={})",
+ networkName, masterUrl);
+ if (networkListener != null) {
+ networkListener.notifyNetwork(networkName, masterUrl);
+ }
}
@Override
public void setState(String component, String data, long revision) {
boolean status = state.update(component, data, revision);
if (status) {
- if (listener != null) {
- listener.stateChanged(component, data);
+ if (stateListener != null) {
+ stateListener.stateChanged(component, data);
}
} else {
logger.warn("Ignoring update: {}",
@@ -93,6 +98,10 @@ public class ClientServiceImpl implements ClientService, UrlReceiver {
}
public void setStateChangedListener(StateChangedListener listener) {
- this.listener = listener;
+ this.stateListener = listener;
+ }
+
+ public void setNetworkListener(NetworkNotificationListener listener) {
+ this.networkListener = listener;
}
}
diff --git a/same/src/main/java/com/orbekk/same/NetworkNotificationListener.java b/same/src/main/java/com/orbekk/same/NetworkNotificationListener.java
new file mode 100644
index 0000000..14c758f
--- /dev/null
+++ b/same/src/main/java/com/orbekk/same/NetworkNotificationListener.java
@@ -0,0 +1,5 @@
+package com.orbekk.same;
+
+public interface NetworkNotificationListener {
+ void notifyNetwork(String networkName, String masterUrl);
+}
diff --git a/same/src/test/java/com/orbekk/same/ClientServiceImplTest.java b/same/src/test/java/com/orbekk/same/ClientServiceImplTest.java
index 2baa829..39c0e7c 100644
--- a/same/src/test/java/com/orbekk/same/ClientServiceImplTest.java
+++ b/same/src/test/java/com/orbekk/same/ClientServiceImplTest.java
@@ -3,6 +3,7 @@ package com.orbekk.same;
import static org.junit.Assert.*;
import org.junit.Test;
+import static org.mockito.Mockito.*;
public class ClientServiceImplTest {
private State state = new State("ClientNetwork");
@@ -15,4 +16,12 @@ public class ClientServiceImplTest {
assertEquals(100, state.getRevision("TestState"));
assertEquals("Test data", state.getDataOf("TestState"));
}
+
+ @Test public void testNetworkListener() {
+ NetworkNotificationListener listener =
+ mock(NetworkNotificationListener.class);
+ client.setNetworkListener(listener);
+ client.notifyNetwork("MyNetwork", "MasterUrl");
+ verify(listener).notifyNetwork("MyNetwork", "MasterUrl");
+ }
}