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. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
stop
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 Phased
getPhase
in interface SmartLifecycle
public void setPhase(int phase)
phase
- the phaseSmartLifecycle
public boolean isAutoStartup()
isAutoStartup
in interface SmartLifecycle
public void setAutoStartup(boolean autoStartup)
autoStartup
- true to start automaticallySmartLifecycle
public 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 setLeaderEventPublisher(LeaderEventPublisher leaderEventPublisher)
LeaderEventPublisher
.leaderEventPublisher
- the event publisherpublic Context getContext()