From 66b1960979106b148623dc5a9ff016c9965f9308 Mon Sep 17 00:00:00 2001 From: Trustin Lee Date: Wed, 7 Jan 2009 06:50:54 +0000 Subject: [PATCH] Fixed incorrect event order on channel closure when OrderedMemoryAwareThreadPoolExecutor is in a pipeline. --- .../OrderedMemoryAwareThreadPoolExecutor.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/jboss/netty/handler/execution/OrderedMemoryAwareThreadPoolExecutor.java b/src/main/java/org/jboss/netty/handler/execution/OrderedMemoryAwareThreadPoolExecutor.java index edc8bba94f..49ef8a8dba 100644 --- a/src/main/java/org/jboss/netty/handler/execution/OrderedMemoryAwareThreadPoolExecutor.java +++ b/src/main/java/org/jboss/netty/handler/execution/OrderedMemoryAwareThreadPoolExecutor.java @@ -31,6 +31,8 @@ import java.util.concurrent.TimeUnit; import org.jboss.netty.channel.Channel; import org.jboss.netty.channel.ChannelEvent; +import org.jboss.netty.channel.ChannelState; +import org.jboss.netty.channel.ChannelStateEvent; /** * A {@link MemoryAwareThreadPoolExecutor} which maintains the @@ -148,11 +150,12 @@ public class OrderedMemoryAwareThreadPoolExecutor extends doUnorderedExecute(task); } else { ChannelEventRunnable r = (ChannelEventRunnable) task; - getOrderedExecutor(r.getEvent().getChannel()).execute(task); + getOrderedExecutor(r.getEvent()).execute(task); } } - private Executor getOrderedExecutor(Channel channel) { + private Executor getOrderedExecutor(ChannelEvent e) { + Channel channel = e.getChannel(); Executor executor = childExecutors.get(channel); if (executor == null) { executor = new ChildExecutor(); @@ -163,8 +166,12 @@ public class OrderedMemoryAwareThreadPoolExecutor extends } // Remove the entry when the channel closes. - if (!channel.isOpen()) { - childExecutors.remove(channel); + if (e instanceof ChannelStateEvent) { + ChannelStateEvent se = (ChannelStateEvent) e; + if (se.getState() == ChannelState.OPEN && + !channel.isOpen()) { + childExecutors.remove(channel); + } } return executor; }