diff options
author | Kjetil Ørbekk <kjetil.orbekk@gmail.com> | 2012-02-06 21:12:20 +0100 |
---|---|---|
committer | Kjetil Ørbekk <kjetil.orbekk@gmail.com> | 2012-02-06 21:12:20 +0100 |
commit | 5a6fc8506af742694c856215dc0e182ba8790c08 (patch) | |
tree | a87ae6c15f439782e5c56ead6abe7fc0c5c9b4fb /same | |
parent | 1e8fd072ee765e70770a89970d164809e9d31a26 (diff) |
Show state in StateServlet.
Support interacting with a Client.
Diffstat (limited to 'same')
4 files changed, 30 insertions, 3 deletions
diff --git a/same/src/main/java/com/orbekk/same/Client.java b/same/src/main/java/com/orbekk/same/Client.java index ce3947c..2a5f11e 100644 --- a/same/src/main/java/com/orbekk/same/Client.java +++ b/same/src/main/java/com/orbekk/same/Client.java @@ -19,6 +19,19 @@ public class Client implements DiscoveryListener { private StateChangedListener stateListener; private NetworkNotificationListener networkListener; + public class ClientInterface { + private ClientInterface() { + } + + /** Get a copy of all the client state. + */ + public State getState() { + return new State(state); + } + } + + private ClientInterface clientInterface = new ClientInterface(); + private ClientService serviceImpl = new ClientService() { @Override public void setState(String component, String data, long revision) throws Exception { @@ -87,6 +100,10 @@ public class Client implements DiscoveryListener { } } + ClientInterface getInterface() { + return clientInterface; + } + String lib_get(String name) { return state.getDataOf(name); } diff --git a/same/src/main/java/com/orbekk/same/SameController.java b/same/src/main/java/com/orbekk/same/SameController.java index abf97c1..6b18115 100644 --- a/same/src/main/java/com/orbekk/same/SameController.java +++ b/same/src/main/java/com/orbekk/same/SameController.java @@ -45,7 +45,7 @@ public class SameController { PaxosServiceImpl paxos = new PaxosServiceImpl(""); ServerContainer server = new ServerBuilder(port) - .withServlet(new StateServlet(), "/_/state") + .withServlet(new StateServlet(client.getInterface()), "/_/state") .withService(client.getService(), ClientService.class) .withService(master, MasterService.class) .withService(paxos, PaxosService.class) diff --git a/same/src/main/java/com/orbekk/same/State.java b/same/src/main/java/com/orbekk/same/State.java index f8ba6a4..ea13582 100644 --- a/same/src/main/java/com/orbekk/same/State.java +++ b/same/src/main/java/com/orbekk/same/State.java @@ -30,6 +30,10 @@ public class State { updateFromObject(".participants", new ArrayList<String>(), 1); } + public State(State other) { + state.putAll(other.state); + } + public synchronized void clear() { logger.info("Clearing state."); updatedComponents.clear(); 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 62b304c..0ccf062 100644 --- a/same/src/main/java/com/orbekk/same/http/StateServlet.java +++ b/same/src/main/java/com/orbekk/same/http/StateServlet.java @@ -9,15 +9,21 @@ import javax.servlet.http.HttpServletResponse; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.orbekk.same.Client; + public class StateServlet extends HttpServlet { private Logger logger = LoggerFactory.getLogger(getClass()); + private Client.ClientInterface client; + + public StateServlet(Client.ClientInterface client) { + this.client = client; + } @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { - logger.error("GOT HERE"); response.setContentType("text/plain; charset=utf8"); - response.getWriter().println("HI"); + response.getWriter().println(client.getState()); response.setStatus(HttpServletResponse.SC_OK); } } |