Commit d908ee05 authored by Mohamad Bashar Desoki's avatar Mohamad Bashar Desoki

Leader reelection Attempt 1

parent 2879dbfc
......@@ -7,8 +7,11 @@
* Zookeeper Client Threading Model & Zookeeper Java API
* Leader Election Implementation
* Watchers, Triggers and Introduction to Failure Detection
* Herd Effect
* Leader reelection Attempt 1 (with Herd Effect)
*Useful links*
* [Class ZooKeeper](https://zookeeper.apache.org/doc/r3.9.1/apidocs/zookeeper-server/org/apache/zookeeper/ZooKeeper.html)
* [wait notify and notifyall in java](https://javarevisited.blogspot.com/2011/05/wait-notify-and-notifyall-in-java.html)
\ No newline at end of file
* [wait notify and notifyall in java](https://javarevisited.blogspot.com/2011/05/wait-notify-and-notifyall-in-java.html)
* [Zookeeper Tutorial](https://bikas-katwal.medium.com/zookeeper-introduction-designing-a-distributed-system-using-zookeeper-and-java-7f1b108e236e)
\ No newline at end of file
......@@ -33,7 +33,7 @@ public class LeaderElection implements Watcher {
}
public void electLeader() throws InterruptedException, KeeperException {
List<String> children = zooKeeper.getChildren(ELECTION_NAMESPACE, false);
List<String> children = zooKeeper.getChildren(ELECTION_NAMESPACE, this);
Collections.sort(children);
String smallestChild = children.get(0); //the first element
......@@ -74,6 +74,15 @@ public class LeaderElection implements Watcher {
} else if (watchedEvent.getState() == Event.KeeperState.Closed) {
System.out.println("Closed Successfully");
}
case NodeChildrenChanged:
try {
electLeader();
System.out.println(ELECTION_NAMESPACE + " NodeChildrenChanged");
} catch (InterruptedException e) {
throw new RuntimeException(e);
} catch (KeeperException e) {
throw new RuntimeException(e);
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment