public class LeaderInitiator
extends java.lang.Object
implements org.springframework.context.SmartLifecycle
candidates
with ZooKeeper/Curator. Upon construction, start() must be invoked to
register the candidate for leadership election.| Modifier and Type | Class and Description |
|---|---|
protected class |
LeaderInitiator.LeaderListener
Implementation of Curator leadership election listener.
|
| Constructor and Description |
|---|
LeaderInitiator(org.apache.curator.framework.CuratorFramework client,
Candidate candidate)
Construct a
LeaderInitiator. |
LeaderInitiator(org.apache.curator.framework.CuratorFramework client,
Candidate candidate,
java.lang.String namespace)
Construct a
LeaderInitiator. |
| Modifier and Type | Method and Description |
|---|---|
Context |
getContext()
The context of the initiator.
|
int |
getPhase() |
boolean |
isAutoStartup() |
boolean |
isRunning() |
void |
setAutoStartup(boolean autoStartup) |
void |
setLeaderEventPublisher(LeaderEventPublisher leaderEventPublisher)
Sets the
LeaderEventPublisher. |
void |
setPhase(int phase) |
void |
start()
Start the registration of the
candidate for leader election. |
void |
stop()
Stop the registration of the
candidate for leader election. |
void |
stop(java.lang.Runnable runnable) |
public LeaderInitiator(org.apache.curator.framework.CuratorFramework client,
Candidate candidate)
LeaderInitiator.client - Curator clientcandidate - leadership election candidatepublic LeaderInitiator(org.apache.curator.framework.CuratorFramework client,
Candidate candidate,
java.lang.String namespace)
LeaderInitiator.client - Curator clientcandidate - leadership election candidatenamespace - namespace base path in zookeeperpublic boolean isRunning()
isRunning in interface org.springframework.context.Lifecyclecandidate is runningpublic int getPhase()
getPhase in interface org.springframework.context.PhasedgetPhase in interface org.springframework.context.SmartLifecyclepublic void setPhase(int phase)
phase - the phaseSmartLifecyclepublic boolean isAutoStartup()
isAutoStartup in interface org.springframework.context.SmartLifecyclepublic void setAutoStartup(boolean autoStartup)
autoStartup - true to start automaticallySmartLifecyclepublic void start()
candidate for leader election.start in interface org.springframework.context.Lifecyclepublic void stop()
candidate for leader election.
If the candidate is currently leader, its leadership will be revoked.stop in interface org.springframework.context.Lifecyclepublic void stop(java.lang.Runnable runnable)
stop in interface org.springframework.context.SmartLifecyclepublic void setLeaderEventPublisher(LeaderEventPublisher leaderEventPublisher)
LeaderEventPublisher.leaderEventPublisher - the event publisherpublic Context getContext()