public class LeaderInitiator extends Object implements 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.
|
DEFAULT_PHASE| Constructor and Description |
|---|
LeaderInitiator(org.apache.curator.framework.CuratorFramework client,
Candidate candidate)
Construct a
LeaderInitiator. |
LeaderInitiator(org.apache.curator.framework.CuratorFramework client,
Candidate candidate,
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(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,
String namespace)
LeaderInitiator.client - Curator clientcandidate - leadership election candidatenamespace - namespace base path in zookeeperpublic boolean isRunning()
public int getPhase()
getPhase in interface PhasedgetPhase in interface SmartLifecyclepublic void setPhase(int phase)
phase - the phaseSmartLifecyclepublic boolean isAutoStartup()
isAutoStartup in interface SmartLifecyclepublic void setAutoStartup(boolean autoStartup)
autoStartup - true to start automaticallySmartLifecyclepublic void start()
candidate for leader election.public void stop()
candidate for leader election.
If the candidate is currently leader, its leadership will be revoked.public void stop(Runnable runnable)
stop in interface SmartLifecyclepublic void setLeaderEventPublisher(LeaderEventPublisher leaderEventPublisher)
LeaderEventPublisher.leaderEventPublisher - the event publisherpublic Context getContext()