core/src/main/java/org/elasticsearch/cluster/service/ClusterService.java
public void add(@Nullable final TimeValue timeout, final TimeoutClusterStateListener listener) {
        if (lifecycle.stoppedOrClosed()) {
            listener.onClose();
            return;
        }
        // call the post added notification on the same event thread
        try {
            updateTasksExecutor.execute(new SourcePrioritizedRunnable(Priority.HIGH, "_add_listener_") {
                @Override
                public void run() {
                    if (timeout != null) {
                        NotifyTimeout notifyTimeout = new NotifyTimeout(listener, timeout);
                        notifyTimeout.future = threadPool.schedule(timeout, ThreadPool.Names.GENERIC, notifyTimeout);
                        onGoingTimeouts.add(notifyTimeout);
                    }
                    postAppliedListeners.add(listener);
                    listener.postAdded();
                }
            });
        } catch (EsRejectedExecutionException e) {
            if (lifecycle.stoppedOrClosed()) {
                listener.onClose();
            } else {
                throw e;
            }
        }
    }
/**
     * Adds a cluster state listener that will timeout after the provided timeout,
     * and is executed after the clusterstate has been successfully applied ie. is
     * in state {@link ClusterStateStatus#APPLIED}
     * NOTE: a {@code null} timeout means that the listener will never be removed
     * automatically
     */
Adds a cluster state listener that will timeout after the provided timeout,
and is executed after the clusterstate has been successfully applied ie. is
in state  ClusterStateStatus#APPLIED
NOTE: a  null timeout means that the listener will never be removed
automatically
Adds a cluster state listener that will timeout after the provided timeout and is executed after the clusterstate has been successfully applied ie . is in state ClusterStateStatus#APPLIED NOTE : a null timeout means that the listener will never be removed automatically
public void add(@Nullable final TimeValue timeout, final TimeoutClusterStateListener listener) {
        if (lifecycle.stoppedOrClosed()) {
            listener.onClose();
            return;
        }
        try {
            updateTasksExecutor.execute(new SourcePrioritizedRunnable(Priority.HIGH, "_add_listener_") {
                @Override
                public void run() {
                    if (timeout != null) {
                        NotifyTimeout notifyTimeout = new NotifyTimeout(listener, timeout);
                        notifyTimeout.future = threadPool.schedule(timeout, ThreadPool.Names.GENERIC, notifyTimeout);
                        onGoingTimeouts.add(notifyTimeout);
                    }
                    postAppliedListeners.add(listener);
                    listener.postAdded();
                }
            });
        } catch (EsRejectedExecutionException e) {
            if (lifecycle.stoppedOrClosed()) {
                listener.onClose();
            } else {
                throw e;
            }
        }
    }
public void add ( @ Nullable final TimeValue timeout , final TimeoutClusterStateListener listener ) { if ( lifecycle . stoppedOrClosed ( ) ) { listener . onClose ( ) ; return ; } try { updateTasksExecutor . execute ( new SourcePrioritizedRunnable ( Priority . HIGH , "_add_listener_" ) { @ Override public void run ( ) { if ( timeout != null ) { NotifyTimeout notifyTimeout = new NotifyTimeout ( listener , timeout ) ; notifyTimeout . future = threadPool . schedule ( timeout , ThreadPool . Names . GENERIC , notifyTimeout ) ; onGoingTimeouts . add ( notifyTimeout ) ; } postAppliedListeners . add ( listener ) ; listener . postAdded ( ) ; } } ) ; } catch ( EsRejectedExecutionException e ) { if ( lifecycle . stoppedOrClosed ( ) ) { listener . onClose ( ) ; } else { throw e ; } } }
Adds a cluster state listener that will timeout after the provided timeout,
 and is executed after the clusterstate has been successfully applied ie.
Adds a cluster state listener that will timeout after the provided timeout and is executed after the clusterstate has been successfully applied ie .
// call the post added notification on the same event thread