summaryrefslogtreecommitdiff
path: root/same/src/main
diff options
context:
space:
mode:
authorKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-03-20 10:24:59 +0100
committerKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-03-20 10:24:59 +0100
commit148d196ef154c420c450f8dcaa5b7d506115421a (patch)
tree584a394a2f39a75ee7953b671d99c664614b2ec9 /same/src/main
parentac5b56dfcd1233eb2c6273ec94c3c4eebbea2461 (diff)
Broadcast masterDown() event.
Diffstat (limited to 'same/src/main')
-rw-r--r--same/src/main/java/com/orbekk/same/Client.java32
-rw-r--r--same/src/main/java/com/orbekk/same/ClientService.java3
2 files changed, 30 insertions, 5 deletions
diff --git a/same/src/main/java/com/orbekk/same/Client.java b/same/src/main/java/com/orbekk/same/Client.java
index 7079016..fc4a6af 100644
--- a/same/src/main/java/com/orbekk/same/Client.java
+++ b/same/src/main/java/com/orbekk/same/Client.java
@@ -123,6 +123,13 @@ public class Client implements DiscoveryListener {
Client.this.masterUrl = masterUrl;
connectionState = ConnectionState.STABLE;
}
+
+ @Override
+ public void masterDown() throws Exception {
+ logger.info("Master is down.");
+ connectionState = ConnectionState.UNSTABLE;
+ tryBecomeMaster();
+ }
};
private WorkQueue<String> discoveryThread = new WorkQueue<String>() {
@@ -240,15 +247,30 @@ public class Client implements DiscoveryListener {
return paxosUrls;
}
- public void startMasterElection() {
- if (masterController == null) {
- logger.warn("Could not become master: No master controller.");
- return;
- }
+ private void tryBecomeMaster() {
List<String> paxosUrls = getPaxosUrls();
MasterProposer proposer = new MasterProposer(getUrl(), paxosUrls,
connections);
// TODO: Run election.
+ if (masterController == null) {
+ logger.warn("Could not become master: No master controller.");
+ return;
+ }
masterController.enableMaster(state);
}
+
+ public void startMasterElection() {
+ List<String> participants = state.getList(".participants");
+ broadcaster.broadcast(participants, new ServiceOperation() {
+ @Override public void run(String url) {
+ ClientService client = connections.getClient(url);
+ try {
+ client.masterDown();
+ } catch (Exception e) {
+ logger.info("{}.masterDown() did not respond (ignored): " +
+ url, e);
+ }
+ }
+ });
+ }
}
diff --git a/same/src/main/java/com/orbekk/same/ClientService.java b/same/src/main/java/com/orbekk/same/ClientService.java
index 453dfef..dfca2cc 100644
--- a/same/src/main/java/com/orbekk/same/ClientService.java
+++ b/same/src/main/java/com/orbekk/same/ClientService.java
@@ -16,4 +16,7 @@ public interface ClientService {
*/
void masterTakeover(String masterUrl, String networkName,
int masterId) throws Exception;
+
+ /** The master is down, so start a new master election. */
+ void masterDown() throws Exception;
}