Commit 4b023b0d authored by Mohamad Bashar Desoki's avatar Mohamad Bashar Desoki

Leader Election process update

parent 2764a3fd
# Leader Election (Zookeeper) # Leader Election (Zookeeper)
*topics*
* Introduction to Cluster Coordination
* Theory of Leader Election
* Zookeeper Server and Client
* Zookeeper Client Threading Model & Zookeeper Java API
* Leader Election Implementation
*Useful links* *Useful links*
* [Class ZooKeeper](https://zookeeper.apache.org/doc/r3.9.1/apidocs/zookeeper-server/org/apache/zookeeper/ZooKeeper.html) * [Class ZooKeeper](https://zookeeper.apache.org/doc/r3.9.1/apidocs/zookeeper-server/org/apache/zookeeper/ZooKeeper.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)
\ No newline at end of file
import org.apache.zookeeper.*; import org.apache.zookeeper.*;
import org.apache.zookeeper.data.Stat;
import java.io.IOException; import java.io.IOException;
import java.util.Collections; import java.util.Collections;
...@@ -65,16 +66,15 @@ public class LeaderElection implements Watcher { ...@@ -65,16 +66,15 @@ public class LeaderElection implements Watcher {
case None: case None:
if (watchedEvent.getState() == Event.KeeperState.SyncConnected) { if (watchedEvent.getState() == Event.KeeperState.SyncConnected) {
System.out.println("Successfully connected to Zookeeper"); System.out.println("Successfully connected to Zookeeper");
} else { } else if (watchedEvent.getState() == Event.KeeperState.Disconnected) {
synchronized (zooKeeper) { synchronized (zooKeeper) {
System.out.println("Disconnected"); System.out.println("Disconnected from Zookeeper");
zooKeeper.notifyAll(); zooKeeper.notifyAll();
} }
} else if (watchedEvent.getState() == Event.KeeperState.Closed) {
System.out.println("Closed Successfully");
} }
break;
// case NodeCreated:
// if (watchedEvent.getState() == )
} }
} }
} }
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