Skip to content

Commit

Permalink
Fix race condition in adding TimeoutClusterStateListener
Browse files Browse the repository at this point in the history
  • Loading branch information
imotov committed Feb 18, 2013
1 parent 435eabd commit 512585d
Showing 1 changed file with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -189,19 +189,19 @@ public void remove(LocalNodeMasterListener listener) {
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();
}
});
Expand Down

0 comments on commit 512585d

Please sign in to comment.