summaryrefslogtreecommitdiff
path: root/same/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'same/src/main')
-rw-r--r--same/src/main/java/com/orbekk/same/Master.java4
-rw-r--r--same/src/main/java/com/orbekk/same/SameController.java32
-rw-r--r--same/src/main/resources/client.properties.example1
3 files changed, 30 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);
}
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