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

Connection init - disconnected - closed

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