Class LeaderInitiator
java.lang.Object
org.springframework.integration.hazelcast.leader.LeaderInitiator
- All Implemented Interfaces:
Aware
,DisposableBean
,ApplicationEventPublisherAware
,Lifecycle
,Phased
,SmartLifecycle
public class LeaderInitiator
extends Object
implements SmartLifecycle, DisposableBean, ApplicationEventPublisherAware
Bootstrap leadership
candidates
with Hazelcast. Upon construction, start()
must be invoked to
register the candidate for leadership election.- Author:
- Patrick Peralta, Gary Russell, Dave Syer, Artem Bilan, Mael Le Guével, Alexey Tsoy, Robert Höglund, Christian Tzolov, Emil Palm
-
Nested Class Summary
Modifier and TypeClassDescriptionprotected class
Implementation of leadership context backed by Hazelcast.protected class
Callable that manages the acquisition of Hazelcast locks for leadership election. -
Field Summary
Fields inherited from interface org.springframework.context.SmartLifecycle
DEFAULT_PHASE
-
Constructor Summary
ConstructorDescriptionLeaderInitiator
(com.hazelcast.core.HazelcastInstance client) Construct aLeaderInitiator
with a default candidate.LeaderInitiator
(com.hazelcast.core.HazelcastInstance client, Candidate candidate) Construct aLeaderInitiator
. -
Method Summary
Modifier and TypeMethodDescriptionvoid
destroy()
The context of the initiator or null if not running.int
getPhase()
boolean
boolean
true
if leadership election for thiscandidate
is running.void
setApplicationEventPublisher
(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
(LeaderEventPublisher leaderEventPublisher) Set theLeaderEventPublisher
.void
setPhase
(int phase) void
setTaskExecutor
(AsyncTaskExecutor taskExecutor) Set aAsyncTaskExecutor
for running leadership daemon.void
start()
Start the registration of thecandidate
for leader election.void
stop()
Stop the registration of thecandidate
for leader election.void
-
Constructor Details
-
LeaderInitiator
public LeaderInitiator(com.hazelcast.core.HazelcastInstance client) Construct aLeaderInitiator
with a default candidate.- Parameters:
client
- Hazelcast client
-
LeaderInitiator
Construct aLeaderInitiator
.- Parameters:
client
- Hazelcast clientcandidate
- leadership election candidate
-
-
Method Details
-
setTaskExecutor
Set aAsyncTaskExecutor
for running leadership daemon.- Parameters:
taskExecutor
- theAsyncTaskExecutor
to use.- Since:
- 6.2
-
setLeaderEventPublisher
Set theLeaderEventPublisher
.- Parameters:
leaderEventPublisher
- the event publisher
-
setHeartBeatMillis
public void setHeartBeatMillis(long heartBeatMillis) Time in milliseconds to wait in between attempts to re-acquire the lock, once it is held. The heartbeat time has to be less than the remote lock expiry period, if there is one, otherwise other nodes can steal the lock while we are sleeping here.- Parameters:
heartBeatMillis
- the heart-beat timeout in milliseconds. Defaults toLockRegistryLeaderInitiator.DEFAULT_HEART_BEAT_TIME
- Since:
- 1.0.1
-
setBusyWaitMillis
public void setBusyWaitMillis(long busyWaitMillis) Time in milliseconds to wait in between attempts to acquire the lock, if it is not held. The longer this is, the longer the system can be leaderless, if the leader dies. If a leader dies without releasing its lock, the system might still have to wait for the old lock to expire, but after that it should not have to wait longer than the busy wait time to get a new leader.- Parameters:
busyWaitMillis
- the busy-wait timeout in milliseconds Defaults toLockRegistryLeaderInitiator.DEFAULT_BUSY_WAIT_TIME
- Since:
- 1.0.1
-
setApplicationEventPublisher
- Specified by:
setApplicationEventPublisher
in interfaceApplicationEventPublisherAware
-
setAutoStartup
public void setAutoStartup(boolean autoStartup) -
isAutoStartup
public boolean isAutoStartup()- Specified by:
isAutoStartup
in interfaceSmartLifecycle
-
setPhase
public void setPhase(int phase) -
getPhase
public int getPhase()- Specified by:
getPhase
in interfacePhased
- Specified by:
getPhase
in interfaceSmartLifecycle
-
getContext
The context of the initiator or null if not running.- Returns:
- the context (or null if not running)
-
start
public void start()Start the registration of thecandidate
for leader election. -
stop
- Specified by:
stop
in interfaceSmartLifecycle
-
stop
public void stop()Stop the registration of thecandidate
for leader election. If the candidate is currently leader, its leadership will be revoked. -
isRunning
public boolean isRunning()true
if leadership election for thiscandidate
is running. -
destroy
public void destroy()- Specified by:
destroy
in interfaceDisposableBean
-