Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
Z
Zookeeper-DS05
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
mohammad.salama
Zookeeper-DS05
Commits
ad3fde9b
Commit
ad3fde9b
authored
Nov 30, 2023
by
mohammad.salama
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Init-Disconnect-Close
parent
e9fc63f0
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
17 deletions
+15
-17
workspace.xml
.idea/workspace.xml
+0
-1
LeaderElection.java
src/LeaderElection.java
+15
-16
No files found.
.idea/workspace.xml
View file @
ad3fde9b
...
...
@@ -2,7 +2,6 @@
<project
version=
"4"
>
<component
name=
"ChangeListManager"
>
<list
default=
"true"
id=
"c96503bf-3b6e-4ec0-9a0f-c9d3e8c6ffc7"
name=
"Changes"
comment=
""
>
<change
beforePath=
"$PROJECT_DIR$/.idea/workspace.xml"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/.idea/workspace.xml"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/src/LeaderElection.java"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/src/LeaderElection.java"
afterDir=
"false"
/>
</list>
<option
name=
"SHOW_DIALOG"
value=
"false"
/>
...
...
src/LeaderElection.java
View file @
ad3fde9b
...
...
@@ -15,8 +15,18 @@ public class LeaderElection implements Watcher {
LeaderElection
leaderElection
=
new
LeaderElection
();
leaderElection
.
connectToZookeeper
();
leaderElection
.
run
();
leaderElection
.
close
();
}
private
void
close
()
{
synchronized
(
zooKeeper
)
{
try
{
zooKeeper
.
close
();
}
catch
(
InterruptedException
e
)
{
throw
new
RuntimeException
(
e
);
}
}
}
public
void
connectToZookeeper
()
throws
IOException
{
this
.
zooKeeper
=
new
ZooKeeper
(
address
,
SESSION_TIMEOUT
,
this
);
}
...
...
@@ -29,8 +39,10 @@ public class LeaderElection implements Watcher {
}
@Override
public
void
process
(
WatchedEvent
watchedEvent
)
{
switch
(
watchedEvent
.
getType
())
{
public
void
process
(
WatchedEvent
watchedEvent
)
{
switch
(
watchedEvent
.
getType
())
{
case
None:
if
(
watchedEvent
.
getState
()
==
Event
.
KeeperState
.
SyncConnected
)
{
...
...
@@ -42,13 +54,7 @@ public class LeaderElection implements Watcher {
synchronized
(
zooKeeper
)
{
zooKeeper
.
notifyAll
();
try
{
zooKeeper
.
close
();
}
catch
(
InterruptedException
e
)
{
throw
new
RuntimeException
(
e
);
}
}
}
else
if
(
watchedEvent
.
getState
()
==
Event
.
KeeperState
.
Disconnected
)
...
...
@@ -56,15 +62,8 @@ public class LeaderElection implements Watcher {
System
.
out
.
println
(
"Disconnected"
);
synchronized
(
zooKeeper
)
{
zooKeeper
.
notifyAll
();
try
{
zooKeeper
.
close
();
}
catch
(
InterruptedException
e
)
{
throw
new
RuntimeException
(
e
);
}
}
///System.exit(0);
}
break
;
}
...
...
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