Class ClusterService
- java.lang.Object
-
- org.elasticsearch.common.component.AbstractLifecycleComponent
-
- org.elasticsearch.cluster.service.ClusterService
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
,LifecycleComponent
,Releasable
public class ClusterService extends AbstractLifecycleComponent
-
-
Field Summary
Fields Modifier and Type Field Description static Setting<TimeValue>
CLUSTER_SERVICE_SLOW_TASK_LOGGING_THRESHOLD_SETTING
static Setting.AffixSetting<java.lang.String>
USER_DEFINED_META_DATA
-
Fields inherited from class org.elasticsearch.common.component.AbstractLifecycleComponent
lifecycle
-
-
Constructor Summary
Constructors Constructor Description ClusterService(Settings settings, ClusterSettings clusterSettings, ThreadPool threadPool, java.util.Map<java.lang.String,java.util.function.Supplier<ClusterState.Custom>> initialClusterStateCustoms)
-
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.static boolean
assertClusterOrMasterStateThread()
protected void
doClose()
protected void
doStart()
protected void
doStop()
ClusterApplierService
getClusterApplierService()
ClusterName
getClusterName()
ClusterSettings
getClusterSettings()
MasterService
getMasterService()
java.lang.String
getNodeName()
The name of this node.Settings
getSettings()
The node's settings.DiscoveryNode
localNode()
The local node.ClusterState.Builder
newClusterStateBuilder()
Creates a new cluster state builder that is initialized with the cluster name and all initial cluster state customs.OperationRouting
operationRouting()
void
removeApplier(ClusterStateApplier applier)
Removes an applier of updated cluster states.void
removeListener(ClusterStateListener listener)
Removes a listener for updated cluster states.void
setNodeConnectionsService(NodeConnectionsService nodeConnectionsService)
ClusterState
state()
The currently applied cluster state.<T extends ClusterStateTaskConfig & ClusterStateTaskExecutor<T> & ClusterStateTaskListener>
voidsubmitStateUpdateTask(java.lang.String source, T updateTask)
Submits a cluster state update task; unlikesubmitStateUpdateTask(String, Object, ClusterStateTaskConfig, ClusterStateTaskExecutor, ClusterStateTaskListener)
, submitted updates will not be batched.<T> void
submitStateUpdateTask(java.lang.String source, T task, ClusterStateTaskConfig config, ClusterStateTaskExecutor<T> executor, ClusterStateTaskListener listener)
Submits a cluster state update task; submitted updates will be batched across the same instance of executor.<T> void
submitStateUpdateTasks(java.lang.String source, java.util.Map<T,ClusterStateTaskListener> tasks, ClusterStateTaskConfig config, ClusterStateTaskExecutor<T> executor)
Submits a batch of cluster state update tasks; submitted updates are guaranteed to be processed together, potentially with more tasks of the same executor.-
Methods inherited from class org.elasticsearch.common.component.AbstractLifecycleComponent
addLifecycleListener, close, lifecycleState, removeLifecycleListener, start, stop
-
-
-
-
Field Detail
-
CLUSTER_SERVICE_SLOW_TASK_LOGGING_THRESHOLD_SETTING
public static final Setting<TimeValue> CLUSTER_SERVICE_SLOW_TASK_LOGGING_THRESHOLD_SETTING
-
USER_DEFINED_META_DATA
public static final Setting.AffixSetting<java.lang.String> USER_DEFINED_META_DATA
-
-
Constructor Detail
-
ClusterService
public ClusterService(Settings settings, ClusterSettings clusterSettings, ThreadPool threadPool, java.util.Map<java.lang.String,java.util.function.Supplier<ClusterState.Custom>> initialClusterStateCustoms)
-
-
Method Detail
-
newClusterStateBuilder
public ClusterState.Builder newClusterStateBuilder()
Creates a new cluster state builder that is initialized with the cluster name and all initial cluster state customs.
-
setNodeConnectionsService
public void setNodeConnectionsService(NodeConnectionsService nodeConnectionsService)
-
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
-
localNode
public DiscoveryNode localNode()
The local node.
-
operationRouting
public OperationRouting operationRouting()
-
state
public ClusterState state()
The currently applied cluster state. TODO: Should be renamed to appliedState / 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.
-
addLocalNodeMasterListener
public void addLocalNodeMasterListener(LocalNodeMasterListener listener)
Add a listener for on/off local node master events
-
getMasterService
public MasterService getMasterService()
-
getClusterApplierService
public ClusterApplierService getClusterApplierService()
-
assertClusterOrMasterStateThread
public static boolean assertClusterOrMasterStateThread()
-
getClusterName
public ClusterName getClusterName()
-
getClusterSettings
public ClusterSettings getClusterSettings()
-
getSettings
public Settings getSettings()
The node's settings.
-
getNodeName
public final java.lang.String getNodeName()
The name of this node.
-
submitStateUpdateTask
public <T extends ClusterStateTaskConfig & ClusterStateTaskExecutor<T> & ClusterStateTaskListener> void submitStateUpdateTask(java.lang.String source, T updateTask)
Submits a cluster state update task; unlikesubmitStateUpdateTask(String, Object, ClusterStateTaskConfig, ClusterStateTaskExecutor, ClusterStateTaskListener)
, submitted updates will not be batched.- Parameters:
source
- the source of the cluster state update taskupdateTask
- the full context for the cluster state update task
-
submitStateUpdateTask
public <T> void submitStateUpdateTask(java.lang.String source, T task, ClusterStateTaskConfig config, ClusterStateTaskExecutor<T> executor, ClusterStateTaskListener listener)
Submits a cluster state update task; submitted updates will be batched across the same instance of executor. The exact batching semantics depend on the underlying implementation but a rough guideline is that if the update task is submitted while there are pending update tasks for the same executor, these update tasks will all be executed on the executor in a single batch- Type Parameters:
T
- the type of the cluster state update task state- Parameters:
source
- the source of the cluster state update tasktask
- the state needed for the cluster state update taskconfig
- the cluster state update task configurationexecutor
- the cluster state update task executor; tasks that share the same executor will be executed batches on this executorlistener
- callback after the cluster state update task completes
-
submitStateUpdateTasks
public <T> void submitStateUpdateTasks(java.lang.String source, java.util.Map<T,ClusterStateTaskListener> tasks, ClusterStateTaskConfig config, ClusterStateTaskExecutor<T> executor)
Submits a batch of cluster state update tasks; submitted updates are guaranteed to be processed together, potentially with more tasks of the same executor.- Type Parameters:
T
- the type of the cluster state update task state- Parameters:
source
- the source of the cluster state update tasktasks
- a map of update tasks and their corresponding listenersconfig
- the cluster state update task configurationexecutor
- the cluster state update task executor; tasks that share the same executor will be executed batches on this executor
-
-