diff options
author | Kjetil Ørbekk <kjetil.orbekk@gmail.com> | 2012-03-12 13:03:33 +0100 |
---|---|---|
committer | Kjetil Ørbekk <kjetil.orbekk@gmail.com> | 2012-03-12 13:04:01 +0100 |
commit | 5cd824833cce13bd71a330e7b2767e6390d54bc0 (patch) | |
tree | f60299d5342e7596a3d8169568d13e4f02173012 /same/src/main/java/com/orbekk | |
parent | 736507d9cffc567afef96cdeaf9ab998c037cd39 (diff) |
Add ConnectionState to Client.
Diffstat (limited to 'same/src/main/java/com/orbekk')
-rw-r--r-- | same/src/main/java/com/orbekk/same/Client.java | 13 | ||||
-rw-r--r-- | same/src/main/java/com/orbekk/same/ClientInterface.java | 1 | ||||
-rw-r--r-- | same/src/main/java/com/orbekk/same/ConnectionState.java | 5 |
3 files changed, 19 insertions, 0 deletions
diff --git a/same/src/main/java/com/orbekk/same/Client.java b/same/src/main/java/com/orbekk/same/Client.java index 8401c4b..f48865d 100644 --- a/same/src/main/java/com/orbekk/same/Client.java +++ b/same/src/main/java/com/orbekk/same/Client.java @@ -16,6 +16,7 @@ import com.orbekk.util.WorkQueue; public class Client implements DiscoveryListener { private Logger logger = LoggerFactory.getLogger(getClass()); + private ConnectionState connectionState = ConnectionState.DISCONNECTED; private ConnectionManager connections; private State state; private String myUrl; @@ -69,6 +70,11 @@ public class Client implements DiscoveryListener { public void removeStateListener(StateChangedListener listener) { stateListeners.remove(listener); } + + @Override + public ConnectionState getConnectionState() { + return Client.this.getConnectionState(); + } } private ClientInterface clientInterface = new ClientInterfaceImpl(); @@ -76,6 +82,7 @@ public class Client implements DiscoveryListener { private ClientService serviceImpl = new ClientService() { @Override public void setState(String component, String data, long revision) throws Exception { + connectionState = ConnectionState.STABLE; boolean status = state.update(component, data, revision); if (status) { for (StateChangedListener listener : stateListeners) { @@ -123,6 +130,7 @@ public class Client implements DiscoveryListener { } public void interrupt() { + connectionState = ConnectionState.DISCONNECTED; discoveryThread.interrupt(); } @@ -130,8 +138,13 @@ public class Client implements DiscoveryListener { return myUrl; } + public ConnectionState getConnectionState() { + return connectionState; + } + public void joinNetwork(String masterUrl) { logger.info("joinNetwork({})", masterUrl); + connectionState = ConnectionState.UNSTABLE; MasterService master = connections.getMaster(masterUrl); state.clear(); try { diff --git a/same/src/main/java/com/orbekk/same/ClientInterface.java b/same/src/main/java/com/orbekk/same/ClientInterface.java index af8edfa..d7de30b 100644 --- a/same/src/main/java/com/orbekk/same/ClientInterface.java +++ b/same/src/main/java/com/orbekk/same/ClientInterface.java @@ -7,4 +7,5 @@ public interface ClientInterface { DelayedOperation set(State.Component component); void addStateListener(StateChangedListener listener); void removeStateListener(StateChangedListener listener); + ConnectionState getConnectionState(); }
\ No newline at end of file diff --git a/same/src/main/java/com/orbekk/same/ConnectionState.java b/same/src/main/java/com/orbekk/same/ConnectionState.java new file mode 100644 index 0000000..9d8fc15 --- /dev/null +++ b/same/src/main/java/com/orbekk/same/ConnectionState.java @@ -0,0 +1,5 @@ +package com.orbekk.same; + +public enum ConnectionState { + DISCONNECTED, STABLE, UNSTABLE; +} |