diff --git a/src/main/java/org/jboss/netty/handler/timeout/HashedWheelTimer.java b/src/main/java/org/jboss/netty/handler/timeout/HashedWheelTimer.java index 367667d255..4fd45ba587 100644 --- a/src/main/java/org/jboss/netty/handler/timeout/HashedWheelTimer.java +++ b/src/main/java/org/jboss/netty/handler/timeout/HashedWheelTimer.java @@ -23,6 +23,8 @@ package org.jboss.netty.handler.timeout; import java.util.ArrayList; +import java.util.Collections; +import java.util.HashSet; import java.util.List; import java.util.Set; import java.util.concurrent.ThreadFactory; @@ -144,10 +146,11 @@ public class HashedWheelTimer implements Timer { workerThread.start(); } - public void stop() { + public Set stop() { if (!shutdown.compareAndSet(false, true)) { - return; + return Collections.emptySet(); } + while (workerThread.isAlive()) { workerThread.interrupt(); try { @@ -156,6 +159,14 @@ public class HashedWheelTimer implements Timer { // Ignore } } + + Set unprocessedTimeouts = new HashSet(); + for (Set bucket: wheel) { + unprocessedTimeouts.addAll(bucket); + bucket.clear(); + } + + return Collections.unmodifiableSet(unprocessedTimeouts); } public Timeout newTimeout(TimerTask task, long initialDelay, TimeUnit unit) { diff --git a/src/main/java/org/jboss/netty/handler/timeout/Timer.java b/src/main/java/org/jboss/netty/handler/timeout/Timer.java index 73f18107fc..3790bcba4b 100644 --- a/src/main/java/org/jboss/netty/handler/timeout/Timer.java +++ b/src/main/java/org/jboss/netty/handler/timeout/Timer.java @@ -22,6 +22,7 @@ */ package org.jboss.netty.handler.timeout; +import java.util.Set; import java.util.concurrent.TimeUnit; /** @@ -31,6 +32,5 @@ import java.util.concurrent.TimeUnit; */ public interface Timer { Timeout newTimeout(TimerTask task, long timeout, TimeUnit unit); - // XXX Should we make stop() return the list of unfinished Timeouts? - void stop(); + Set stop(); }