diff options
Diffstat (limited to 'same/src')
-rw-r--r-- | same/src/main/java/com/orbekk/same/Master.java | 22 | ||||
-rw-r--r-- | same/src/test/java/com/orbekk/same/MasterTest.java | 3 |
2 files changed, 22 insertions, 3 deletions
diff --git a/same/src/main/java/com/orbekk/same/Master.java b/same/src/main/java/com/orbekk/same/Master.java index 6e08c48..4402487 100644 --- a/same/src/main/java/com/orbekk/same/Master.java +++ b/same/src/main/java/com/orbekk/same/Master.java @@ -10,6 +10,7 @@ import org.slf4j.LoggerFactory; public class Master { private Logger logger = LoggerFactory.getLogger(getClass()); private final ConnectionManager connections; + private String myUrl; State state; private Broadcaster broadcaster; @@ -17,14 +18,15 @@ public class Master { Broadcaster broadcaster, String myUrl, String networkName) { State state = new State(networkName); state.update(".masterUrl", myUrl, 1); - return new Master(state, connections, broadcaster); + return new Master(state, connections, broadcaster, myUrl); } Master(State initialState, ConnectionManager connections, - Broadcaster broadcaster) { + Broadcaster broadcaster, String myUrl) { this.state = initialState; this.connections = connections; this.broadcaster = broadcaster; + this.myUrl = myUrl; } private MasterService serviceImpl = new MasterService() { @@ -135,5 +137,21 @@ public class Master { /** This master should take over from an earlier master. */ public void resumeFrom(State lastKnownState) { + state = lastKnownState; + broadcaster.broadcast(state.getList(".participants"), + new ServiceOperation() { + @Override + public void run(String url) { + ClientService client = connections.getClient(url); + try { + client.masterTakeover(myUrl, + state.getDataOf(".networkName"), 0); + } catch (Exception e) { + logger.info("Client {} failed to acknowledge new master. " + + "Removing {}", url); + removeParticipant(url); + } + } + }); } } diff --git a/same/src/test/java/com/orbekk/same/MasterTest.java b/same/src/test/java/com/orbekk/same/MasterTest.java index 77f024a..ec0a56c 100644 --- a/same/src/test/java/com/orbekk/same/MasterTest.java +++ b/same/src/test/java/com/orbekk/same/MasterTest.java @@ -43,7 +43,8 @@ public class MasterTest { @Before public void setUp() { state.update(".masterUrl", "http://master/MasterService.json", 1); - master = new Master(state, connections, broadcaster); + master = new Master(state, connections, broadcaster, + "http://master/MasterService.json"); masterS = master.getService(); connections.masterMap.put("http://master/MasterService.json", masterS); |