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
d908ee05
Commit
d908ee05
authored
Dec 01, 2023
by
Mohamad Bashar Desoki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Leader reelection Attempt 1
parent
2879dbfc
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
2 deletions
+14
-2
Readme.md
Readme.md
+4
-1
LeaderElection.java
src/main/java/LeaderElection.java
+10
-1
No files found.
Readme.md
View file @
d908ee05
...
...
@@ -7,8 +7,11 @@
*
Zookeeper Client Threading Model & Zookeeper Java API
*
Leader Election Implementation
*
Watchers, Triggers and Introduction to Failure Detection
*
Herd Effect
*
Leader reelection Attempt 1 (with Herd Effect)
*Useful links*
*
[
Class ZooKeeper
](
https://zookeeper.apache.org/doc/r3.9.1/apidocs/zookeeper-server/org/apache/zookeeper/ZooKeeper.html
)
*
[
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
*
[
wait notify and notifyall in java
](
https://javarevisited.blogspot.com/2011/05/wait-notify-and-notifyall-in-java.html
)
*
[
Zookeeper Tutorial
](
https://bikas-katwal.medium.com/zookeeper-introduction-designing-a-distributed-system-using-zookeeper-and-java-7f1b108e236e
)
\ No newline at end of file
src/main/java/LeaderElection.java
View file @
d908ee05
...
...
@@ -33,7 +33,7 @@ public class LeaderElection implements Watcher {
}
public
void
electLeader
()
throws
InterruptedException
,
KeeperException
{
List
<
String
>
children
=
zooKeeper
.
getChildren
(
ELECTION_NAMESPACE
,
false
);
List
<
String
>
children
=
zooKeeper
.
getChildren
(
ELECTION_NAMESPACE
,
this
);
Collections
.
sort
(
children
);
String
smallestChild
=
children
.
get
(
0
);
//the first element
...
...
@@ -74,6 +74,15 @@ public class LeaderElection implements Watcher {
}
else
if
(
watchedEvent
.
getState
()
==
Event
.
KeeperState
.
Closed
)
{
System
.
out
.
println
(
"Closed Successfully"
);
}
case
NodeChildrenChanged:
try
{
electLeader
();
System
.
out
.
println
(
ELECTION_NAMESPACE
+
" NodeChildrenChanged"
);
}
catch
(
InterruptedException
e
)
{
throw
new
RuntimeException
(
e
);
}
catch
(
KeeperException
e
)
{
throw
new
RuntimeException
(
e
);
}
}
}
...
...
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