Package org.elasticsearch.cluster
Class ClusterStateObserver
java.lang.Object
org.elasticsearch.cluster.ClusterStateObserver
A utility class which simplifies interacting with the cluster state in cases where
one tries to take action based on the current state but may want to wait for a new state
and retry upon failure.
-
Nested Class Summary
-
Field Summary
-
Constructor Summary
ConstructorDescriptionClusterStateObserver(ClusterState initialState, ClusterApplierService clusterApplierService, org.elasticsearch.core.TimeValue timeout, org.apache.logging.log4j.Logger logger, ThreadContext contextHolder)
ClusterStateObserver(ClusterState initialState, ClusterService clusterService, org.elasticsearch.core.TimeValue timeout, org.apache.logging.log4j.Logger logger, ThreadContext contextHolder)
ClusterStateObserver(ClusterService clusterService, org.apache.logging.log4j.Logger logger, ThreadContext contextHolder)
ClusterStateObserver(ClusterService clusterService, org.elasticsearch.core.TimeValue timeout, org.apache.logging.log4j.Logger logger, ThreadContext contextHolder)
-
Method Summary
Modifier and TypeMethodDescriptionboolean
indicates whether this observer has timed outsets the last observed state to the currently applied cluster state and returns itvoid
void
waitForNextChange(ClusterStateObserver.Listener listener, Predicate<ClusterState> statePredicate)
void
waitForNextChange(ClusterStateObserver.Listener listener, Predicate<ClusterState> statePredicate, org.elasticsearch.core.TimeValue timeOutValue)
Wait for the next cluster state which satisfies statePredicatevoid
waitForNextChange(ClusterStateObserver.Listener listener, org.elasticsearch.core.TimeValue timeOutValue)
-
Field Details
-
logger
protected final org.apache.logging.log4j.Logger logger
-
-
Constructor Details
-
ClusterStateObserver
public ClusterStateObserver(ClusterService clusterService, org.apache.logging.log4j.Logger logger, ThreadContext contextHolder) -
ClusterStateObserver
public ClusterStateObserver(ClusterService clusterService, @Nullable org.elasticsearch.core.TimeValue timeout, org.apache.logging.log4j.Logger logger, ThreadContext contextHolder)- Parameters:
timeout
- a global timeout for this observer. After it has expired the observer will fail any existing or new #waitForNextChange calls. Set to null to wait indefinitely
-
ClusterStateObserver
public ClusterStateObserver(ClusterState initialState, ClusterService clusterService, @Nullable org.elasticsearch.core.TimeValue timeout, org.apache.logging.log4j.Logger logger, ThreadContext contextHolder)- Parameters:
timeout
- a global timeout for this observer. After it has expired the observer will fail any existing or new #waitForNextChange calls. Set to null to wait indefinitely
-
ClusterStateObserver
public ClusterStateObserver(ClusterState initialState, ClusterApplierService clusterApplierService, @Nullable org.elasticsearch.core.TimeValue timeout, org.apache.logging.log4j.Logger logger, ThreadContext contextHolder)
-
-
Method Details
-
setAndGetObservedState
sets the last observed state to the currently applied cluster state and returns it -
isTimedOut
public boolean isTimedOut()indicates whether this observer has timed out -
waitForNextChange
-
waitForNextChange
public void waitForNextChange(ClusterStateObserver.Listener listener, @Nullable org.elasticsearch.core.TimeValue timeOutValue) -
waitForNextChange
public void waitForNextChange(ClusterStateObserver.Listener listener, Predicate<ClusterState> statePredicate) -
waitForNextChange
public void waitForNextChange(ClusterStateObserver.Listener listener, Predicate<ClusterState> statePredicate, @Nullable org.elasticsearch.core.TimeValue timeOutValue)Wait for the next cluster state which satisfies statePredicate- Parameters:
listener
- callback listenerstatePredicate
- predicate to check whether cluster state changes are relevant and the callback should be calledtimeOutValue
- a timeout for waiting. If null the global observer timeout will be used.
-