summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--same-android/src/main/java/com/orbekk/same/android/ClientInterfaceBridge.java7
-rw-r--r--same-android/src/main/java/com/orbekk/same/android/StateViewerActivity.java4
-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
5 files changed, 27 insertions, 3 deletions
diff --git a/same-android/src/main/java/com/orbekk/same/android/ClientInterfaceBridge.java b/same-android/src/main/java/com/orbekk/same/android/ClientInterfaceBridge.java
index 081b7ed..47a6535 100644
--- a/same-android/src/main/java/com/orbekk/same/android/ClientInterfaceBridge.java
+++ b/same-android/src/main/java/com/orbekk/same/android/ClientInterfaceBridge.java
@@ -18,6 +18,7 @@ import android.os.Messenger;
import android.os.RemoteException;
import com.orbekk.same.ClientInterface;
+import com.orbekk.same.ConnectionState;
import com.orbekk.same.State;
import com.orbekk.same.State.Component;
import com.orbekk.same.StateChangedListener;
@@ -193,4 +194,10 @@ public class ClientInterfaceBridge implements ClientInterface {
return VariableFactory.create(this);
}
+ /** Doesn't work yet. Maybe we needs a listener interface? */
+ @Override
+ public ConnectionState getConnectionState() {
+ return null;
+ }
+
}
diff --git a/same-android/src/main/java/com/orbekk/same/android/StateViewerActivity.java b/same-android/src/main/java/com/orbekk/same/android/StateViewerActivity.java
index 679e3b6..fac73c0 100644
--- a/same-android/src/main/java/com/orbekk/same/android/StateViewerActivity.java
+++ b/same-android/src/main/java/com/orbekk/same/android/StateViewerActivity.java
@@ -9,12 +9,10 @@ import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
-import android.widget.Toast;
-import com.orbekk.same.android.R;
import com.orbekk.same.State;
-import com.orbekk.same.StateChangedListener;
import com.orbekk.same.State.Component;
+import com.orbekk.same.StateChangedListener;
public class StateViewerActivity extends Activity {
private Logger logger = LoggerFactory.getLogger(getClass());
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;
+}