From 593c54c78cdbcc135a09f396239e583f91cd139b Mon Sep 17 00:00:00 2001 From: Maxim Samoylych Date: Thu, 25 May 2017 14:47:06 +0300 Subject: [PATCH] setter for bossGroup and workerGroup --- .../netty/server/NettyHttpServerEngine.java | 67 +++++++++++++------ 1 file changed, 48 insertions(+), 19 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 5eabf3de749..878f5b4598e 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 @@ -90,8 +90,8 @@ 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; public NettyHttpServerEngine() { @@ -104,20 +104,11 @@ public NettyHttpServerEngine( 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 } - /** * This method is used to programmatically set the TLSServerParameters. * This method may only be called by the factory. @@ -130,7 +121,6 @@ public void setTlsServerParameters(TLSServerParameters params) { * This method returns the programmatically set TLSServerParameters, not * the TLSServerParametersType, which is the JAXB generated type used * in SpringConfiguration. - * @return */ public TLSServerParameters getTlsServerParameters() { return tlsServerParameters; @@ -145,6 +135,12 @@ public ThreadingParameters getThreadingParameters() { } protected Channel startServer() { + if (bossGroup == null) { + bossGroup = new NioEventLoopGroup(); + } + if (workerGroup == null) { + workerGroup = new NioEventLoopGroup(); + } final ServerBootstrap bootstrap = new ServerBootstrap(); bootstrap.group(bossGroup, workerGroup) @@ -161,7 +157,7 @@ protected Channel startServer() { // Start the servletPipeline's timer servletPipeline.start(); bootstrap.childHandler(servletPipeline); - InetSocketAddress address = null; + InetSocketAddress address; if (host == null) { address = new InetSocketAddress(port); } else { @@ -184,10 +180,8 @@ protected void checkRegistedContext(URL url) { throw new Fault(new Message("ADD_HANDLER_CONTEXT_IS_USED_MSG", LOG, url, registedPath)); } } - } - @Override public void addServant(URL url, NettyHttpHandler handler) { checkRegistedContext(url); @@ -220,7 +214,6 @@ public void removeServant(URL url) { } } registedPaths.remove(url.getPath()); - } @Override @@ -248,9 +241,13 @@ public void shutdown() { serverChannel.close(); } - bossGroup.shutdownGracefully(); - workerGroup.shutdownGracefully(); - + // shutdown executors + if (bossGroup != null) { + bossGroup.shutdownGracefully(); + } + if (workerGroup != null) { + workerGroup.shutdownGracefully(); + } } public int getReadIdleTime() { @@ -300,4 +297,36 @@ public void setHost(String host) { 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; + } }