public class LockRegistryLeaderInitiator
extends java.lang.Object
implements org.springframework.context.SmartLifecycle, org.springframework.beans.factory.DisposableBean, org.springframework.context.ApplicationEventPublisherAware
| Modifier and Type | Class and Description |
|---|---|
protected class |
LockRegistryLeaderInitiator.LeaderSelector |
| Modifier and Type | Field and Description |
|---|---|
static long |
DEFAULT_BUSY_WAIT_TIME |
static long |
DEFAULT_HEART_BEAT_TIME |
| Constructor and Description |
|---|
LockRegistryLeaderInitiator(LockRegistry locks)
Create a new leader initiator with the provided lock registry and a default
candidate (which just logs the leadership events).
|
LockRegistryLeaderInitiator(LockRegistry locks,
Candidate candidate)
Create a new leader initiator.
|
| Modifier and Type | Method and Description |
|---|---|
void |
destroy() |
Context |
getContext() |
int |
getPhase() |
boolean |
isAutoStartup() |
boolean |
isPublishFailedEvents() |
boolean |
isRunning() |
void |
setApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher applicationEventPublisher) |
void |
setAutoStartup(boolean autoStartup) |
void |
setBusyWaitMillis(long busyWaitMillis) |
void |
setExecutorService(java.util.concurrent.ExecutorService executorService)
Set the
ExecutorService, where is not provided then a default of
single thread Executor will be used. |
void |
setHeartBeatMillis(long heartBeatMillis) |
void |
setLeaderEventPublisher(LeaderEventPublisher leaderEventPublisher)
Set the
LeaderEventPublisher. |
void |
setPhase(int phase) |
void |
setPublishFailedEvents(boolean publishFailedEvents)
Enable or disable the publishing of failed events to the
specified applicationEventPublisher.
|
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 runnable) |
public static final long DEFAULT_HEART_BEAT_TIME
public static final long DEFAULT_BUSY_WAIT_TIME
public LockRegistryLeaderInitiator(LockRegistry locks)
locks - lock registrypublic LockRegistryLeaderInitiator(LockRegistry locks, Candidate candidate)
locks - lock registrycandidate - leadership election candidatepublic void setExecutorService(java.util.concurrent.ExecutorService executorService)
ExecutorService, where is not provided then a default of
single thread Executor will be used.executorService - the executor servicepublic void setHeartBeatMillis(long heartBeatMillis)
public void setBusyWaitMillis(long busyWaitMillis)
public void setLeaderEventPublisher(LeaderEventPublisher leaderEventPublisher)
LeaderEventPublisher.leaderEventPublisher - the event publisherpublic void setApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher applicationEventPublisher)
setApplicationEventPublisher in interface org.springframework.context.ApplicationEventPublisherAwarepublic boolean isRunning()
isRunning in interface org.springframework.context.Lifecyclecandidate is running.public int getPhase()
getPhase in interface org.springframework.context.PhasedgetPhase in interface org.springframework.context.SmartLifecyclepublic void setPhase(int phase)
phase - the phaseSmartLifecyclepublic boolean isAutoStartup()
isAutoStartup in interface org.springframework.context.SmartLifecyclepublic void setAutoStartup(boolean autoStartup)
autoStartup - true to start automaticallySmartLifecyclepublic Context getContext()
public boolean isPublishFailedEvents()
public void setPublishFailedEvents(boolean publishFailedEvents)
publishFailedEvents - boolean that if true, failed events will
be published. If false, no failures will be published. Default is false.public void start()
candidate for leader election.start in interface org.springframework.context.Lifecyclepublic void destroy()
destroy in interface org.springframework.beans.factory.DisposableBeanpublic void stop(java.lang.Runnable runnable)
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.Lifecycle