Class 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.
    • Field Detail

      • logger

        protected final org.apache.logging.log4j.Logger logger
    • 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
    • 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,
                                      java.util.function.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.