public class LeaderInitiator
extends java.lang.Object
implements org.springframework.context.SmartLifecycle, org.springframework.beans.factory.DisposableBean, org.springframework.context.ApplicationEventPublisherAware
candidates
with Hazelcast. Upon construction, start() must be invoked to
register the candidate for leadership election.| Modifier and Type | Class and Description |
|---|---|
protected class |
LeaderInitiator.HazelcastContext
Implementation of leadership context backed by Hazelcast.
|
protected class |
LeaderInitiator.LeaderSelector
Callable that manages the acquisition of Hazelcast locks
for leadership election.
|
| Constructor and Description |
|---|
LeaderInitiator(com.hazelcast.core.HazelcastInstance client)
Construct a
LeaderInitiator with a default candidate. |
LeaderInitiator(com.hazelcast.core.HazelcastInstance client,
org.springframework.integration.leader.Candidate candidate)
Construct a
LeaderInitiator. |
| Modifier and Type | Method and Description |
|---|---|
void |
destroy() |
org.springframework.integration.leader.Context |
getContext()
The context of the initiator or null if not running.
|
int |
getPhase() |
boolean |
isAutoStartup() |
boolean |
isRunning()
true if leadership election for this candidate is running. |
void |
setApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher applicationEventPublisher) |
void |
setAutoStartup(boolean autoStartup) |
void |
setBusyWaitMillis(long busyWaitMillis)
Time in milliseconds to wait in between attempts to acquire the lock, if it is not
held.
|
void |
setHeartBeatMillis(long heartBeatMillis)
Time in milliseconds to wait in between attempts to re-acquire the lock, once it is
held.
|
void |
setLeaderEventPublisher(org.springframework.integration.leader.event.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 callback) |
public LeaderInitiator(com.hazelcast.core.HazelcastInstance client)
LeaderInitiator with a default candidate.client - Hazelcast clientpublic LeaderInitiator(com.hazelcast.core.HazelcastInstance client,
org.springframework.integration.leader.Candidate candidate)
LeaderInitiator.client - Hazelcast clientcandidate - leadership election candidatepublic void setLeaderEventPublisher(org.springframework.integration.leader.event.LeaderEventPublisher leaderEventPublisher)
LeaderEventPublisher.leaderEventPublisher - the event publisherpublic void setHeartBeatMillis(long heartBeatMillis)
heartBeatMillis - the heart-beat timeout in milliseconds.
Defaults to LockRegistryLeaderInitiator.DEFAULT_HEART_BEAT_TIMEpublic void setBusyWaitMillis(long busyWaitMillis)
busyWaitMillis - the busy-wait timeout in milliseconds
Defaults to LockRegistryLeaderInitiator.DEFAULT_BUSY_WAIT_TIMEpublic void setApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher applicationEventPublisher)
setApplicationEventPublisher in interface org.springframework.context.ApplicationEventPublisherAwarepublic void setAutoStartup(boolean autoStartup)
public boolean isAutoStartup()
isAutoStartup in interface org.springframework.context.SmartLifecyclepublic void setPhase(int phase)
public int getPhase()
getPhase in interface org.springframework.context.PhasedgetPhase in interface org.springframework.context.SmartLifecyclepublic org.springframework.integration.leader.Context getContext()
public void start()
candidate for leader election.start in interface org.springframework.context.Lifecyclepublic void stop(java.lang.Runnable callback)
stop in interface org.springframework.context.SmartLifecyclepublic void stop()
candidate for leader election.
If the candidate is currently leader, its leadership will be revoked.stop in interface org.springframework.context.Lifecyclepublic boolean isRunning()
true if leadership election for this candidate is running.isRunning in interface org.springframework.context.Lifecyclecandidate is runningpublic void destroy()
destroy in interface org.springframework.beans.factory.DisposableBean