summaryrefslogtreecommitdiff
path: root/same/src/main
diff options
context:
space:
mode:
authorKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-02-23 14:59:44 +0100
committerKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-02-23 14:59:44 +0100
commitc4425e949d1942d7519046d276126dfab284b658 (patch)
treef36c0aeb40073317c7b12aa84ff92dcc15b045cf /same/src/main
parentb325d4005793d5f147b4eb539ae7f4fa5e5fb813 (diff)
Make it possible to create "fake" clients on Android.
Extract interface from Client.ClientInterface in order to override it for Android, while still using the VariableFactory code as-is.
Diffstat (limited to 'same/src/main')
-rw-r--r--same/src/main/java/com/orbekk/same/Client.java10
-rw-r--r--same/src/main/java/com/orbekk/same/VariableFactory.java6
-rw-r--r--same/src/main/java/com/orbekk/same/http/StateServlet.java6
3 files changed, 13 insertions, 9 deletions
diff --git a/same/src/main/java/com/orbekk/same/Client.java b/same/src/main/java/com/orbekk/same/Client.java
index 3799041..244a64d 100644
--- a/same/src/main/java/com/orbekk/same/Client.java
+++ b/same/src/main/java/com/orbekk/same/Client.java
@@ -20,16 +20,18 @@ public class Client implements DiscoveryListener {
new ArrayList<StateChangedListener>();
private NetworkNotificationListener networkListener;
- public class ClientInterface {
- private ClientInterface() {
+ public class ClientInterfaceImpl implements ClientInterface {
+ private ClientInterfaceImpl() {
}
/** Get a copy of all the client state.
*/
+ @Override
public State getState() {
return new State(state);
}
+ @Override
public void set(String name, String data, long revision)
throws UpdateConflict {
String masterUrl = state.getDataOf(".masterUrl");
@@ -47,16 +49,18 @@ public class Client implements DiscoveryListener {
}
}
+ @Override
public void addStateListener(StateChangedListener listener) {
stateListeners.add(listener);
}
+ @Override
public void removeStateListener(StateChangedListener listener) {
stateListeners.remove(listener);
}
}
- private ClientInterface clientInterface = new ClientInterface();
+ private ClientInterface clientInterface = new ClientInterfaceImpl();
private ClientService serviceImpl = new ClientService() {
@Override
diff --git a/same/src/main/java/com/orbekk/same/VariableFactory.java b/same/src/main/java/com/orbekk/same/VariableFactory.java
index 49604c6..66e6747 100644
--- a/same/src/main/java/com/orbekk/same/VariableFactory.java
+++ b/same/src/main/java/com/orbekk/same/VariableFactory.java
@@ -16,7 +16,7 @@ import com.orbekk.same.State.Component;
*/
public class VariableFactory {
private Logger logger = LoggerFactory.getLogger(getClass());
- private Client.ClientInterface client;
+ private ClientInterface client;
private ObjectMapper mapper = new ObjectMapper();
private class VariableImpl<T> implements Variable<T>, StateChangedListener {
@@ -76,11 +76,11 @@ public class VariableFactory {
}
}
- public static VariableFactory create(Client.ClientInterface client) {
+ public static VariableFactory create(ClientInterface client) {
return new VariableFactory(client);
}
- VariableFactory(Client.ClientInterface client) {
+ VariableFactory(ClientInterface client) {
this.client = client;
}
diff --git a/same/src/main/java/com/orbekk/same/http/StateServlet.java b/same/src/main/java/com/orbekk/same/http/StateServlet.java
index 17e566d..8b4d8c5 100644
--- a/same/src/main/java/com/orbekk/same/http/StateServlet.java
+++ b/same/src/main/java/com/orbekk/same/http/StateServlet.java
@@ -12,18 +12,18 @@ import javax.servlet.http.HttpServletResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.orbekk.same.Client;
+import com.orbekk.same.ClientInterface;
import com.orbekk.same.UpdateConflict;
import com.orbekk.same.Variable;
import com.orbekk.same.VariableFactory;
public class StateServlet extends HttpServlet {
private Logger logger = LoggerFactory.getLogger(getClass());
- private Client.ClientInterface client;
+ private ClientInterface client;
private VariableFactory variableFactory;
private final static String TITLE = "State viewer";
- public StateServlet(Client.ClientInterface client,
+ public StateServlet(ClientInterface client,
VariableFactory variableFactory) {
this.client = client;
this.variableFactory = variableFactory;