Improved HashedWheelTimer.stop() to return a set of unprocessed timeouts
This commit is contained in:
parent
5249c47da7
commit
6894b0f277
@ -23,6 +23,8 @@
|
|||||||
package org.jboss.netty.handler.timeout;
|
package org.jboss.netty.handler.timeout;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ThreadFactory;
|
import java.util.concurrent.ThreadFactory;
|
||||||
@ -144,10 +146,11 @@ public class HashedWheelTimer implements Timer {
|
|||||||
workerThread.start();
|
workerThread.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stop() {
|
public Set<Timeout> stop() {
|
||||||
if (!shutdown.compareAndSet(false, true)) {
|
if (!shutdown.compareAndSet(false, true)) {
|
||||||
return;
|
return Collections.emptySet();
|
||||||
}
|
}
|
||||||
|
|
||||||
while (workerThread.isAlive()) {
|
while (workerThread.isAlive()) {
|
||||||
workerThread.interrupt();
|
workerThread.interrupt();
|
||||||
try {
|
try {
|
||||||
@ -156,6 +159,14 @@ public class HashedWheelTimer implements Timer {
|
|||||||
// Ignore
|
// Ignore
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Set<Timeout> unprocessedTimeouts = new HashSet<Timeout>();
|
||||||
|
for (Set<HashedWheelTimeout> bucket: wheel) {
|
||||||
|
unprocessedTimeouts.addAll(bucket);
|
||||||
|
bucket.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
return Collections.unmodifiableSet(unprocessedTimeouts);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Timeout newTimeout(TimerTask task, long initialDelay, TimeUnit unit) {
|
public Timeout newTimeout(TimerTask task, long initialDelay, TimeUnit unit) {
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.jboss.netty.handler.timeout;
|
package org.jboss.netty.handler.timeout;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -31,6 +32,5 @@ import java.util.concurrent.TimeUnit;
|
|||||||
*/
|
*/
|
||||||
public interface Timer {
|
public interface Timer {
|
||||||
Timeout newTimeout(TimerTask task, long timeout, TimeUnit unit);
|
Timeout newTimeout(TimerTask task, long timeout, TimeUnit unit);
|
||||||
// XXX Should we make stop() return the list of unfinished Timeouts?
|
Set<Timeout> stop();
|
||||||
void stop();
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user