diff options
author | Kjetil Ørbekk <kjetil.orbekk@gmail.com> | 2012-02-23 13:48:59 +0100 |
---|---|---|
committer | Kjetil Ørbekk <kjetil.orbekk@gmail.com> | 2012-02-23 13:48:59 +0100 |
commit | ff7bb967cce1fdfe64fe3126c11e5c7d3f3ffb12 (patch) | |
tree | 401d683dce104a01132e9a928d9888b767d8eea0 /same | |
parent | b21b53b919a741bc30ad835db14aefbeb4579f50 (diff) |
Use Variables in StateServlet.
Diffstat (limited to 'same')
3 files changed, 18 insertions, 5 deletions
diff --git a/same/src/main/java/com/orbekk/same/SameController.java b/same/src/main/java/com/orbekk/same/SameController.java index 58dfc6f..bce6831 100644 --- a/same/src/main/java/com/orbekk/same/SameController.java +++ b/same/src/main/java/com/orbekk/same/SameController.java @@ -57,8 +57,11 @@ public class SameController { discoveryService = new DiscoveryService(client, broadcastListener); } + StateServlet stateServlet = new StateServlet(client.getInterface(), + new VariableFactory(client.getInterface())); + ServerContainer server = new ServerBuilder(port) - .withServlet(new StateServlet(client.getInterface()), "/_/state") + .withServlet(stateServlet, "/_/state") .withService(client.getService(), ClientService.class) .withService(master.getService(), MasterService.class) .withService(paxos, PaxosService.class) diff --git a/same/src/main/java/com/orbekk/same/VariableFactory.java b/same/src/main/java/com/orbekk/same/VariableFactory.java index 79c2cdc..87db576 100644 --- a/same/src/main/java/com/orbekk/same/VariableFactory.java +++ b/same/src/main/java/com/orbekk/same/VariableFactory.java @@ -77,4 +77,8 @@ public class VariableFactory { variable.update(); return variable; } + + public Variable<String> createString(String identifier) { + return create(identifier, new TypeReference<String>() {}); + } } 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 31e8bcb..17e566d 100644 --- a/same/src/main/java/com/orbekk/same/http/StateServlet.java +++ b/same/src/main/java/com/orbekk/same/http/StateServlet.java @@ -14,14 +14,19 @@ import org.slf4j.LoggerFactory; import com.orbekk.same.Client; 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 VariableFactory variableFactory; private final static String TITLE = "State viewer"; - public StateServlet(Client.ClientInterface client) { + public StateServlet(Client.ClientInterface client, + VariableFactory variableFactory) { this.client = client; + this.variableFactory = variableFactory; } private void handleSetState(HttpServletRequest request, @@ -35,8 +40,9 @@ public class StateServlet extends HttpServlet { try { String key = request.getParameter("key"); String value = request.getParameter("value"); - long revision = client.getState().getRevision(key); - client.set(key, value, revision); + Variable<String> variable = variableFactory.createString(key); + variable.set(value); + response.getWriter().println("Updated component: " + key + "=" + value); } catch (UpdateConflict e) { @@ -98,5 +104,5 @@ public class StateServlet extends HttpServlet { PrintWriter w = response.getWriter(); w.println("</body>"); w.println("</html>"); - } + } } |