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
180305ef
Commit
180305ef
authored
Nov 29, 2023
by
mohammad.salama
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Exit when Connection is Disconnected or Closed
parent
8baf18bc
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
55 deletions
+25
-55
workspace.xml
.idea/workspace.xml
+1
-41
LeaderElection.java
src/LeaderElection.java
+24
-14
No files found.
.idea/workspace.xml
View file @
180305ef
...
...
@@ -3,47 +3,7 @@
<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$/REAM ME.txt"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/REAM ME.txt"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/ZookeeperProject.iml"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/ZookeeperProject.iml"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/zookeeper-3.8.3/audience-annotations-0.12.0.jar"
beforeDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/zookeeper-3.8.3/commons-io-2.11.0.jar"
beforeDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/zookeeper-3.8.3/logback-classic-1.2.10.jar"
beforeDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/zookeeper-3.8.3/logback-core-1.2.10.jar"
beforeDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/zookeeper-3.8.3/netty-buffer-4.1.94.Final.jar"
beforeDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/zookeeper-3.8.3/netty-codec-4.1.94.Final.jar"
beforeDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/zookeeper-3.8.3/netty-common-4.1.94.Final.jar"
beforeDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/zookeeper-3.8.3/netty-handler-4.1.94.Final.jar"
beforeDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/zookeeper-3.8.3/netty-resolver-4.1.94.Final.jar"
beforeDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/zookeeper-3.8.3/netty-transport-4.1.94.Final.jar"
beforeDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/zookeeper-3.8.3/netty-transport-classes-epoll-4.1.94.Final.jar"
beforeDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/zookeeper-3.8.3/netty-transport-native-epoll-4.1.94.Final.jar"
beforeDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/zookeeper-3.8.3/netty-transport-native-unix-common-4.1.94.Final.jar"
beforeDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/zookeeper-3.8.3/slf4j-api-1.7.30.jar"
beforeDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/zookeeper-3.8.3/zookeeper-3.8.3.jar"
beforeDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/zookeeper-3.8.3/zookeeper-jute-3.8.3.jar"
beforeDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/zookeeper-3.9.1/audience-annotations-0.12.0.jar"
beforeDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/zookeeper-3.9.1/commons-io-2.11.0.jar"
beforeDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/zookeeper-3.9.1/logback-classic-1.2.10.jar"
beforeDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/zookeeper-3.9.1/logback-core-1.2.10.jar"
beforeDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/zookeeper-3.9.1/netty-buffer-4.1.94.Final.jar"
beforeDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/zookeeper-3.9.1/netty-codec-4.1.94.Final.jar"
beforeDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/zookeeper-3.9.1/netty-common-4.1.94.Final.jar"
beforeDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/zookeeper-3.9.1/netty-handler-4.1.94.Final.jar"
beforeDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/zookeeper-3.9.1/netty-resolver-4.1.94.Final.jar"
beforeDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/zookeeper-3.9.1/netty-tcnative-boringssl-static-2.0.61.Final-linux-aarch_64.jar"
beforeDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/zookeeper-3.9.1/netty-tcnative-boringssl-static-2.0.61.Final-linux-x86_64.jar"
beforeDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/zookeeper-3.9.1/netty-tcnative-boringssl-static-2.0.61.Final-osx-aarch_64.jar"
beforeDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/zookeeper-3.9.1/netty-tcnative-boringssl-static-2.0.61.Final-osx-x86_64.jar"
beforeDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/zookeeper-3.9.1/netty-tcnative-boringssl-static-2.0.61.Final-windows-x86_64.jar"
beforeDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/zookeeper-3.9.1/netty-tcnative-boringssl-static-2.0.61.Final.jar"
beforeDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/zookeeper-3.9.1/netty-tcnative-classes-2.0.61.Final.jar"
beforeDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/zookeeper-3.9.1/netty-transport-4.1.94.Final.jar"
beforeDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/zookeeper-3.9.1/netty-transport-classes-epoll-4.1.94.Final.jar"
beforeDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/zookeeper-3.9.1/netty-transport-native-epoll-4.1.94.Final-linux-x86_64.jar"
beforeDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/zookeeper-3.9.1/netty-transport-native-unix-common-4.1.94.Final.jar"
beforeDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/zookeeper-3.9.1/slf4j-api-1.7.30.jar"
beforeDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/zookeeper-3.9.1/zookeeper-3.9.1.jar"
beforeDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/zookeeper-3.9.1/zookeeper-jute-3.9.1.jar"
beforeDir=
"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"
/>
<option
name=
"HIGHLIGHT_CONFLICTS"
value=
"true"
/>
...
...
src/LeaderElection.java
View file @
180305ef
...
...
@@ -4,38 +4,48 @@ import org.apache.zookeeper.ZooKeeper;
import
java.io.IOException
;
public
class
LeaderElection
implements
Watcher
{
public
class
LeaderElection
implements
Watcher
{
private
static
final
String
address
=
"192.168.184.10:2181"
;
private
static
final
int
SESSION_TIMEOUT
=
3000
;
//dead client
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
();
}
public
void
connectToZookeeper
()
throws
IOException
{
public
void
connectToZookeeper
()
throws
IOException
{
this
.
zooKeeper
=
new
ZooKeeper
(
address
,
SESSION_TIMEOUT
,
this
);
}
public
void
run
()
throws
InterruptedException
{
synchronized
(
zooKeeper
)
{
zooKeeper
.
wait
();
synchronized
(
zooKeeper
)
{
zooKeeper
.
wait
();
}
}
@Override
public
void
process
(
WatchedEvent
watchedEvent
)
{
public
void
process
(
WatchedEvent
watchedEvent
)
{
switch
(
watchedEvent
.
getType
())
{
case
None:
if
(
watchedEvent
.
getState
()
==
Event
.
KeeperState
.
SyncConnected
)
{
System
.
out
.
println
(
"Successfully connected to Zookeeper"
);
if
(
watchedEvent
.
getState
()
==
Event
.
KeeperState
.
SyncConnected
)
{
System
.
out
.
println
(
"Successfully connected to ZooKeeper"
);
}
else
if
(
watchedEvent
.
getState
()
==
Event
.
KeeperState
.
Closed
)
{
System
.
out
.
println
(
"Connection Closed"
);
System
.
exit
(
0
);
}
else
if
(
watchedEvent
.
getState
()
==
Event
.
KeeperState
.
Disconnected
)
{
System
.
out
.
println
(
"Disconnected"
);
System
.
exit
(
0
);
}
break
;
}
}
}
}
\ No newline at end of file
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