diff options
author | Kjetil Ørbekk <kjetil.orbekk@gmail.com> | 2012-03-13 14:05:38 +0100 |
---|---|---|
committer | Kjetil Ørbekk <kjetil.orbekk@gmail.com> | 2012-03-13 14:05:38 +0100 |
commit | b256d125695da6b2a8eedd6f59ad07e94bd2b0bc (patch) | |
tree | 042074790f5d34775e528cc1ef164056bbf94849 /same/src/main/java/com | |
parent | af836cf8e577d2dabeb6450066bcc7ff55bf70e8 (diff) |
Clients can control their master.
Add failing test.
Diffstat (limited to 'same/src/main/java/com')
-rw-r--r-- | same/src/main/java/com/orbekk/same/Client.java | 12 | ||||
-rw-r--r-- | same/src/main/java/com/orbekk/same/SameController.java | 1 |
2 files changed, 12 insertions, 1 deletions
diff --git a/same/src/main/java/com/orbekk/same/Client.java b/same/src/main/java/com/orbekk/same/Client.java index 4d5965b..d4ec19e 100644 --- a/same/src/main/java/com/orbekk/same/Client.java +++ b/same/src/main/java/com/orbekk/same/Client.java @@ -23,6 +23,7 @@ public class Client implements DiscoveryListener { private String myUrl; String masterUrl; private int masterId = -1; + private MasterController masterController = null; private List<StateChangedListener> stateListeners = new ArrayList<StateChangedListener>(); @@ -160,6 +161,10 @@ public class Client implements DiscoveryListener { return connectionState; } + public void setMasterController(MasterController masterController) { + this.masterController = masterController; + } + public void joinNetwork(String masterUrl) { logger.info("joinNetwork({})", masterUrl); connectionState = ConnectionState.UNSTABLE; @@ -233,10 +238,15 @@ public class Client implements DiscoveryListener { return paxosUrls; } - private void startMasterElection() { + public void startMasterElection() { + if (masterController == null) { + logger.warn("Could not become master: No master controller."); + return; + } List<String> paxosUrls = getPaxosUrls(); MasterProposer proposer = new MasterProposer(getUrl(), paxosUrls, connections); // TODO: Run election. + masterController.enableMaster(state); } } diff --git a/same/src/main/java/com/orbekk/same/SameController.java b/same/src/main/java/com/orbekk/same/SameController.java index c4bdfe7..a9b389c 100644 --- a/same/src/main/java/com/orbekk/same/SameController.java +++ b/same/src/main/java/com/orbekk/same/SameController.java @@ -130,6 +130,7 @@ public class SameController { public void start() throws Exception { server.start(); + client.setMasterController(masterController); client.start(); if (discoveryService != null) { discoveryService.start(); |