diff options
Diffstat (limited to 'same/src/main/java')
-rw-r--r-- | same/src/main/java/com/orbekk/same/Master.java | 4 | ||||
-rw-r--r-- | same/src/main/java/com/orbekk/same/SameController.java | 32 |
2 files changed, 29 insertions, 7 deletions
diff --git a/same/src/main/java/com/orbekk/same/Master.java b/same/src/main/java/com/orbekk/same/Master.java index 88177d6..6e08c48 100644 --- a/same/src/main/java/com/orbekk/same/Master.java +++ b/same/src/main/java/com/orbekk/same/Master.java @@ -132,4 +132,8 @@ public class Master { } }); } + + /** This master should take over from an earlier master. */ + public void resumeFrom(State lastKnownState) { + } } diff --git a/same/src/main/java/com/orbekk/same/SameController.java b/same/src/main/java/com/orbekk/same/SameController.java index 3fcfad9..c4bdfe7 100644 --- a/same/src/main/java/com/orbekk/same/SameController.java +++ b/same/src/main/java/com/orbekk/same/SameController.java @@ -35,6 +35,29 @@ public class SameController { */ private static final int timeout = 10000; + private MasterController masterController = new MasterController() { + @Override + public void enableMaster(State lastKnownState) { + String masterUrl = configuration.get("baseUrl") + + "MasterService.json"; + master = Master.create(connections, serviceBroadcaster, + masterUrl, configuration.get("networkName")); + if (lastKnownState != null) { + master.resumeFrom(lastKnownState); + } + master.start(); + masterService.setService(master.getService()); + } + + @Override + public void disableMaster() { + masterService.setService(null); + if (master != null) { + master.interrupt(); + } + } + }; + public static SameController create(BroadcasterFactory broadcasterFactory, Configuration configuration) { int port = configuration.getInt("port"); @@ -148,15 +171,10 @@ public class SameController { } public void createNetwork(String networkName) { - masterService.setService(null); - if (master != null) { - master.interrupt(); - } + masterController.disableMaster(); + masterController.enableMaster(null); String masterUrl = configuration.get("baseUrl") + "MasterService.json"; - master = Master.create(connections, serviceBroadcaster, - masterUrl, configuration.get("networkName")); - masterService.setService(master.getService()); joinNetwork(masterUrl); } |