Package org.elasticsearch.cluster
Class ClusterStateObserver
- java.lang.Object
-
- org.elasticsearch.cluster.ClusterStateObserver
-
public class ClusterStateObserver extends java.lang.Object
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
Nested Classes Modifier and Type Class Description static interface
ClusterStateObserver.Listener
-
Field Summary
Fields Modifier and Type Field Description protected org.apache.logging.log4j.Logger
logger
-
Constructor Summary
Constructors Constructor Description ClusterStateObserver(ClusterState initialState, ClusterApplierService clusterApplierService, TimeValue timeout, org.apache.logging.log4j.Logger logger, ThreadContext contextHolder)
ClusterStateObserver(ClusterState initialState, ClusterService clusterService, TimeValue timeout, org.apache.logging.log4j.Logger logger, ThreadContext contextHolder)
ClusterStateObserver(ClusterService clusterService, org.apache.logging.log4j.Logger logger, ThreadContext contextHolder)
ClusterStateObserver(ClusterService clusterService, TimeValue timeout, org.apache.logging.log4j.Logger logger, ThreadContext contextHolder)
-
Method Summary
Modifier and Type Method Description boolean
isTimedOut()
indicates whether this observer has timed outClusterState
setAndGetObservedState()
sets the last observed state to the currently applied cluster state and returns itvoid
waitForNextChange(ClusterStateObserver.Listener listener)
void
waitForNextChange(ClusterStateObserver.Listener listener, java.util.function.Predicate<ClusterState> statePredicate)
void
waitForNextChange(ClusterStateObserver.Listener listener, java.util.function.Predicate<ClusterState> statePredicate, TimeValue timeOutValue)
Wait for the next cluster state which satisfies statePredicatevoid
waitForNextChange(ClusterStateObserver.Listener listener, TimeValue timeOutValue)
-
-
-
Constructor Detail
-
ClusterStateObserver
public ClusterStateObserver(ClusterService clusterService, org.apache.logging.log4j.Logger logger, ThreadContext contextHolder)
-
ClusterStateObserver
public ClusterStateObserver(ClusterService clusterService, @Nullable 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 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 TimeValue timeout, org.apache.logging.log4j.Logger logger, ThreadContext contextHolder)
-
-
Method Detail
-
setAndGetObservedState
public ClusterState 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
public void waitForNextChange(ClusterStateObserver.Listener listener)
-
waitForNextChange
public void waitForNextChange(ClusterStateObserver.Listener listener, @Nullable TimeValue timeOutValue)
-
waitForNextChange
public void waitForNextChange(ClusterStateObserver.Listener listener, java.util.function.Predicate<ClusterState> statePredicate)
-
waitForNextChange
public void waitForNextChange(ClusterStateObserver.Listener listener, java.util.function.Predicate<ClusterState> statePredicate, @Nullable 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.
-
-