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
e3c94330
Commit
e3c94330
authored
Nov 23, 2023
by
Mohamad Bashar Desoki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Connect to Zookeeper
parents
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
114 additions
and
0 deletions
+114
-0
.gitignore
.gitignore
+39
-0
pom.xml
pom.xml
+38
-0
LeaderElection.java
src/main/java/LeaderElection.java
+37
-0
No files found.
.gitignore
0 → 100644
View file @
e3c94330
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
### IntelliJ IDEA ###
.idea/modules.xml
.idea/jarRepositories.xml
.idea/compiler.xml
.idea/libraries/
*.iws
*.iml
*.ipr
### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/
### VS Code ###
.vscode/
### Mac OS ###
.DS_Store
\ No newline at end of file
pom.xml
0 → 100644
View file @
e3c94330
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<modelVersion>
4.0.0
</modelVersion>
<groupId>
org.example
</groupId>
<artifactId>
leader-election
</artifactId>
<version>
1.0-SNAPSHOT
</version>
<properties>
<maven.compiler.source>
17
</maven.compiler.source>
<maven.compiler.target>
17
</maven.compiler.target>
<project.build.sourceEncoding>
UTF-8
</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-compiler-plugin
</artifactId>
<version>
3.11.0
</version>
<configuration>
<source>
17
</source>
<target>
17
</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>
org.apache.zookeeper
</groupId>
<artifactId>
zookeeper
</artifactId>
<version>
3.9.1
</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
src/main/java/LeaderElection.java
0 → 100644
View file @
e3c94330
import
org.apache.zookeeper.WatchedEvent
;
import
org.apache.zookeeper.Watcher
;
import
org.apache.zookeeper.ZooKeeper
;
import
java.io.IOException
;
public
class
LeaderElection
implements
Watcher
{
private
static
final
String
address
=
"172.29.3.101:2181"
;
private
static
final
int
SESSION_TIMEOUT
=
3000
;
//dead client
private
ZooKeeper
zooKeeper
;
public
static
void
main
(
String
[]
args
)
throws
IOException
,
InterruptedException
{
LeaderElection
leaderElection
=
new
LeaderElection
();
leaderElection
.
connectToZookeeper
();
leaderElection
.
run
();
}
public
void
connectToZookeeper
()
throws
IOException
{
this
.
zooKeeper
=
new
ZooKeeper
(
address
,
SESSION_TIMEOUT
,
this
);
}
public
void
run
()
throws
InterruptedException
{
synchronized
(
zooKeeper
)
{
zooKeeper
.
wait
();
}
}
@Override
public
void
process
(
WatchedEvent
watchedEvent
)
{
switch
(
watchedEvent
.
getType
())
{
case
None:
if
(
watchedEvent
.
getState
()
==
Event
.
KeeperState
.
SyncConnected
)
{
System
.
out
.
println
(
"Successfully connected to Zookeeper"
);
}
}
}
}
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