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/Client.java7
-rw-r--r--same/src/main/java/com/orbekk/same/Master.java11
-rw-r--r--same/src/main/java/com/orbekk/same/SameController.java5
3 files changed, 16 insertions, 7 deletions
diff --git a/same/src/main/java/com/orbekk/same/Client.java b/same/src/main/java/com/orbekk/same/Client.java
index 1a9fb7f..1927731 100644
--- a/same/src/main/java/com/orbekk/same/Client.java
+++ b/same/src/main/java/com/orbekk/same/Client.java
@@ -195,11 +195,16 @@ public class Client implements DiscoveryListener {
this.masterController = masterController;
}
+ private void reset() {
+ state.clear();
+ masterId = 0;
+ }
+
public void joinNetwork(String masterUrl) {
logger.info("joinNetwork({})", masterUrl);
connectionState = ConnectionState.UNSTABLE;
MasterService master = connections.getMaster(masterUrl);
- state.clear();
+ reset();
try {
master.joinNetworkRequest(myUrl);
} catch (Exception e) {
diff --git a/same/src/main/java/com/orbekk/same/Master.java b/same/src/main/java/com/orbekk/same/Master.java
index 32d6ec2..3bb6260 100644
--- a/same/src/main/java/com/orbekk/same/Master.java
+++ b/same/src/main/java/com/orbekk/same/Master.java
@@ -13,6 +13,7 @@ public class Master {
private String myUrl;
State state;
private Broadcaster broadcaster;
+ private volatile int masterId = 0;
public static Master create(ConnectionManager connections,
Broadcaster broadcaster, String myUrl, String networkName) {
@@ -119,14 +120,14 @@ public class Master {
@Override public void run(String url) {
ClientService client = connections.getClient(url);
try {
+ client.masterTakeover(
+ state.getDataOf(".masterUrl"),
+ state.getDataOf(".networkName"),
+ masterId);
for (Component c : components) {
client.setState(c.getName(), c.getData(),
c.getRevision());
}
- client.masterTakeover(
- state.getDataOf(".masterUrl"),
- state.getDataOf(".networkName"),
- 0);
} catch (Exception e) {
logger.info("Client {} failed to receive state update.", url);
removeParticipant(url);
@@ -138,6 +139,8 @@ public class Master {
/** This master should take over from an earlier master. */
public void resumeFrom(State lastKnownState, final int masterId) {
state = lastKnownState;
+ state.update(".masterUrl", myUrl, state.getRevision(".masterUrl") + 100);
+ this.masterId = masterId;
broadcaster.broadcast(state.getList(".participants"),
new ServiceOperation() {
@Override
diff --git a/same/src/main/java/com/orbekk/same/SameController.java b/same/src/main/java/com/orbekk/same/SameController.java
index 8788be0..e9a7916 100644
--- a/same/src/main/java/com/orbekk/same/SameController.java
+++ b/same/src/main/java/com/orbekk/same/SameController.java
@@ -42,9 +42,10 @@ public class SameController {
"MasterService.json";
master = Master.create(connections, serviceBroadcaster,
masterUrl, configuration.get("networkName"));
- if (lastKnownState != null) {
- master.resumeFrom(lastKnownState, masterId);
+ if (lastKnownState == null) {
+ lastKnownState = master.state;
}
+ master.resumeFrom(lastKnownState, masterId);
master.start();
masterService.setService(master.getService());
}