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
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final org.apache.logging.log4j.Loggerstatic final Predicate<ClusterState> -
Constructor Summary
ConstructorsConstructorDescriptionClusterStateObserver(long initialVersion, 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, TimeValue timeout, org.apache.logging.log4j.Logger logger, ThreadContext contextHolder) -
Method Summary
Modifier and TypeMethodDescriptionbooleanindicates whether this observer has timed outsets the last observed state to the currently applied cluster state and returns itvoidvoidwaitForNextChange(ClusterStateObserver.Listener listener, Predicate<ClusterState> statePredicate) voidwaitForNextChange(ClusterStateObserver.Listener listener, Predicate<ClusterState> statePredicate, TimeValue timeOutValue) Wait for the next cluster state which satisfies statePredicatevoidwaitForNextChange(ClusterStateObserver.Listener listener, TimeValue timeOutValue) static voidwaitForState(ClusterService clusterService, ThreadContext threadContext, ClusterStateObserver.Listener listener, Predicate<ClusterState> statePredicate, TimeValue timeout, org.apache.logging.log4j.Logger logger) Waits for the cluster state to match a given predicate.
-
Field Details
-
logger
protected final org.apache.logging.log4j.Logger logger -
NON_NULL_MASTER_PREDICATE
-
-
Constructor Details
-
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(long initialVersion, ClusterApplierService clusterApplierService, @Nullable 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 TimeValue timeOutValue) -
waitForNextChange
public void waitForNextChange(ClusterStateObserver.Listener listener, Predicate<ClusterState> statePredicate) -
waitForNextChange
public void waitForNextChange(ClusterStateObserver.Listener listener, 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.
-
waitForState
public static void waitForState(ClusterService clusterService, ThreadContext threadContext, ClusterStateObserver.Listener listener, Predicate<ClusterState> statePredicate, @Nullable TimeValue timeout, org.apache.logging.log4j.Logger logger) Waits for the cluster state to match a given predicate. UnlikewaitForNextChange(org.elasticsearch.cluster.ClusterStateObserver.Listener)this method checks whether the current state matches the predicate first and resolves the listener directly if it matches without waiting for another cluster state update.- Parameters:
clusterService- cluster servicethreadContext- thread context to resolve listener inlistener- listener to resolve once state matches the predicatestatePredicate- predicate the cluster state has to matchtimeout- timeout for the wait ornullfor no timeoutlogger- logger to use for logging observer messages
-