diff options
Diffstat (limited to 'same/src/main')
4 files changed, 23 insertions, 7 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() { |