Fix race condition in adding TimeoutClusterStateListener

Fixes #2658
This commit is contained in:
Igor Motov 2013-02-16 16:44:33 -05:00
parent 435eabd4a0
commit 512585da82
1 changed files with 5 additions and 5 deletions

View File

@ -189,19 +189,19 @@ public class InternalClusterService extends AbstractLifecycleComponent<ClusterSe
localNodeMasterListeners.remove(listener);
}
public void add(TimeValue timeout, final TimeoutClusterStateListener listener) {
public void add(final TimeValue timeout, final TimeoutClusterStateListener listener) {
if (lifecycle.stoppedOrClosed()) {
listener.onClose();
return;
}
NotifyTimeout notifyTimeout = new NotifyTimeout(listener, timeout);
notifyTimeout.future = threadPool.schedule(timeout, ThreadPool.Names.GENERIC, notifyTimeout);
onGoingTimeouts.add(notifyTimeout);
clusterStateListeners.add(listener);
// call the post added notification on the same event thread
updateTasksExecutor.execute(new Runnable() {
@Override
public void run() {
NotifyTimeout notifyTimeout = new NotifyTimeout(listener, timeout);
notifyTimeout.future = threadPool.schedule(timeout, ThreadPool.Names.GENERIC, notifyTimeout);
onGoingTimeouts.add(notifyTimeout);
clusterStateListeners.add(listener);
listener.postAdded();
}
});