summaryrefslogtreecommitdiff
path: root/same/src/main/java/com
diff options
context:
space:
mode:
Diffstat (limited to 'same/src/main/java/com')
-rw-r--r--same/src/main/java/com/orbekk/same/SameController.java5
-rw-r--r--same/src/main/java/com/orbekk/same/VariableFactory.java4
-rw-r--r--same/src/main/java/com/orbekk/same/http/StateServlet.java14
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>");
- }
+ }
}