Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
Z
Zookeeper_Reelection_Leader
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
ali.saeed
Zookeeper_Reelection_Leader
Commits
cf57854e
Commit
cf57854e
authored
Dec 02, 2023
by
Ali Saeed
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Zookeeper reelection leader
parents
Changes
17
Show whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
474 additions
and
0 deletions
+474
-0
Report.pdf
Report.pdf
+0
-0
.name
leader-elecation-zookeeper/.idea/.name
+2
-0
leader_elecation_zookeeper_jar.xml
...keeper/.idea/artifacts/leader_elecation_zookeeper_jar.xml
+32
-0
compiler.xml
leader-elecation-zookeeper/.idea/compiler.xml
+14
-0
encodings.xml
leader-elecation-zookeeper/.idea/encodings.xml
+8
-0
jarRepositories.xml
leader-elecation-zookeeper/.idea/jarRepositories.xml
+21
-0
misc.xml
leader-elecation-zookeeper/.idea/misc.xml
+15
-0
uiDesigner.xml
leader-elecation-zookeeper/.idea/uiDesigner.xml
+125
-0
vcs.xml
leader-elecation-zookeeper/.idea/vcs.xml
+7
-0
workspace.xml
leader-elecation-zookeeper/.idea/workspace.xml
+74
-0
leader-elecation-zookeeper.jar
...er_elecation_zookeeper_jar/leader-elecation-zookeeper.jar
+0
-0
pom.xml
leader-elecation-zookeeper/pom.xml
+36
-0
LeaderElection.java
...n-zookeeper/src/main/java/org/example/LeaderElection.java
+134
-0
MANIFEST.MF
...ecation-zookeeper/src/main/resources/META-INF/MANIFEST.MF
+3
-0
MANIFEST.MF
...r-elecation-zookeeper/target/classes/META-INF/MANIFEST.MF
+3
-0
LeaderElection$1.class
...okeeper/target/classes/org/example/LeaderElection$1.class
+0
-0
LeaderElection.class
...zookeeper/target/classes/org/example/LeaderElection.class
+0
-0
No files found.
Report.pdf
0 → 100644
View file @
cf57854e
File added
leader-elecation-zookeeper/.idea/.name
0 → 100644
View file @
cf57854e
LeaderElection.java
\ No newline at end of file
leader-elecation-zookeeper/.idea/artifacts/leader_elecation_zookeeper_jar.xml
0 → 100644
View file @
cf57854e
<component
name=
"ArtifactManager"
>
<artifact
type=
"jar"
name=
"leader-elecation-zookeeper:jar"
>
<output-path>
$PROJECT_DIR$/out/artifacts/leader_elecation_zookeeper_jar
</output-path>
<root
id=
"archive"
name=
"leader-elecation-zookeeper.jar"
>
<element
id=
"module-output"
name=
"leader-elecation-zookeeper"
/>
<element
id=
"extracted-dir"
path=
"$MAVEN_REPOSITORY$/io/netty/netty-buffer/4.1.94.Final/netty-buffer-4.1.94.Final.jar"
path-in-jar=
"/"
/>
<element
id=
"extracted-dir"
path=
"$MAVEN_REPOSITORY$/io/netty/netty-codec/4.1.94.Final/netty-codec-4.1.94.Final.jar"
path-in-jar=
"/"
/>
<element
id=
"extracted-dir"
path=
"$MAVEN_REPOSITORY$/io/netty/netty-handler/4.1.94.Final/netty-handler-4.1.94.Final.jar"
path-in-jar=
"/"
/>
<element
id=
"extracted-dir"
path=
"$MAVEN_REPOSITORY$/io/netty/netty-common/4.1.94.Final/netty-common-4.1.94.Final.jar"
path-in-jar=
"/"
/>
<element
id=
"extracted-dir"
path=
"$MAVEN_REPOSITORY$/org/slf4j/slf4j-api/1.7.30/slf4j-api-1.7.30.jar"
path-in-jar=
"/"
/>
<element
id=
"extracted-dir"
path=
"$MAVEN_REPOSITORY$/io/netty/netty-tcnative-boringssl-static/2.0.61.Final/netty-tcnative-boringssl-static-2.0.61.Final-osx-aarch_64.jar"
path-in-jar=
"/"
/>
<element
id=
"extracted-dir"
path=
"$MAVEN_REPOSITORY$/ch/qos/logback/logback-core/1.2.10/logback-core-1.2.10.jar"
path-in-jar=
"/"
/>
<element
id=
"extracted-dir"
path=
"$MAVEN_REPOSITORY$/io/netty/netty-transport-classes-epoll/4.1.94.Final/netty-transport-classes-epoll-4.1.94.Final.jar"
path-in-jar=
"/"
/>
<element
id=
"extracted-dir"
path=
"$MAVEN_REPOSITORY$/io/netty/netty-transport-native-unix-common/4.1.94.Final/netty-transport-native-unix-common-4.1.94.Final.jar"
path-in-jar=
"/"
/>
<element
id=
"extracted-dir"
path=
"$MAVEN_REPOSITORY$/ch/qos/logback/logback-classic/1.2.10/logback-classic-1.2.10.jar"
path-in-jar=
"/"
/>
<element
id=
"extracted-dir"
path=
"$MAVEN_REPOSITORY$/commons-io/commons-io/2.11.0/commons-io-2.11.0.jar"
path-in-jar=
"/"
/>
<element
id=
"extracted-dir"
path=
"$MAVEN_REPOSITORY$/io/netty/netty-tcnative-boringssl-static/2.0.61.Final/netty-tcnative-boringssl-static-2.0.61.Final.jar"
path-in-jar=
"/"
/>
<element
id=
"extracted-dir"
path=
"$MAVEN_REPOSITORY$/io/netty/netty-tcnative-boringssl-static/2.0.61.Final/netty-tcnative-boringssl-static-2.0.61.Final-osx-x86_64.jar"
path-in-jar=
"/"
/>
<element
id=
"extracted-dir"
path=
"$MAVEN_REPOSITORY$/org/apache/zookeeper/zookeeper/3.9.1/zookeeper-3.9.1.jar"
path-in-jar=
"/"
/>
<element
id=
"extracted-dir"
path=
"$MAVEN_REPOSITORY$/io/netty/netty-tcnative-boringssl-static/2.0.61.Final/netty-tcnative-boringssl-static-2.0.61.Final-linux-aarch_64.jar"
path-in-jar=
"/"
/>
<element
id=
"extracted-dir"
path=
"$MAVEN_REPOSITORY$/io/netty/netty-tcnative-boringssl-static/2.0.61.Final/netty-tcnative-boringssl-static-2.0.61.Final-windows-x86_64.jar"
path-in-jar=
"/"
/>
<element
id=
"extracted-dir"
path=
"$MAVEN_REPOSITORY$/io/netty/netty-tcnative-classes/2.0.61.Final/netty-tcnative-classes-2.0.61.Final.jar"
path-in-jar=
"/"
/>
<element
id=
"extracted-dir"
path=
"$MAVEN_REPOSITORY$/io/netty/netty-transport-native-epoll/4.1.94.Final/netty-transport-native-epoll-4.1.94.Final-linux-x86_64.jar"
path-in-jar=
"/"
/>
<element
id=
"extracted-dir"
path=
"$MAVEN_REPOSITORY$/org/apache/yetus/audience-annotations/0.12.0/audience-annotations-0.12.0.jar"
path-in-jar=
"/"
/>
<element
id=
"extracted-dir"
path=
"$MAVEN_REPOSITORY$/io/netty/netty-resolver/4.1.94.Final/netty-resolver-4.1.94.Final.jar"
path-in-jar=
"/"
/>
<element
id=
"extracted-dir"
path=
"$MAVEN_REPOSITORY$/io/netty/netty-transport/4.1.94.Final/netty-transport-4.1.94.Final.jar"
path-in-jar=
"/"
/>
<element
id=
"extracted-dir"
path=
"$MAVEN_REPOSITORY$/io/netty/netty-tcnative-boringssl-static/2.0.61.Final/netty-tcnative-boringssl-static-2.0.61.Final-linux-x86_64.jar"
path-in-jar=
"/"
/>
<element
id=
"extracted-dir"
path=
"$MAVEN_REPOSITORY$/org/apache/zookeeper/zookeeper-jute/3.9.1/zookeeper-jute-3.9.1.jar"
path-in-jar=
"/"
/>
</root>
</artifact>
</component>
\ No newline at end of file
leader-elecation-zookeeper/.idea/compiler.xml
0 → 100644
View file @
cf57854e
<?xml version="1.0" encoding="UTF-8"?>
<project
version=
"4"
>
<component
name=
"CompilerConfiguration"
>
<annotationProcessing>
<profile
name=
"Maven default annotation processors profile"
enabled=
"true"
>
<sourceOutputDir
name=
"target/generated-sources/annotations"
/>
<sourceTestOutputDir
name=
"target/generated-test-sources/test-annotations"
/>
<outputRelativeToContentRoot
value=
"true"
/>
<module
name=
"leader-elecation-zookeeper"
/>
</profile>
</annotationProcessing>
</component>
</project>
\ No newline at end of file
leader-elecation-zookeeper/.idea/encodings.xml
0 → 100644
View file @
cf57854e
<?xml version="1.0" encoding="UTF-8"?>
<project
version=
"4"
>
<component
name=
"Encoding"
>
<file
url=
"file://$PROJECT_DIR$/src/main/java"
charset=
"UTF-8"
/>
<file
url=
"file://$PROJECT_DIR$/src/main/resources"
charset=
"UTF-8"
/>
</component>
</project>
\ No newline at end of file
leader-elecation-zookeeper/.idea/jarRepositories.xml
0 → 100644
View file @
cf57854e
<?xml version="1.0" encoding="UTF-8"?>
<project
version=
"4"
>
<component
name=
"RemoteRepositoriesConfiguration"
>
<remote-repository>
<option
name=
"id"
value=
"central"
/>
<option
name=
"name"
value=
"Central Repository"
/>
<option
name=
"url"
value=
"https://repo.maven.apache.org/maven2"
/>
</remote-repository>
<remote-repository>
<option
name=
"id"
value=
"central"
/>
<option
name=
"name"
value=
"Maven Central repository"
/>
<option
name=
"url"
value=
"https://repo1.maven.org/maven2"
/>
</remote-repository>
<remote-repository>
<option
name=
"id"
value=
"jboss.community"
/>
<option
name=
"name"
value=
"JBoss Community repository"
/>
<option
name=
"url"
value=
"https://repository.jboss.org/nexus/content/repositories/public/"
/>
</remote-repository>
</component>
</project>
\ No newline at end of file
leader-elecation-zookeeper/.idea/misc.xml
0 → 100644
View file @
cf57854e
<?xml version="1.0" encoding="UTF-8"?>
<project
version=
"4"
>
<component
name=
"ExternalStorageConfigurationManager"
enabled=
"true"
/>
<component
name=
"MavenProjectsManager"
>
<option
name=
"originalFiles"
>
<list>
<option
value=
"$PROJECT_DIR$/pom.xml"
/>
</list>
</option>
</component>
<component
name=
"ProjectRootManager"
version=
"2"
languageLevel=
"JDK_1_8"
default=
"true"
project-jdk-name=
"1.8"
project-jdk-type=
"JavaSDK"
>
<output
url=
"file://$PROJECT_DIR$/out"
/>
</component>
</project>
\ No newline at end of file
leader-elecation-zookeeper/.idea/uiDesigner.xml
0 → 100644
View file @
cf57854e
<?xml version="1.0" encoding="UTF-8"?>
<project
version=
"4"
>
<component
name=
"Palette2"
>
<group
name=
"Swing"
>
<item
class=
"com.intellij.uiDesigner.HSpacer"
tooltip-text=
"Horizontal Spacer"
icon=
"/com/intellij/uiDesigner/icons/hspacer.svg"
removable=
"false"
auto-create-binding=
"false"
can-attach-label=
"false"
>
<default-constraints
vsize-policy=
"1"
hsize-policy=
"6"
anchor=
"0"
fill=
"1"
/>
</item>
<item
class=
"com.intellij.uiDesigner.VSpacer"
tooltip-text=
"Vertical Spacer"
icon=
"/com/intellij/uiDesigner/icons/vspacer.svg"
removable=
"false"
auto-create-binding=
"false"
can-attach-label=
"false"
>
<default-constraints
vsize-policy=
"6"
hsize-policy=
"1"
anchor=
"0"
fill=
"2"
/>
</item>
<item
class=
"javax.swing.JPanel"
icon=
"/com/intellij/uiDesigner/icons/panel.svg"
removable=
"false"
auto-create-binding=
"false"
can-attach-label=
"false"
>
<default-constraints
vsize-policy=
"3"
hsize-policy=
"3"
anchor=
"0"
fill=
"3"
/>
</item>
<item
class=
"javax.swing.JScrollPane"
icon=
"/com/intellij/uiDesigner/icons/scrollPane.svg"
removable=
"false"
auto-create-binding=
"false"
can-attach-label=
"true"
>
<default-constraints
vsize-policy=
"7"
hsize-policy=
"7"
anchor=
"0"
fill=
"3"
/>
</item>
<item
class=
"javax.swing.JButton"
icon=
"/com/intellij/uiDesigner/icons/button.svg"
removable=
"false"
auto-create-binding=
"true"
can-attach-label=
"false"
>
<default-constraints
vsize-policy=
"0"
hsize-policy=
"3"
anchor=
"0"
fill=
"1"
/>
<initial-values>
<property
name=
"text"
value=
"Button"
/>
</initial-values>
</item>
<item
class=
"javax.swing.JRadioButton"
icon=
"/com/intellij/uiDesigner/icons/radioButton.svg"
removable=
"false"
auto-create-binding=
"true"
can-attach-label=
"false"
>
<default-constraints
vsize-policy=
"0"
hsize-policy=
"3"
anchor=
"8"
fill=
"0"
/>
<initial-values>
<property
name=
"text"
value=
"RadioButton"
/>
</initial-values>
</item>
<item
class=
"javax.swing.JCheckBox"
icon=
"/com/intellij/uiDesigner/icons/checkBox.svg"
removable=
"false"
auto-create-binding=
"true"
can-attach-label=
"false"
>
<default-constraints
vsize-policy=
"0"
hsize-policy=
"3"
anchor=
"8"
fill=
"0"
/>
<initial-values>
<property
name=
"text"
value=
"CheckBox"
/>
</initial-values>
</item>
<item
class=
"javax.swing.JLabel"
icon=
"/com/intellij/uiDesigner/icons/label.svg"
removable=
"false"
auto-create-binding=
"false"
can-attach-label=
"false"
>
<default-constraints
vsize-policy=
"0"
hsize-policy=
"0"
anchor=
"8"
fill=
"0"
/>
<initial-values>
<property
name=
"text"
value=
"Label"
/>
</initial-values>
</item>
<item
class=
"javax.swing.JTextField"
icon=
"/com/intellij/uiDesigner/icons/textField.svg"
removable=
"false"
auto-create-binding=
"true"
can-attach-label=
"true"
>
<default-constraints
vsize-policy=
"0"
hsize-policy=
"6"
anchor=
"8"
fill=
"1"
>
<preferred-size
width=
"150"
height=
"-1"
/>
</default-constraints>
</item>
<item
class=
"javax.swing.JPasswordField"
icon=
"/com/intellij/uiDesigner/icons/passwordField.svg"
removable=
"false"
auto-create-binding=
"true"
can-attach-label=
"true"
>
<default-constraints
vsize-policy=
"0"
hsize-policy=
"6"
anchor=
"8"
fill=
"1"
>
<preferred-size
width=
"150"
height=
"-1"
/>
</default-constraints>
</item>
<item
class=
"javax.swing.JFormattedTextField"
icon=
"/com/intellij/uiDesigner/icons/formattedTextField.svg"
removable=
"false"
auto-create-binding=
"true"
can-attach-label=
"true"
>
<default-constraints
vsize-policy=
"0"
hsize-policy=
"6"
anchor=
"8"
fill=
"1"
>
<preferred-size
width=
"150"
height=
"-1"
/>
</default-constraints>
</item>
<item
class=
"javax.swing.JTextArea"
icon=
"/com/intellij/uiDesigner/icons/textArea.svg"
removable=
"false"
auto-create-binding=
"true"
can-attach-label=
"true"
>
<default-constraints
vsize-policy=
"6"
hsize-policy=
"6"
anchor=
"0"
fill=
"3"
>
<preferred-size
width=
"150"
height=
"50"
/>
</default-constraints>
</item>
<item
class=
"javax.swing.JTextPane"
icon=
"/com/intellij/uiDesigner/icons/textPane.svg"
removable=
"false"
auto-create-binding=
"true"
can-attach-label=
"true"
>
<default-constraints
vsize-policy=
"6"
hsize-policy=
"6"
anchor=
"0"
fill=
"3"
>
<preferred-size
width=
"150"
height=
"50"
/>
</default-constraints>
</item>
<item
class=
"javax.swing.JEditorPane"
icon=
"/com/intellij/uiDesigner/icons/editorPane.svg"
removable=
"false"
auto-create-binding=
"true"
can-attach-label=
"true"
>
<default-constraints
vsize-policy=
"6"
hsize-policy=
"6"
anchor=
"0"
fill=
"3"
>
<preferred-size
width=
"150"
height=
"50"
/>
</default-constraints>
</item>
<item
class=
"javax.swing.JComboBox"
icon=
"/com/intellij/uiDesigner/icons/comboBox.svg"
removable=
"false"
auto-create-binding=
"true"
can-attach-label=
"true"
>
<default-constraints
vsize-policy=
"0"
hsize-policy=
"2"
anchor=
"8"
fill=
"1"
/>
</item>
<item
class=
"javax.swing.JTable"
icon=
"/com/intellij/uiDesigner/icons/table.svg"
removable=
"false"
auto-create-binding=
"true"
can-attach-label=
"false"
>
<default-constraints
vsize-policy=
"6"
hsize-policy=
"6"
anchor=
"0"
fill=
"3"
>
<preferred-size
width=
"150"
height=
"50"
/>
</default-constraints>
</item>
<item
class=
"javax.swing.JList"
icon=
"/com/intellij/uiDesigner/icons/list.svg"
removable=
"false"
auto-create-binding=
"true"
can-attach-label=
"false"
>
<default-constraints
vsize-policy=
"6"
hsize-policy=
"2"
anchor=
"0"
fill=
"3"
>
<preferred-size
width=
"150"
height=
"50"
/>
</default-constraints>
</item>
<item
class=
"javax.swing.JTree"
icon=
"/com/intellij/uiDesigner/icons/tree.svg"
removable=
"false"
auto-create-binding=
"true"
can-attach-label=
"false"
>
<default-constraints
vsize-policy=
"6"
hsize-policy=
"6"
anchor=
"0"
fill=
"3"
>
<preferred-size
width=
"150"
height=
"50"
/>
</default-constraints>
</item>
<item
class=
"javax.swing.JTabbedPane"
icon=
"/com/intellij/uiDesigner/icons/tabbedPane.svg"
removable=
"false"
auto-create-binding=
"true"
can-attach-label=
"false"
>
<default-constraints
vsize-policy=
"3"
hsize-policy=
"3"
anchor=
"0"
fill=
"3"
>
<preferred-size
width=
"200"
height=
"200"
/>
</default-constraints>
</item>
<item
class=
"javax.swing.JSplitPane"
icon=
"/com/intellij/uiDesigner/icons/splitPane.svg"
removable=
"false"
auto-create-binding=
"false"
can-attach-label=
"false"
>
<default-constraints
vsize-policy=
"3"
hsize-policy=
"3"
anchor=
"0"
fill=
"3"
>
<preferred-size
width=
"200"
height=
"200"
/>
</default-constraints>
</item>
<item
class=
"javax.swing.JSpinner"
icon=
"/com/intellij/uiDesigner/icons/spinner.svg"
removable=
"false"
auto-create-binding=
"true"
can-attach-label=
"true"
>
<default-constraints
vsize-policy=
"0"
hsize-policy=
"6"
anchor=
"8"
fill=
"1"
/>
</item>
<item
class=
"javax.swing.JSlider"
icon=
"/com/intellij/uiDesigner/icons/slider.svg"
removable=
"false"
auto-create-binding=
"true"
can-attach-label=
"false"
>
<default-constraints
vsize-policy=
"0"
hsize-policy=
"6"
anchor=
"8"
fill=
"1"
/>
</item>
<item
class=
"javax.swing.JSeparator"
icon=
"/com/intellij/uiDesigner/icons/separator.svg"
removable=
"false"
auto-create-binding=
"false"
can-attach-label=
"false"
>
<default-constraints
vsize-policy=
"6"
hsize-policy=
"6"
anchor=
"0"
fill=
"3"
/>
</item>
<item
class=
"javax.swing.JProgressBar"
icon=
"/com/intellij/uiDesigner/icons/progressbar.svg"
removable=
"false"
auto-create-binding=
"true"
can-attach-label=
"false"
>
<default-constraints
vsize-policy=
"0"
hsize-policy=
"6"
anchor=
"0"
fill=
"1"
/>
</item>
<item
class=
"javax.swing.JToolBar"
icon=
"/com/intellij/uiDesigner/icons/toolbar.svg"
removable=
"false"
auto-create-binding=
"false"
can-attach-label=
"false"
>
<default-constraints
vsize-policy=
"0"
hsize-policy=
"6"
anchor=
"0"
fill=
"1"
>
<preferred-size
width=
"-1"
height=
"20"
/>
</default-constraints>
</item>
<item
class=
"javax.swing.JToolBar$Separator"
icon=
"/com/intellij/uiDesigner/icons/toolbarSeparator.svg"
removable=
"false"
auto-create-binding=
"false"
can-attach-label=
"false"
>
<default-constraints
vsize-policy=
"0"
hsize-policy=
"0"
anchor=
"0"
fill=
"1"
/>
</item>
<item
class=
"javax.swing.JScrollBar"
icon=
"/com/intellij/uiDesigner/icons/scrollbar.svg"
removable=
"false"
auto-create-binding=
"true"
can-attach-label=
"false"
>
<default-constraints
vsize-policy=
"6"
hsize-policy=
"0"
anchor=
"0"
fill=
"2"
/>
</item>
</group>
</component>
</project>
\ No newline at end of file
leader-elecation-zookeeper/.idea/vcs.xml
0 → 100644
View file @
cf57854e
<?xml version="1.0" encoding="UTF-8"?>
<project
version=
"4"
>
<component
name=
"VcsDirectoryMappings"
>
<mapping
directory=
"$PROJECT_DIR$"
vcs=
"Git"
/>
</component>
</project>
\ No newline at end of file
leader-elecation-zookeeper/.idea/workspace.xml
0 → 100644
View file @
cf57854e
<?xml version="1.0" encoding="UTF-8"?>
<project
version=
"4"
>
<component
name=
"ArtifactsWorkspaceSettings"
>
<artifacts-to-build>
<artifact
name=
"leader-elecation-zookeeper:jar"
/>
</artifacts-to-build>
</component>
<component
name=
"AutoImportSettings"
>
<option
name=
"autoReloadType"
value=
"SELECTIVE"
/>
</component>
<component
name=
"ChangeListManager"
>
<list
default=
"true"
id=
"9fb9d77f-8cfe-4348-8d8d-465141541b74"
name=
"Changes"
comment=
""
>
<change
afterPath=
"$PROJECT_DIR$/.gitignore"
afterDir=
"false"
/>
<change
afterPath=
"$PROJECT_DIR$/.idea/artifacts/leader_elecation_zookeeper_jar.xml"
afterDir=
"false"
/>
<change
afterPath=
"$PROJECT_DIR$/.idea/encodings.xml"
afterDir=
"false"
/>
<change
afterPath=
"$PROJECT_DIR$/.idea/misc.xml"
afterDir=
"false"
/>
<change
afterPath=
"$PROJECT_DIR$/.idea/uiDesigner.xml"
afterDir=
"false"
/>
<change
afterPath=
"$PROJECT_DIR$/.idea/vcs.xml"
afterDir=
"false"
/>
<change
afterPath=
"$PROJECT_DIR$/.idea/workspace.xml"
afterDir=
"false"
/>
<change
afterPath=
"$PROJECT_DIR$/pom.xml"
afterDir=
"false"
/>
<change
afterPath=
"$PROJECT_DIR$/src/main/java/org/example/LeaderElection.java"
afterDir=
"false"
/>
</list>
<option
name=
"SHOW_DIALOG"
value=
"false"
/>
<option
name=
"HIGHLIGHT_CONFLICTS"
value=
"true"
/>
<option
name=
"HIGHLIGHT_NON_ACTIVE_CHANGELIST"
value=
"false"
/>
<option
name=
"LAST_RESOLUTION"
value=
"IGNORE"
/>
</component>
<component
name=
"Git.Settings"
>
<option
name=
"RECENT_GIT_ROOT_PATH"
value=
"$PROJECT_DIR$"
/>
</component>
<component
name=
"MarkdownSettingsMigration"
>
<option
name=
"stateVersion"
value=
"1"
/>
</component>
<component
name=
"ProjectId"
id=
"2YlnEPbBHiL2w50RUCTE4gNn99H"
/>
<component
name=
"ProjectLevelVcsManager"
settingsEditedManually=
"true"
/>
<component
name=
"ProjectViewState"
>
<option
name=
"hideEmptyMiddlePackages"
value=
"true"
/>
<option
name=
"showLibraryContents"
value=
"true"
/>
</component>
<component
name=
"PropertiesComponent"
>
<![CDATA[{
"keyToString": {
"RunOnceActivity.OpenProjectViewOnStart": "true",
"RunOnceActivity.ShowReadmeOnStart": "true",
"SHARE_PROJECT_CONFIGURATION_FILES": "true",
"last_opened_file_path": "D:/leader-elecation-zookeeper",
"project.structure.last.edited": "Artifacts",
"project.structure.proportion": "0.15",
"project.structure.side.proportion": "0.2"
}
}]]>
</component>
<component
name=
"SpellCheckerSettings"
RuntimeDictionaries=
"0"
Folders=
"0"
CustomDictionaries=
"0"
DefaultDictionary=
"application-level"
UseSingleDictionary=
"true"
transferred=
"true"
/>
<component
name=
"TaskManager"
>
<task
active=
"true"
id=
"Default"
summary=
"Default task"
>
<changelist
id=
"9fb9d77f-8cfe-4348-8d8d-465141541b74"
name=
"Changes"
comment=
""
/>
<created>
1701108928238
</created>
<option
name=
"number"
value=
"Default"
/>
<option
name=
"presentableId"
value=
"Default"
/>
<updated>
1701108928238
</updated>
</task>
<servers
/>
</component>
<component
name=
"Vcs.Log.Tabs.Properties"
>
<option
name=
"TAB_STATES"
>
<map>
<entry
key=
"MAIN"
>
<value>
<State
/>
</value>
</entry>
</map>
</option>
</component>
</project>
\ No newline at end of file
leader-elecation-zookeeper/out/artifacts/leader_elecation_zookeeper_jar/leader-elecation-zookeeper.jar
0 → 100644
View file @
cf57854e
File added
leader-elecation-zookeeper/pom.xml
0 → 100644
View file @
cf57854e
<?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-elecation-zookeeper
</artifactId>
<version>
1.0-SNAPSHOT
</version>
<properties>
<maven.compiler.source>
8
</maven.compiler.source>
<maven.compiler.target>
8
</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>
8
</source>
<target>
8
</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
leader-elecation-zookeeper/src/main/java/org/example/LeaderElection.java
0 → 100644
View file @
cf57854e
package
org
.
example
;
import
org.apache.zookeeper.*
;
import
org.apache.zookeeper.data.Stat
;
import
java.io.IOException
;
import
java.util.Collections
;
import
java.util.List
;
public
class
LeaderElection
implements
Watcher
{
private
static
final
String
ADDRESS
=
"192.168.181.136:2181"
;
private
static
final
int
SESSION_TIMEOUT
=
3000
;
private
static
final
String
ELECTION_NAMESPACE
=
"/election"
;
private
static
final
String
LEADER_NODE_PREFIX
=
"leader-"
;
private
String
currentNodePath
;
private
String
previousNodePath
;
private
ZooKeeper
zooKeeper
;
private
Stat
previousNodeStat
;
public
static
void
main
(
String
[]
args
)
throws
IOException
,
InterruptedException
,
KeeperException
{
LeaderElection
leaderElection
=
new
LeaderElection
();
leaderElection
.
connectToZookeeper
();
leaderElection
.
volunteerForLeadership
();
leaderElection
.
electLeader
();
leaderElection
.
run
();
}
public
void
connectToZookeeper
()
throws
IOException
{
this
.
zooKeeper
=
new
ZooKeeper
(
ADDRESS
,
SESSION_TIMEOUT
,
this
);
}
public
void
run
()
{
synchronized
(
zooKeeper
)
{
try
{
zooKeeper
.
wait
();
// Wait for events
}
catch
(
InterruptedException
e
)
{
System
.
out
.
println
(
e
.
getMessage
());
}
}
try
{
zooKeeper
.
close
();
}
catch
(
InterruptedException
e
)
{
throw
new
RuntimeException
(
e
);
}
}
public
void
volunteerForLeadership
()
throws
InterruptedException
,
KeeperException
{
String
znodeFullPath
=
zooKeeper
.
create
(
ELECTION_NAMESPACE
+
"/"
+
LEADER_NODE_PREFIX
,
new
byte
[]{},
ZooDefs
.
Ids
.
OPEN_ACL_UNSAFE
,
CreateMode
.
EPHEMERAL_SEQUENTIAL
);
System
.
out
.
println
(
"Created znode: "
+
znodeFullPath
);
this
.
currentNodePath
=
znodeFullPath
.
replace
(
ELECTION_NAMESPACE
+
"/"
,
""
);
}
public
void
electLeader
()
throws
InterruptedException
,
KeeperException
{
List
<
String
>
children
=
zooKeeper
.
getChildren
(
ELECTION_NAMESPACE
,
false
);
Collections
.
sort
(
children
);
int
currentNodeIndex
=
children
.
indexOf
(
currentNodePath
);
if
(
currentNodeIndex
==
0
)
{
becomeLeader
();
}
else
{
String
previousNodeName
=
children
.
get
(
currentNodeIndex
-
1
);
previousNodePath
=
ELECTION_NAMESPACE
+
"/"
+
previousNodeName
;
System
.
out
.
println
(
"I'm not the leader, the leader is: "
+
children
.
get
(
0
));
watchPreviousNode
();
}
}
private
void
becomeLeader
()
throws
KeeperException
,
InterruptedException
{
System
.
out
.
println
(
"I'm the leader"
);
// Notify other nodes that you are the leader
String
leaderData
=
"Leader: "
+
currentNodePath
;
zooKeeper
.
setData
(
ELECTION_NAMESPACE
+
"/"
+
currentNodePath
,
leaderData
.
getBytes
(),
-
1
);
}
private
void
watchPreviousNode
()
throws
KeeperException
,
InterruptedException
{
previousNodeStat
=
zooKeeper
.
exists
(
previousNodePath
,
this
);
if
(
previousNodeStat
!=
null
)
{
System
.
out
.
println
(
"Watching previous node: "
+
previousNodePath
);
}
}
private
void
setData
()
throws
InterruptedException
,
KeeperException
{
// Retrieve leader data from the previous leader's znode, because it contains our new leader
byte
[]
data
=
zooKeeper
.
getData
(
previousNodePath
,
this
,
previousNodeStat
);
String
leaderData
=
new
String
(
data
);
zooKeeper
.
setData
(
ELECTION_NAMESPACE
+
"/"
+
currentNodePath
,
data
,-
1
);
System
.
out
.
println
(
"Current leader: "
+
leaderData
);
}
@Override
public
void
process
(
WatchedEvent
watchedEvent
)
{
switch
(
watchedEvent
.
getType
())
{
case
None:
if
(
watchedEvent
.
getState
()
==
Event
.
KeeperState
.
SyncConnected
)
{
System
.
out
.
println
(
"Successfully connected to ZooKeeper"
);
}
else
if
(
watchedEvent
.
getState
()
==
Event
.
KeeperState
.
Disconnected
)
{
System
.
out
.
println
(
"Disconnected from ZooKeeper. Shutting down the program."
);
synchronized
(
zooKeeper
)
{
zooKeeper
.
notifyAll
();
}
}
break
;
case
NodeDeleted:
if
(
watchedEvent
.
getPath
().
equals
(
previousNodePath
))
{
System
.
out
.
println
(
"Previous leader node deleted. Attempting to become the new leader..."
);
try
{
electLeader
();
}
catch
(
InterruptedException
|
KeeperException
e
)
{
throw
new
RuntimeException
(
e
);
}
}
break
;
case
NodeDataChanged:
if
(
watchedEvent
.
getPath
().
equals
(
previousNodePath
))
{
System
.
out
.
println
(
"Previous leader data changed. maybe we have a new leader ."
);
try
{
setData
();
}
catch
(
InterruptedException
|
KeeperException
e
)
{
throw
new
RuntimeException
(
e
);
}
}
break
;
default
:
break
;
}
}
}
\ No newline at end of file
leader-elecation-zookeeper/src/main/resources/META-INF/MANIFEST.MF
0 → 100644
View file @
cf57854e
Manifest-Version: 1.0
Main-Class: org.example.LeaderElection
leader-elecation-zookeeper/target/classes/META-INF/MANIFEST.MF
0 → 100644
View file @
cf57854e
Manifest-Version: 1.0
Main-Class: org.example.LeaderElection
leader-elecation-zookeeper/target/classes/org/example/LeaderElection$1.class
0 → 100644
View file @
cf57854e
File added
leader-elecation-zookeeper/target/classes/org/example/LeaderElection.class
0 → 100644
View file @
cf57854e
File added
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