Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
L
leader-election-zookeeper
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
mohamadbashar.disoki
leader-election-zookeeper
Commits
88582424
Commit
88582424
authored
Nov 30, 2023
by
Mohamad Bashar Desoki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Handle Disconnect Event to Close Zookeeper
parent
e3c94330
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
0 deletions
+19
-0
Readme.md
Readme.md
+5
-0
LeaderElection.java
src/main/java/LeaderElection.java
+14
-0
No files found.
Readme.md
0 → 100644
View file @
88582424
# 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
src/main/java/LeaderElection.java
View file @
88582424
...
...
@@ -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() == )
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment