Repository: cxf Updated Branches: refs/heads/3.1.x-fixes ec00a0800 -> ad3670fc3
setter for applicationExecutor This closes #284 Project: http://git-wip-us.apache.org/repos/asf/cxf/repo Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/bdb04ca1 Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/bdb04ca1 Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/bdb04ca1 Branch: refs/heads/3.1.x-fixes Commit: bdb04ca14e1a73b0f97369c2764033139c578b4e Parents: ec00a08 Author: Maxim Samoylych <[email protected]> Authored: Thu Jun 22 13:50:14 2017 +0200 Committer: Daniel Kulp <[email protected]> Committed: Mon Jun 26 13:18:43 2017 -0400 ---------------------------------------------------------------------- .../netty/server/NettyHttpServerEngine.java | 83 ++++++++++++++++---- .../server/NettyHttpServletPipelineFactory.java | 19 ++++- 2 files changed, 81 insertions(+), 21 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cxf/blob/bdb04ca1/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 8434060..820c0ac 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.ChannelOption; 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 { @@ -90,9 +91,10 @@ public class NettyHttpServerEngine implements ServerEngine { private boolean sessionSupport; // TODO need to setup configuration about them - private EventLoopGroup bossGroup = new NioEventLoopGroup(); - private EventLoopGroup workerGroup = new NioEventLoopGroup(); - + private EventLoopGroup bossGroup; + private EventLoopGroup workerGroup; + private EventExecutorGroup applicationExecutor; + public NettyHttpServerEngine() { } @@ -104,14 +106,6 @@ public class NettyHttpServerEngine implements ServerEngine { this.port = port; } - public String getProtocol() { - return protocol; - } - - public void setProtocol(String protocol) { - this.protocol = protocol; - } - @PostConstruct public void finalizeConfig() { // need to check if we need to any other thing other than Setting the TLSServerParameter @@ -145,7 +139,16 @@ public class NettyHttpServerEngine implements ServerEngine { } protected Channel startServer() { - + if (bossGroup == null) { + bossGroup = new NioEventLoopGroup(); + } + if (workerGroup == null) { + workerGroup = new NioEventLoopGroup(); + } + if (applicationExecutor == null) { + applicationExecutor = new DefaultEventExecutorGroup(threadingParameters.getThreadPoolSize()); + } + final ServerBootstrap bootstrap = new ServerBootstrap(); bootstrap.group(bossGroup, workerGroup) .channel(NioServerSocketChannel.class) @@ -154,10 +157,9 @@ public class NettyHttpServerEngine implements ServerEngine { // Set up the event pipeline factory. servletPipeline = new NettyHttpServletPipelineFactory( - tlsServerParameters, sessionSupport, - threadingParameters.getThreadPoolSize(), - maxChunkContentSize, - handlerMap, this); + tlsServerParameters, sessionSupport, + maxChunkContentSize, handlerMap, + this, applicationExecutor); // Start the servletPipeline's timer servletPipeline.start(); bootstrap.childHandler(servletPipeline); @@ -242,6 +244,9 @@ public class NettyHttpServerEngine implements ServerEngine { // 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) { @@ -300,4 +305,48 @@ public class NettyHttpServerEngine implements ServerEngine { public String getHost() { return host; } + + public String getProtocol() { + return protocol; + } + + public void setProtocol(String protocol) { + this.protocol = protocol; + } + + public void setBossGroup(EventLoopGroup bossGroup) { + if (this.bossGroup == null) { + this.bossGroup = bossGroup; + } else { + throw new IllegalStateException("bossGroup is already defined"); + } + } + + public EventLoopGroup getBossGroup() { + return bossGroup; + } + + public void setWorkerGroup(EventLoopGroup workerGroup) { + if (this.workerGroup == null) { + this.workerGroup = workerGroup; + } else { + throw new IllegalStateException("workerGroup is already defined"); + } + } + + 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"); + } + } } http://git-wip-us.apache.org/repos/asf/cxf/blob/bdb04ca1/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 4357925..d7f158d 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<Channel> private final NettyHttpServerEngine nettyHttpServerEngine; - public NettyHttpServletPipelineFactory(TLSServerParameters tlsServerParameters, + /** + * @deprecated use {@link #NettyHttpServletPipelineFactory(TLSServerParameters, boolean, int, Map, + * NettyHttpServerEngine, EventExecutorGroup)} + */ + @Deprecated + public NettyHttpServletPipelineFactory(TLSServerParameters tlsServerParameters, boolean supportSession, int threadPoolSize, int maxChunkContentSize, Map<String, NettyHttpContextHandler> handlerMap, NettyHttpServerEngine engine) { + this(tlsServerParameters, supportSession, maxChunkContentSize, handlerMap, engine, + new DefaultEventExecutorGroup(threadPoolSize)); + } + + public NettyHttpServletPipelineFactory(TLSServerParameters tlsServerParameters, + boolean supportSession, int maxChunkContentSize, + Map<String, NettyHttpContextHandler> 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<String, NettyHttpContextHandler> getHttpContextHandlerMap() { return handlerMap; }
