diff options
author | Kjetil Ørbekk <kjetil.orbekk@gmail.com> | 2012-04-17 14:23:25 +0200 |
---|---|---|
committer | Kjetil Ørbekk <kjetil.orbekk@gmail.com> | 2012-04-17 14:23:25 +0200 |
commit | a6a1c550731caaa2e46aab2112b81f318da229aa (patch) | |
tree | 5db60653f65c3b81899a89fd370c892b07bfab32 | |
parent | 3abdb97eafcf7825d8f2a0bf71b5966a6e3f7c1f (diff) |
Client registers with protobuf service location.
6 files changed, 19 insertions, 13 deletions
diff --git a/same/src/main/java/com/orbekk/same/Client.java b/same/src/main/java/com/orbekk/same/Client.java index 7d1ce56..6386928 100644 --- a/same/src/main/java/com/orbekk/same/Client.java +++ b/same/src/main/java/com/orbekk/same/Client.java @@ -28,6 +28,7 @@ public class Client { private final ConnectionManager connections; volatile State state; private volatile String myUrl; + private volatile String myLocation; volatile String masterUrl; volatile String masterLocation; private volatile int masterId = 0; @@ -206,10 +207,11 @@ public class Client { }; public Client(State state, ConnectionManager connections, - String myUrl, Broadcaster broadcaster) { + String myUrl, String myLocation, Broadcaster broadcaster) { this.state = state; this.connections = connections; this.myUrl = myUrl; + this.myLocation = myLocation; this.broadcaster = broadcaster; } @@ -229,7 +231,8 @@ public class Client { public Services.ClientState getClientState() { return Services.ClientState.newBuilder() - .setUrl(getUrl()) + .setUrl(myUrl) + .setLocation(myLocation) .build(); } diff --git a/same/src/main/java/com/orbekk/same/Master.java b/same/src/main/java/com/orbekk/same/Master.java index b2adea1..511da08 100644 --- a/same/src/main/java/com/orbekk/same/Master.java +++ b/same/src/main/java/com/orbekk/same/Master.java @@ -83,7 +83,7 @@ public class Master { } /** New participant code. */ - addParticipant(request); + addParticipant(request.getLocation()); done.run(Empty.getDefaultInstance()); } @@ -199,10 +199,10 @@ public class Master { return serviceImpl; } - private synchronized void addParticipant(ClientState client) { + private synchronized void addParticipant(String location) { List<String> participants = state.getList(State.PARTICIPANTS); - if (!participants.contains(client.getUrl())) { - participants.add(client.getUrl()); + if (!participants.contains(location)) { + participants.add(location); state.updateFromObject(State.PARTICIPANTS, participants, state.getRevision(State.PARTICIPANTS) + 1); updateStateRequestThread.add(State.PARTICIPANTS); diff --git a/same/src/main/java/com/orbekk/same/SameController.java b/same/src/main/java/com/orbekk/same/SameController.java index 900dcbc..b87e6f5 100644 --- a/same/src/main/java/com/orbekk/same/SameController.java +++ b/same/src/main/java/com/orbekk/same/SameController.java @@ -57,6 +57,8 @@ public class SameController { public static SameController create(Configuration configuration) { int port = configuration.getInt("port"); int pport = configuration.getInt("pport"); + String myLocation = configuration.get("localIp") + ":" + pport; + ConnectionManagerImpl connections = new ConnectionManagerImpl( timeout, timeout); State clientState = new State(".InvalidClientNetwork"); @@ -67,7 +69,8 @@ public class SameController { MasterServiceProxy master = new MasterServiceProxy(); Client client = new Client(clientState, connections, - clientUrl, BroadcasterImpl.getDefaultBroadcastRunner()); + clientUrl, myLocation, + BroadcasterImpl.getDefaultBroadcastRunner()); PaxosServiceImpl paxos = new PaxosServiceImpl(""); StateServlet stateServlet = new StateServlet(client.getInterface(), new VariableFactory(client.getInterface())); diff --git a/same/src/test/java/com/orbekk/same/ClientTest.java b/same/src/test/java/com/orbekk/same/ClientTest.java index 97ccae0..1781ef3 100644 --- a/same/src/test/java/com/orbekk/same/ClientTest.java +++ b/same/src/test/java/com/orbekk/same/ClientTest.java @@ -18,7 +18,7 @@ public class ClientTest { private State state = new State("ClientNetwork"); private TestConnectionManager connections = new TestConnectionManager(); private Client client = new Client(state, connections, - "http://client/ClientService.json", null); + "http://client/ClientService.json", "clientLocation", null); private ClientService clientS = client.getService(); private MasterService mockMaster = mock(MasterService.class); diff --git a/same/src/test/java/com/orbekk/same/FunctionalTest.java b/same/src/test/java/com/orbekk/same/FunctionalTest.java index 3d2b3d8..73f0a37 100644 --- a/same/src/test/java/com/orbekk/same/FunctionalTest.java +++ b/same/src/test/java/com/orbekk/same/FunctionalTest.java @@ -48,7 +48,7 @@ public class FunctionalTest { Client newClient(String clientName, String clientUrl) { Client client = new Client(new State(clientName), connections, - clientUrl, broadcaster); + clientUrl, "clientLocation", broadcaster); connections.clientMap.put(clientUrl, client.getService()); clients.add(client); String paxosUrl = clientUrl.replace("ClientService", "PaxosService"); diff --git a/same/src/test/java/com/orbekk/same/MasterTest.java b/same/src/test/java/com/orbekk/same/MasterTest.java index 99a05d3..8830c10 100644 --- a/same/src/test/java/com/orbekk/same/MasterTest.java +++ b/same/src/test/java/com/orbekk/same/MasterTest.java @@ -60,7 +60,7 @@ public class MasterTest { public void clientJoin() throws Exception { Client client = new Client( new State("ClientNetwork"), connections, - "http://client/ClientService.json", null); + "http://client/ClientService.json", "clientLocation", null); ClientService clientS = client.getService(); connections.clientMap.put("http://client/ClientService.json", clientS); client.joinNetwork(master.getMasterInfo()); @@ -73,12 +73,12 @@ public class MasterTest { public void updateStateRequest() throws Exception { Client client1 = new Client( new State("ClientNetwork"), connections, - "http://client/ClientService.json", null); + "http://client/ClientService.json", "clientLocation", null); ClientService client1S = client1.getService(); connections.clientMap.put("http://client/ClientService.json", client1S); Client client2 = new Client( new State("ClientNetwork"), connections, - "http://client2/ClientService.json", null); + "http://client2/ClientService.json", "clientLocation", null); ClientService client2S = client2.getService(); connections.clientMap.put("http://client2/ClientService.json", client2S); @@ -108,7 +108,7 @@ public class MasterTest { public void masterRemovesParticipant() throws Exception { Client client = new Client( new State("ClientNetwork"), connections, - "http://client/ClientService.json", null); + "http://client/ClientService.json", "clientLocation", null); ClientService clientS = client.getService(); connections.clientMap.put("http://client/ClientService.json", clientS); client.joinNetwork(master.getMasterInfo()); |