Class ClusterApplierService
- java.lang.Object
-
- org.elasticsearch.common.component.AbstractLifecycleComponent
-
- org.elasticsearch.cluster.service.ClusterApplierService
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
,ClusterApplier
,LifecycleComponent
,Releasable
public class ClusterApplierService extends AbstractLifecycleComponent implements ClusterApplier
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.elasticsearch.cluster.service.ClusterApplier
ClusterApplier.ClusterApplyListener
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
CLUSTER_UPDATE_THREAD_NAME
protected ThreadPool
threadPool
-
Fields inherited from class org.elasticsearch.common.component.AbstractLifecycleComponent
lifecycle
-
-
Constructor Summary
Constructors Constructor Description ClusterApplierService(java.lang.String nodeName, Settings settings, ClusterSettings clusterSettings, ThreadPool threadPool, java.util.function.Supplier<ClusterState.Builder> stateBuilderSupplier)
-
Method Summary
Modifier and Type Method Description void
addHighPriorityApplier(ClusterStateApplier applier)
Adds a high priority applier of updated cluster states.void
addListener(ClusterStateListener listener)
Add a listener for updated cluster statesvoid
addLocalNodeMasterListener(LocalNodeMasterListener listener)
Add a listener for on/off local node master eventsvoid
addLowPriorityApplier(ClusterStateApplier applier)
Adds an applier which will be called after all high priority and normal appliers have been called.void
addStateApplier(ClusterStateApplier applier)
Adds a applier of updated cluster states.void
addTimeoutListener(TimeValue timeout, TimeoutClusterStateListener listener)
Adds a cluster state listener that is expected to be removed during a short period of time.static boolean
assertNotClusterStateUpdateThread(java.lang.String reason)
asserts that the current thread is NOT the cluster state update threadprotected long
currentTimeInNanos()
protected void
doClose()
protected void
doStart()
protected void
doStop()
ClusterState.Builder
newClusterStateBuilder()
Creates a new cluster state builder that is initialized with the cluster name and all initial cluster state customs.void
onNewClusterState(java.lang.String source, java.util.function.Supplier<ClusterState> clusterStateSupplier, ClusterApplier.ClusterApplyListener listener)
Method to invoke when a new cluster state is available to be appliedvoid
removeApplier(ClusterStateApplier applier)
Removes an applier of updated cluster states.void
removeListener(ClusterStateListener listener)
Removes a listener for updated cluster states.void
removeTimeoutListener(TimeoutClusterStateListener listener)
Removes a timeout listener for updated cluster states.void
runOnApplierThread(java.lang.String source, java.util.function.Consumer<ClusterState> clusterStateConsumer, ClusterApplier.ClusterApplyListener listener)
void
runOnApplierThread(java.lang.String source, java.util.function.Consumer<ClusterState> clusterStateConsumer, ClusterApplier.ClusterApplyListener listener, Priority priority)
protected void
runTask(org.elasticsearch.cluster.service.ClusterApplierService.UpdateTask task)
void
setInitialState(ClusterState initialState)
Sets the initial state for this applier.void
setNodeConnectionsService(NodeConnectionsService nodeConnectionsService)
void
setSlowTaskLoggingThreshold(TimeValue slowTaskLoggingThreshold)
ClusterState
state()
The current cluster state.protected void
warnAboutSlowTaskIfNeeded(TimeValue executionTime, java.lang.String source)
-
Methods inherited from class org.elasticsearch.common.component.AbstractLifecycleComponent
addLifecycleListener, close, lifecycleState, removeLifecycleListener, start, stop
-
-
-
-
Field Detail
-
CLUSTER_UPDATE_THREAD_NAME
public static final java.lang.String CLUSTER_UPDATE_THREAD_NAME
- See Also:
- Constant Field Values
-
threadPool
protected final ThreadPool threadPool
-
-
Constructor Detail
-
ClusterApplierService
public ClusterApplierService(java.lang.String nodeName, Settings settings, ClusterSettings clusterSettings, ThreadPool threadPool, java.util.function.Supplier<ClusterState.Builder> stateBuilderSupplier)
-
-
Method Detail
-
setSlowTaskLoggingThreshold
public void setSlowTaskLoggingThreshold(TimeValue slowTaskLoggingThreshold)
-
setNodeConnectionsService
public void setNodeConnectionsService(NodeConnectionsService nodeConnectionsService)
-
setInitialState
public void setInitialState(ClusterState initialState)
Description copied from interface:ClusterApplier
Sets the initial state for this applier. Should only be called once.- Specified by:
setInitialState
in interfaceClusterApplier
- Parameters:
initialState
- the initial state to set
-
doStart
protected void doStart()
- Specified by:
doStart
in classAbstractLifecycleComponent
-
doStop
protected void doStop()
- Specified by:
doStop
in classAbstractLifecycleComponent
-
doClose
protected void doClose()
- Specified by:
doClose
in classAbstractLifecycleComponent
-
state
public ClusterState state()
The current cluster state. Should be renamed to appliedClusterState
-
addHighPriorityApplier
public void addHighPriorityApplier(ClusterStateApplier applier)
Adds a high priority applier of updated cluster states.
-
addLowPriorityApplier
public void addLowPriorityApplier(ClusterStateApplier applier)
Adds an applier which will be called after all high priority and normal appliers have been called.
-
addStateApplier
public void addStateApplier(ClusterStateApplier applier)
Adds a applier of updated cluster states.
-
removeApplier
public void removeApplier(ClusterStateApplier applier)
Removes an applier of updated cluster states.
-
addListener
public void addListener(ClusterStateListener listener)
Add a listener for updated cluster states
-
removeListener
public void removeListener(ClusterStateListener listener)
Removes a listener for updated cluster states.
-
removeTimeoutListener
public void removeTimeoutListener(TimeoutClusterStateListener listener)
Removes a timeout listener for updated cluster states.
-
addLocalNodeMasterListener
public void addLocalNodeMasterListener(LocalNodeMasterListener listener)
Add a listener for on/off local node master events
-
addTimeoutListener
public void addTimeoutListener(@Nullable TimeValue timeout, TimeoutClusterStateListener listener)
Adds a cluster state listener that is expected to be removed during a short period of time. If provided, the listener will be notified once a specific time has elapsed. NOTE: the listener is not removed on timeout. This is the responsibility of the caller.
-
runOnApplierThread
public void runOnApplierThread(java.lang.String source, java.util.function.Consumer<ClusterState> clusterStateConsumer, ClusterApplier.ClusterApplyListener listener, Priority priority)
-
runOnApplierThread
public void runOnApplierThread(java.lang.String source, java.util.function.Consumer<ClusterState> clusterStateConsumer, ClusterApplier.ClusterApplyListener listener)
-
onNewClusterState
public void onNewClusterState(java.lang.String source, java.util.function.Supplier<ClusterState> clusterStateSupplier, ClusterApplier.ClusterApplyListener listener)
Description copied from interface:ClusterApplier
Method to invoke when a new cluster state is available to be applied- Specified by:
onNewClusterState
in interfaceClusterApplier
- Parameters:
source
- information where the cluster state came fromclusterStateSupplier
- the cluster state supplier which provides the latest cluster state to applylistener
- callback that is invoked after cluster state is applied
-
assertNotClusterStateUpdateThread
public static boolean assertNotClusterStateUpdateThread(java.lang.String reason)
asserts that the current thread is NOT the cluster state update thread
-
runTask
protected void runTask(org.elasticsearch.cluster.service.ClusterApplierService.UpdateTask task)
-
warnAboutSlowTaskIfNeeded
protected void warnAboutSlowTaskIfNeeded(TimeValue executionTime, java.lang.String source)
-
currentTimeInNanos
protected long currentTimeInNanos()
-
newClusterStateBuilder
public ClusterState.Builder newClusterStateBuilder()
Description copied from interface:ClusterApplier
Creates a new cluster state builder that is initialized with the cluster name and all initial cluster state customs.- Specified by:
newClusterStateBuilder
in interfaceClusterApplier
-
-