CXF-5699 IdleStateHandler should not be shared across the channels
Project: http://git-wip-us.apache.org/repos/asf/cxf/repo Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/e2b52647 Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/e2b52647 Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/e2b52647 Branch: refs/heads/master Commit: e2b526476defbb109e71cd12a72dd78b8c0d4c66 Parents: 19a66ba Author: Willem Jiang <willem.ji...@gmail.com> Authored: Thu Apr 17 22:36:52 2014 +0800 Committer: Willem Jiang <willem.ji...@gmail.com> Committed: Thu Apr 17 22:50:46 2014 +0800 ---------------------------------------------------------------------- .../http/netty/server/NettyHttpServerEngine.java | 8 ++------ .../netty/server/NettyHttpServletPipelineFactory.java | 13 +++++++------ 2 files changed, 9 insertions(+), 12 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cxf/blob/e2b52647/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/NettyHttpServerEngine.java ---------------------------------------------------------------------- diff --git a/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/NettyHttpServerEngine.java b/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/NettyHttpServerEngine.java index ee77148..8434060 100644 --- a/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/NettyHttpServerEngine.java +++ b/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/NettyHttpServerEngine.java @@ -40,7 +40,6 @@ import io.netty.channel.ChannelOption; import io.netty.channel.EventLoopGroup; import io.netty.channel.nio.NioEventLoopGroup; import io.netty.channel.socket.nio.NioServerSocketChannel; -import io.netty.handler.timeout.IdleStateHandler; public class NettyHttpServerEngine implements ServerEngine { @@ -151,17 +150,14 @@ public class NettyHttpServerEngine implements ServerEngine { bootstrap.group(bossGroup, workerGroup) .channel(NioServerSocketChannel.class) .option(ChannelOption.SO_REUSEADDR, true); - - // Set up the idle handler - IdleStateHandler idleStateHandler = - new IdleStateHandler(getReadIdleTime(), getWriteIdleTime(), 0); + // Set up the event pipeline factory. servletPipeline = new NettyHttpServletPipelineFactory( tlsServerParameters, sessionSupport, threadingParameters.getThreadPoolSize(), maxChunkContentSize, - handlerMap, idleStateHandler); + handlerMap, this); // Start the servletPipeline's timer servletPipeline.start(); bootstrap.childHandler(servletPipeline); http://git-wip-us.apache.org/repos/asf/cxf/blob/e2b52647/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/NettyHttpServletPipelineFactory.java ---------------------------------------------------------------------- diff --git a/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/NettyHttpServletPipelineFactory.java b/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/NettyHttpServletPipelineFactory.java index 7d9be18..600b47c 100644 --- a/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/NettyHttpServletPipelineFactory.java +++ b/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/NettyHttpServletPipelineFactory.java @@ -35,7 +35,6 @@ import org.apache.cxf.transport.http.netty.server.session.HttpSessionStore; import org.apache.cxf.transport.https.SSLUtils; import io.netty.channel.Channel; -import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelPipeline; import io.netty.channel.group.ChannelGroup; @@ -58,8 +57,6 @@ public class NettyHttpServletPipelineFactory extends ChannelInitializer<Channel> private final ChannelGroup allChannels = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE);; private final HttpSessionWatchdog watchdog; - - private final ChannelHandler idleStateHandler; private final TLSServerParameters tlsServerParameters; @@ -71,16 +68,18 @@ public class NettyHttpServletPipelineFactory extends ChannelInitializer<Channel> private final EventExecutorGroup applicationExecutor; + private final NettyHttpServerEngine nettyHttpServerEngine; + public NettyHttpServletPipelineFactory(TLSServerParameters tlsServerParameters, boolean supportSession, int threadPoolSize, int maxChunkContentSize, Map<String, NettyHttpContextHandler> handlerMap, - IdleStateHandler idleStateHandler) { + NettyHttpServerEngine engine) { this.supportSession = supportSession; - this.idleStateHandler = idleStateHandler; this.watchdog = new HttpSessionWatchdog(); this.handlerMap = handlerMap; this.tlsServerParameters = tlsServerParameters; this.maxChunkContentSize = maxChunkContentSize; + this.nettyHttpServerEngine = engine; //TODO need to configure the thread size of EventExecutorGroup applicationExecutor = new DefaultEventExecutorGroup(16); } @@ -151,7 +150,9 @@ public class NettyHttpServletPipelineFactory extends ChannelInitializer<Channel> // Remove the following line if you don't want automatic content // compression. pipeline.addLast("deflater", new HttpContentCompressor()); - pipeline.addLast("idle", this.idleStateHandler); + // Set up the idle handler + pipeline.addLast("idle", new IdleStateHandler(nettyHttpServerEngine.getReadIdleTime(), + nettyHttpServerEngine.getWriteIdleTime(), 0)); return pipeline; }