summaryrefslogtreecommitdiff
path: root/same/src
diff options
context:
space:
mode:
Diffstat (limited to 'same/src')
-rw-r--r--same/src/main/java/com/orbekk/same/Client.java13
-rw-r--r--same/src/main/java/com/orbekk/same/ClientInterface.java1
-rw-r--r--same/src/main/java/com/orbekk/same/ConnectionState.java5
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;
+}