diff options
author | Kjetil Ørbekk <kjetil.orbekk@gmail.com> | 2012-01-18 21:08:26 +0100 |
---|---|---|
committer | Kjetil Ørbekk <kjetil.orbekk@gmail.com> | 2012-01-18 21:08:26 +0100 |
commit | 5b27e3c7b289792b6520a099280a6c1bc28c20e8 (patch) | |
tree | d89b964dd0e4ea0f49c000e8853a15a8762e62e8 /same/src/main/java/com | |
parent | 6c150264b21eded212b9e2cf9c802b36c3f75144 (diff) |
Hack: Use Same to synchronize state in the android app.
Diffstat (limited to 'same/src/main/java/com')
-rw-r--r-- | same/src/main/java/com/orbekk/same/ClientApp.java | 2 | ||||
-rw-r--r-- | same/src/main/java/com/orbekk/same/ClientServiceImpl.java | 16 | ||||
-rw-r--r-- | same/src/main/java/com/orbekk/same/State.java | 12 |
3 files changed, 29 insertions, 1 deletions
diff --git a/same/src/main/java/com/orbekk/same/ClientApp.java b/same/src/main/java/com/orbekk/same/ClientApp.java index 5829c5d..970f16d 100644 --- a/same/src/main/java/com/orbekk/same/ClientApp.java +++ b/same/src/main/java/com/orbekk/same/ClientApp.java @@ -12,7 +12,7 @@ public class ClientApp { private Server server; private static final int timeout = 1000; - public ClientService getClient(int port, String networkName, + public ClientServiceImpl getClient(int port, String networkName, String masterUrl) { logger.info("Starting client with port:{}, networkName:{}, masterUrl:{}", new Object[]{port, networkName, masterUrl}); diff --git a/same/src/main/java/com/orbekk/same/ClientServiceImpl.java b/same/src/main/java/com/orbekk/same/ClientServiceImpl.java index 3f84c2e..46cdd86 100644 --- a/same/src/main/java/com/orbekk/same/ClientServiceImpl.java +++ b/same/src/main/java/com/orbekk/same/ClientServiceImpl.java @@ -53,6 +53,22 @@ public class ClientServiceImpl implements ClientService, UrlReceiver { } } + public boolean sendStateUpdate(String componentName, String data, + long revision) { + String masterUrl = state.getDataOf(".masterUrl"); + MasterService master = connections.getMaster(masterUrl); + try { + return master.updateStateRequest(componentName, data, revision); + } catch (Exception e) { + logger.error("Unable to contact master. Update fails."); + return false; + } + } + + public State.Component getState(String name) { + return state.getComponent(name); + } + State testGetState() { return state; } diff --git a/same/src/main/java/com/orbekk/same/State.java b/same/src/main/java/com/orbekk/same/State.java index 58cb5b5..f8ba6a4 100644 --- a/same/src/main/java/com/orbekk/same/State.java +++ b/same/src/main/java/com/orbekk/same/State.java @@ -67,6 +67,18 @@ public class State { return false; } } + + /** + * Get a copy of a component. + */ + public Component getComponent(String name) { + Component component = state.get(name); + if (component != null) { + return new Component(component); + } else { + return null; + } + } public String getDataOf(String componentName) { Component component = state.get(componentName); |