summaryrefslogtreecommitdiff
path: root/same/src/main/java/com/orbekk
diff options
context:
space:
mode:
authorKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-02-23 14:02:57 +0100
committerKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-02-23 14:02:57 +0100
commitef8563e3106f1774b05fe5ea94f538e9983b0182 (patch)
tree65dd47986646ab319dc34204e8824fff2926d5e9 /same/src/main/java/com/orbekk
parente59207ad371db3895b36d85b6717f12a9cb7b275 (diff)
Support several state listeners in Client.
Diffstat (limited to 'same/src/main/java/com/orbekk')
-rw-r--r--same/src/main/java/com/orbekk/same/Client.java20
1 files changed, 13 insertions, 7 deletions
diff --git a/same/src/main/java/com/orbekk/same/Client.java b/same/src/main/java/com/orbekk/same/Client.java
index 4c03f31..3799041 100644
--- a/same/src/main/java/com/orbekk/same/Client.java
+++ b/same/src/main/java/com/orbekk/same/Client.java
@@ -2,6 +2,7 @@ package com.orbekk.same;
import static com.orbekk.same.StackTraceUtil.throwableToString;
+import java.util.ArrayList;
import java.util.List;
import org.codehaus.jackson.type.TypeReference;
@@ -15,7 +16,8 @@ public class Client implements DiscoveryListener {
private ConnectionManager connections;
private State state;
private String myUrl;
- private StateChangedListener stateListener;
+ private List<StateChangedListener> stateListeners =
+ new ArrayList<StateChangedListener>();
private NetworkNotificationListener networkListener;
public class ClientInterface {
@@ -44,6 +46,14 @@ public class Client implements DiscoveryListener {
throw new UpdateConflict("Unable to contact master. Update fails.");
}
}
+
+ public void addStateListener(StateChangedListener listener) {
+ stateListeners.add(listener);
+ }
+
+ public void removeStateListener(StateChangedListener listener) {
+ stateListeners.remove(listener);
+ }
}
private ClientInterface clientInterface = new ClientInterface();
@@ -53,8 +63,8 @@ public class Client implements DiscoveryListener {
public void setState(String component, String data, long revision) throws Exception {
boolean status = state.update(component, data, revision);
if (status) {
- if (stateListener != null) {
- stateListener.stateChanged(state.getComponent(component));
+ for (StateChangedListener listener : stateListeners) {
+ listener.stateChanged(state.getComponent(component));
}
} else {
logger.warn("Ignoring update: {}",
@@ -153,10 +163,6 @@ public class Client implements DiscoveryListener {
return state;
}
- public void setStateChangedListener(StateChangedListener listener) {
- this.stateListener = listener;
- }
-
public void setNetworkListener(NetworkNotificationListener listener) {
this.networkListener = listener;
}