Class ClusterStateObserver

java.lang.Object
org.elasticsearch.cluster.ClusterStateObserver

public class ClusterStateObserver extends 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.
  • 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 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 Details

    • 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, 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 listener
      statePredicate - predicate to check whether cluster state changes are relevant and the callback should be called
      timeOutValue - a timeout for waiting. If null the global observer timeout will be used.