From af836cf8e577d2dabeb6450066bcc7ff55bf70e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kjetil=20=C3=98rbekk?= Date: Tue, 13 Mar 2012 12:51:09 +0100 Subject: Add MasterController interface. This interface should be used by a client in order to become a master. --- same/src/main/java/com/orbekk/same/Master.java | 4 +++ .../main/java/com/orbekk/same/SameController.java | 32 +++++++++++++++++----- same/src/main/resources/client.properties.example | 1 + 3 files changed, 30 insertions(+), 7 deletions(-) (limited to 'same') 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); } diff --git a/same/src/main/resources/client.properties.example b/same/src/main/resources/client.properties.example index d000a5d..5c13a0a 100644 --- a/same/src/main/resources/client.properties.example +++ b/same/src/main/resources/client.properties.example @@ -1,5 +1,6 @@ port=10011 localIp=10.0.0.6 +baseUrl=http://10.0.0.6:10011/ masterUrl=http://10.0.0.6:10010/MasterService.json enableDiscovery=true discoveryPort=15066 -- cgit v1.2.3