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

Handle Disconnect Event to Close Zookeeper

parent e3c94330
# Leader Election (Zookeeper)
*Useful links*
* [Class ZooKeeper](https://zookeeper.apache.org/doc/r3.9.1/apidocs/zookeeper-server/org/apache/zookeeper/ZooKeeper.html)
\ No newline at end of file
......@@ -13,6 +13,12 @@ public class LeaderElection implements Watcher {
LeaderElection leaderElection = new LeaderElection();
leaderElection.connectToZookeeper();
leaderElection.run();
leaderElection.close();
System.out.println("Successfully Closed");
}
private void close() throws InterruptedException {
this.zooKeeper.close();
}
public void connectToZookeeper() throws IOException {
......@@ -31,7 +37,15 @@ public class LeaderElection implements Watcher {
case None:
if (watchedEvent.getState() == Event.KeeperState.SyncConnected) {
System.out.println("Successfully connected to Zookeeper");
} else {
synchronized (zooKeeper) {
System.out.println("Disconnected");
zooKeeper.notifyAll();
}
}
// 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