summaryrefslogtreecommitdiff
path: root/same
diff options
context:
space:
mode:
authorKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-03-20 15:01:31 +0100
committerKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-03-20 15:01:31 +0100
commite622d72a9d1cf7dbf5e2eaf5290aef073233c545 (patch)
treeecb5fa9ff20f8167adab5cf720ad36b12ee948c4 /same
parent4ad09d6604aa6c2091824a239f9c75a06aef0b24 (diff)
Fix issues when transfering to new master.
.masterUrl needs to be set explicitly. Some other fixes.
Diffstat (limited to 'same')
-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());
}