Commit e9fc63f0 authored by mohammad.salama's avatar mohammad.salama

Connection init - disconnected - closed

parent 180305ef
......@@ -22,16 +22,16 @@
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent"><![CDATA[{
"keyToString": {
"RunOnceActivity.OpenProjectViewOnStart": "true",
"RunOnceActivity.ShowReadmeOnStart": "true",
"last_opened_file_path": "D:/HIAST/FIY/FS/Distributed Systems/Lab/5/Session/ZookeeperProject/zookeeper-3.9.1-dependency",
"project.structure.last.edited": "Modules",
"project.structure.proportion": "0.15",
"project.structure.side.proportion": "0.2"
<component name="PropertiesComponent">{
&quot;keyToString&quot;: {
&quot;RunOnceActivity.OpenProjectViewOnStart&quot;: &quot;true&quot;,
&quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;,
&quot;last_opened_file_path&quot;: &quot;D:/HIAST/FIY/FS/Distributed Systems/Lab/5/Session/ZookeeperProject/zookeeper-3.9.1-dependency&quot;,
&quot;project.structure.last.edited&quot;: &quot;Modules&quot;,
&quot;project.structure.proportion&quot;: &quot;0.15&quot;,
&quot;project.structure.side.proportion&quot;: &quot;0.2&quot;
}
}]]></component>
}</component>
<component name="RecentsManager">
<key name="CopyFile.RECENT_KEYS">
<recent name="D:\HIAST\FIY\FS\Distributed Systems\Lab\5\Session\ZookeeperProject" />
......
......@@ -10,7 +10,8 @@ public class LeaderElection implements Watcher {
private static final int SESSION_TIMEOUT = 3000;
private ZooKeeper zooKeeper;
public static void main(String[] args) throws IOException, InterruptedException {
public static void main(String[] args) throws IOException, InterruptedException
{
LeaderElection leaderElection = new LeaderElection();
leaderElection.connectToZookeeper();
leaderElection.run();
......@@ -38,12 +39,32 @@ public class LeaderElection implements Watcher {
else if (watchedEvent.getState() == Event.KeeperState.Closed)
{
System.out.println("Connection Closed");
System.exit(0);
synchronized (zooKeeper)
{
zooKeeper.notifyAll();
try {
zooKeeper.close();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
}
else if (watchedEvent.getState() == Event.KeeperState.Disconnected)
{
System.out.println("Disconnected");
System.exit(0);
synchronized (zooKeeper)
{
zooKeeper.notifyAll();
try {
zooKeeper.close();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
///System.exit(0);
}
break;
}
......
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