clean timeout listener from on going listeners once its removed

This commit is contained in:
kimchy 2010-07-20 21:11:56 +03:00
parent f4064038e4
commit 1ff8b43aa7
1 changed files with 6 additions and 3 deletions

View File

@ -36,6 +36,7 @@ import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.timer.TimerService; import org.elasticsearch.timer.TimerService;
import org.elasticsearch.transport.TransportService; import org.elasticsearch.transport.TransportService;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Queue; import java.util.Queue;
import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.CopyOnWriteArrayList;
@ -107,9 +108,11 @@ public class InternalClusterService extends AbstractLifecycleComponent<ClusterSe
public void remove(ClusterStateListener listener) { public void remove(ClusterStateListener listener) {
clusterStateListeners.remove(listener); clusterStateListeners.remove(listener);
for (Tuple<Timeout, NotifyTimeout> onGoingTimeout : onGoingTimeouts) { for (Iterator<Tuple<Timeout, NotifyTimeout>> it = onGoingTimeouts.iterator(); it.hasNext();) {
if (onGoingTimeout.v2().listener == listener) { Tuple<Timeout, NotifyTimeout> tuple = it.next();
onGoingTimeout.v1().cancel(); if (tuple.v2().listener.equals(listener)) {
tuple.v1().cancel();
it.remove();
} }
} }
} }