From 05aadb5c7d21d795dfca9db7c4d1b0b6467a1df2 Mon Sep 17 00:00:00 2001 From: Maxim Samoylych Date: Wed, 21 Jun 2017 13:25:07 +0300 Subject: [PATCH] setter for applicationExecutor --- .../netty/server/NettyHttpServerEngine.java | 27 ++++++++++++++++--- .../NettyHttpServletPipelineFactory.java | 17 +++++++++--- 2 files changed, 37 insertions(+), 7 deletions(-) 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 878f5b4598e..6dff4e681c1 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,8 @@ import io.netty.channel.EventLoopGroup; import io.netty.channel.nio.NioEventLoopGroup; import io.netty.channel.socket.nio.NioServerSocketChannel; - +import io.netty.util.concurrent.DefaultEventExecutorGroup; +import io.netty.util.concurrent.EventExecutorGroup; public class NettyHttpServerEngine implements ServerEngine { @@ -92,6 +93,7 @@ public class NettyHttpServerEngine implements ServerEngine { // TODO need to setup configuration about them private EventLoopGroup bossGroup; private EventLoopGroup workerGroup; + private EventExecutorGroup applicationExecutor; public NettyHttpServerEngine() { @@ -141,6 +143,9 @@ protected Channel startServer() { if (workerGroup == null) { workerGroup = new NioEventLoopGroup(); } + if (applicationExecutor == null) { + applicationExecutor = new DefaultEventExecutorGroup(threadingParameters.getThreadPoolSize()); + } final ServerBootstrap bootstrap = new ServerBootstrap(); bootstrap.group(bossGroup, workerGroup) @@ -151,9 +156,8 @@ protected Channel startServer() { servletPipeline = new NettyHttpServletPipelineFactory( tlsServerParameters, sessionSupport, - threadingParameters.getThreadPoolSize(), - maxChunkContentSize, - handlerMap, this); + maxChunkContentSize, handlerMap, + this, applicationExecutor); // Start the servletPipeline's timer servletPipeline.start(); bootstrap.childHandler(servletPipeline); @@ -235,6 +239,9 @@ public void shutdown() { // just unbind the channel if (servletPipeline != null) { servletPipeline.shutdown(); + } else if (applicationExecutor != null) { + // shutdown executor if it set but not server started + applicationExecutor.shutdownGracefully(); } if (serverChannel != null) { @@ -329,4 +336,16 @@ public void setWorkerGroup(EventLoopGroup workerGroup) { public EventLoopGroup getWorkerGroup() { return workerGroup; } + + public EventExecutorGroup getApplicationExecutor() { + return applicationExecutor; + } + + public void setApplicationExecutor(EventExecutorGroup applicationExecutor) { + if (this.applicationExecutor == null) { + this.applicationExecutor = applicationExecutor; + } else { + throw new IllegalStateException("applicationExecutor is already defined"); + } + } } 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 eec502acd61..5c27ae59247 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 @@ -69,21 +69,32 @@ public class NettyHttpServletPipelineFactory extends ChannelInitializer private final NettyHttpServerEngine nettyHttpServerEngine; + /** + * @deprecated use {@link #NettyHttpServletPipelineFactory(TLSServerParameters, boolean, int, Map, + * NettyHttpServerEngine, EventExecutorGroup)} + */ + @Deprecated public NettyHttpServletPipelineFactory(TLSServerParameters tlsServerParameters, boolean supportSession, int threadPoolSize, int maxChunkContentSize, Map handlerMap, NettyHttpServerEngine engine) { + this(tlsServerParameters, supportSession, maxChunkContentSize, handlerMap, engine, + new DefaultEventExecutorGroup(threadPoolSize)); + } + + public NettyHttpServletPipelineFactory(TLSServerParameters tlsServerParameters, + boolean supportSession, int maxChunkContentSize, + Map handlerMap, + NettyHttpServerEngine engine, EventExecutorGroup applicationExecutor) { this.supportSession = supportSession; 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(threadPoolSize); + this.applicationExecutor = applicationExecutor; } - public Map getHttpContextHandlerMap() { return handlerMap; }