diff options
author | Kjetil Ørbekk <kjetil.orbekk@gmail.com> | 2012-04-11 15:46:27 +0200 |
---|---|---|
committer | Kjetil Ørbekk <kjetil.orbekk@gmail.com> | 2012-04-11 15:46:27 +0200 |
commit | 04d448aade12127b1d8c9d4f26963833102698f8 (patch) | |
tree | b4120784e328197aa5d724f6e6ca0d4d3b676c7d /same/src | |
parent | a21280cc77c163ec7bd7bc1fc4b451a1fc01a1d8 (diff) |
Change Client.joinNetwork.
Take MasterState instead of a simple URL.
Diffstat (limited to 'same/src')
6 files changed, 28 insertions, 12 deletions
diff --git a/same/src/main/java/com/orbekk/same/App.java b/same/src/main/java/com/orbekk/same/App.java index ca12fa2..2b2985e 100644 --- a/same/src/main/java/com/orbekk/same/App.java +++ b/same/src/main/java/com/orbekk/same/App.java @@ -8,6 +8,13 @@ import com.orbekk.same.config.Configuration; public class App { private Logger logger = LoggerFactory.getLogger(getClass()); + private Services.MasterState getMasterInfo(Configuration configuration) { + return Services.MasterState.newBuilder() + .setMasterUrl(configuration.get(".masterUrl")) + .setMasterLocation(configuration.get("masterLocation")) + .build(); + } + public void run(String[] args) { Configuration configuration = Configuration.loadOrDie(); SameController controller = SameController.create(configuration); @@ -16,7 +23,7 @@ public class App { if ("true".equals(configuration.get("isMaster"))) { controller.createNetwork(configuration.get("networkName")); } else { - controller.joinNetwork(configuration.get("masterUrl")); + controller.joinNetwork(getMasterInfo(configuration)); } controller.join(); } catch (Exception e) { diff --git a/same/src/main/java/com/orbekk/same/Client.java b/same/src/main/java/com/orbekk/same/Client.java index 257735c..c8d4ef3 100644 --- a/same/src/main/java/com/orbekk/same/Client.java +++ b/same/src/main/java/com/orbekk/same/Client.java @@ -222,10 +222,10 @@ public class Client { masterId = 0; } - public void joinNetwork(String masterUrl) { - logger.info("joinNetwork({})", masterUrl); + public void joinNetwork(Services.MasterState masterInfo) { + logger.info("joinNetwork({})", masterInfo); connectionState = ConnectionState.UNSTABLE; - MasterService master = connections.getMaster(masterUrl); + MasterService master = connections.getMaster(masterInfo.getMasterUrl()); reset(); try { master.joinNetworkRequest(myUrl); diff --git a/same/src/main/java/com/orbekk/same/Master.java b/same/src/main/java/com/orbekk/same/Master.java index 1b2fbee..55d7daf 100644 --- a/same/src/main/java/com/orbekk/same/Master.java +++ b/same/src/main/java/com/orbekk/same/Master.java @@ -53,6 +53,15 @@ public class Master { return myUrl; } + public Services.MasterState getMasterInfo() { + return Services.MasterState.newBuilder() + .setMasterUrl(getUrl()) + .setMasterLocation(getLocation()) + .setNetworkName(getNetworkName()) + .setMasterId(masterId) + .build(); + } + private Services.Master newMasterImpl = new Services.Master() { @Override public void joinNetworkRequest(RpcController controller, ClientState request, RpcCallback<Empty> done) { diff --git a/same/src/main/java/com/orbekk/same/SameController.java b/same/src/main/java/com/orbekk/same/SameController.java index a68290d..900dcbc 100644 --- a/same/src/main/java/com/orbekk/same/SameController.java +++ b/same/src/main/java/com/orbekk/same/SameController.java @@ -138,11 +138,11 @@ public class SameController { masterController.enableMaster(new State(networkName), 1); String masterUrl = configuration.get("baseUrl") + "MasterService.json"; - joinNetwork(masterUrl); + joinNetwork(master.getMasterInfo()); } - public void joinNetwork(String url) { - client.joinNetwork(url); + public void joinNetwork(Services.MasterState masterInfo) { + client.joinNetwork(masterInfo); } public Client getClient() { diff --git a/same/src/test/java/com/orbekk/same/FunctionalTest.java b/same/src/test/java/com/orbekk/same/FunctionalTest.java index fc71803..12898ad 100644 --- a/same/src/test/java/com/orbekk/same/FunctionalTest.java +++ b/same/src/test/java/com/orbekk/same/FunctionalTest.java @@ -68,7 +68,7 @@ public class FunctionalTest { void joinClients() { for (Client c : clients) { - c.joinNetwork(masterUrl); + c.joinNetwork(master.getMasterInfo()); } performWork(); } diff --git a/same/src/test/java/com/orbekk/same/MasterTest.java b/same/src/test/java/com/orbekk/same/MasterTest.java index 423f292..b0bd666 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 { "http://client/ClientService.json", null); ClientService clientS = client.getService(); connections.clientMap.put("http://client/ClientService.json", clientS); - client.joinNetwork("http://master/MasterService.json"); + client.joinNetwork(master.getMasterInfo()); master.performWork(); assertTrue(state.getList(".participants").contains("http://client/ClientService.json")); assertEquals(state, client.testGetState()); @@ -79,8 +79,8 @@ public class MasterTest { ClientService client2S = client2.getService(); connections.clientMap.put("http://client2/ClientService.json", client2S); - client1.joinNetwork("http://master/MasterService.json"); - client2.joinNetwork("http://master/MasterService.json"); + client1.joinNetwork(master.getMasterInfo()); + client2.joinNetwork(master.getMasterInfo()); master.performWork(); assertTrue(state.getList(".participants").contains("http://client/ClientService.json")); @@ -108,7 +108,7 @@ public class MasterTest { "http://client/ClientService.json", null); ClientService clientS = client.getService(); connections.clientMap.put("http://client/ClientService.json", clientS); - client.joinNetwork("http://master/MasterService.json"); + client.joinNetwork(master.getMasterInfo()); master.performWork(); assertTrue(state.getList(".participants").contains("http://client/ClientService.json")); |