diff options
Diffstat (limited to 'same/src/main/java/com/orbekk/same')
-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); |