Class LeaderInitiator
java.lang.Object
org.springframework.integration.zookeeper.leader.LeaderInitiator
- All Implemented Interfaces:
Lifecycle
,Phased
,SmartLifecycle
public class LeaderInitiator extends Object implements SmartLifecycle
Bootstrap leadership
candidates
with ZooKeeper/Curator. Upon construction, start()
must be invoked to
register the candidate for leadership election.- Since:
- 4.2
- Author:
- Patrick Peralta, Janne Valkealahti, Gary Russell, Artem Bilan
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected class
LeaderInitiator.LeaderListener
Implementation of Curator leadership election listener. -
Field Summary
-
Constructor Summary
Constructors Constructor Description LeaderInitiator(org.apache.curator.framework.CuratorFramework client, Candidate candidate)
Construct aLeaderInitiator
.LeaderInitiator(org.apache.curator.framework.CuratorFramework client, Candidate candidate, String namespace)
Construct aLeaderInitiator
. -
Method Summary
Modifier and Type Method Description Context
getContext()
The context of the initiator.int
getPhase()
boolean
isAutoStartup()
boolean
isRunning()
void
setAutoStartup(boolean autoStartup)
void
setLeaderEventPublisher(LeaderEventPublisher leaderEventPublisher)
Sets theLeaderEventPublisher
.void
setPhase(int phase)
void
start()
Start the registration of thecandidate
for leader election.void
stop()
Stop the registration of thecandidate
for leader election.
-
Constructor Details
-
LeaderInitiator
Construct aLeaderInitiator
.- Parameters:
client
- Curator clientcandidate
- leadership election candidate
-
LeaderInitiator
public LeaderInitiator(org.apache.curator.framework.CuratorFramework client, Candidate candidate, String namespace)Construct aLeaderInitiator
.- Parameters:
client
- Curator clientcandidate
- leadership election candidatenamespace
- namespace base path in zookeeper
-
-
Method Details
-
isRunning
public boolean isRunning() -
getPhase
public int getPhase()- Specified by:
getPhase
in interfacePhased
- Specified by:
getPhase
in interfaceSmartLifecycle
-
setPhase
public void setPhase(int phase)- Parameters:
phase
- the phase- See Also:
SmartLifecycle
-
isAutoStartup
public boolean isAutoStartup()- Specified by:
isAutoStartup
in interfaceSmartLifecycle
-
setAutoStartup
public void setAutoStartup(boolean autoStartup)- Parameters:
autoStartup
- true to start automatically- See Also:
SmartLifecycle
-
start
public void start()Start the registration of thecandidate
for leader election. -
stop
public void stop()Stop the registration of thecandidate
for leader election. If the candidate is currently leader, its leadership will be revoked. -
setLeaderEventPublisher
Sets theLeaderEventPublisher
.- Parameters:
leaderEventPublisher
- the event publisher
-
getContext
The context of the initiator.- Returns:
- the context.
- Since:
- 5.0
-