Repository: camel Updated Branches: refs/heads/master 45bd634f7 -> 58b0f8d63
CAMEL-7054 - CamelNetty - No way to get ChannelGroup Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/58b0f8d6 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/58b0f8d6 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/58b0f8d6 Branch: refs/heads/master Commit: 58b0f8d635fe990273d1778e3d3ecf2e08313f7e Parents: 45bd634 Author: lburgazzoli <lburgazz...@gmail.com> Authored: Sun Jan 24 16:41:45 2016 +0100 Committer: lburgazzoli <lburgazz...@gmail.com> Committed: Sun Jan 24 17:29:03 2016 +0100 ---------------------------------------------------------------------- .../netty/NettyServerBootstrapConfiguration.java | 14 ++++++++++++++ .../netty/SingleTCPNettyServerBootstrapFactory.java | 11 +++++++++-- .../netty/SingleUDPNettyServerBootstrapFactory.java | 11 +++++++++-- .../netty4/NettyServerBootstrapConfiguration.java | 14 ++++++++++++++ .../netty4/SingleTCPNettyServerBootstrapFactory.java | 12 +++++++++--- .../camel/component/netty4/NettyProducerHangTest.java | 2 +- 6 files changed, 56 insertions(+), 8 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/58b0f8d6/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyServerBootstrapConfiguration.java ---------------------------------------------------------------------- diff --git a/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyServerBootstrapConfiguration.java b/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyServerBootstrapConfiguration.java index 29aa309..7b4834c 100644 --- a/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyServerBootstrapConfiguration.java +++ b/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyServerBootstrapConfiguration.java @@ -24,6 +24,7 @@ import org.apache.camel.spi.UriParam; import org.apache.camel.spi.UriParams; import org.apache.camel.spi.UriPath; import org.apache.camel.util.jsse.SSLContextParameters; +import org.jboss.netty.channel.group.ChannelGroup; import org.jboss.netty.channel.socket.nio.BossPool; import org.jboss.netty.channel.socket.nio.WorkerPool; import org.jboss.netty.handler.ssl.SslHandler; @@ -99,6 +100,8 @@ public class NettyServerBootstrapConfiguration implements Cloneable { @UriParam(label = "consumer,advanced") protected WorkerPool workerPool; @UriParam(label = "consumer,advanced") + protected ChannelGroup channelGroup; + @UriParam(label = "consumer,advanced") protected String networkInterface; public String getAddress() { @@ -468,6 +471,17 @@ public class NettyServerBootstrapConfiguration implements Cloneable { this.workerPool = workerPool; } + public ChannelGroup getChannelGroup() { + return channelGroup; + } + + /** + * To use a explicit ChannelGroup. + */ + public void setChannelGroup(ChannelGroup channelGroup) { + this.channelGroup = channelGroup; + } + public String getNetworkInterface() { return networkInterface; } http://git-wip-us.apache.org/repos/asf/camel/blob/58b0f8d6/components/camel-netty/src/main/java/org/apache/camel/component/netty/SingleTCPNettyServerBootstrapFactory.java ---------------------------------------------------------------------- diff --git a/components/camel-netty/src/main/java/org/apache/camel/component/netty/SingleTCPNettyServerBootstrapFactory.java b/components/camel-netty/src/main/java/org/apache/camel/component/netty/SingleTCPNettyServerBootstrapFactory.java index 97f3395..3a74b0f 100644 --- a/components/camel-netty/src/main/java/org/apache/camel/component/netty/SingleTCPNettyServerBootstrapFactory.java +++ b/components/camel-netty/src/main/java/org/apache/camel/component/netty/SingleTCPNettyServerBootstrapFactory.java @@ -42,7 +42,7 @@ import org.slf4j.LoggerFactory; public class SingleTCPNettyServerBootstrapFactory extends ServiceSupport implements NettyServerBootstrapFactory { protected static final Logger LOG = LoggerFactory.getLogger(SingleTCPNettyServerBootstrapFactory.class); - private final ChannelGroup allChannels; + private ChannelGroup allChannels; private CamelContext camelContext; private ThreadFactory threadFactory; private NettyServerBootstrapConfiguration configuration; @@ -54,19 +54,26 @@ public class SingleTCPNettyServerBootstrapFactory extends ServiceSupport impleme private WorkerPool workerPool; public SingleTCPNettyServerBootstrapFactory() { - this.allChannels = new DefaultChannelGroup(SingleTCPNettyServerBootstrapFactory.class.getName()); } public void init(CamelContext camelContext, NettyServerBootstrapConfiguration configuration, ChannelPipelineFactory pipelineFactory) { this.camelContext = camelContext; this.configuration = configuration; this.pipelineFactory = pipelineFactory; + + this.allChannels = configuration.getChannelGroup() != null + ? configuration.getChannelGroup() + : new DefaultChannelGroup(SingleTCPNettyServerBootstrapFactory.class.getName()); } public void init(ThreadFactory threadFactory, NettyServerBootstrapConfiguration configuration, ChannelPipelineFactory pipelineFactory) { this.threadFactory = threadFactory; this.configuration = configuration; this.pipelineFactory = pipelineFactory; + + this.allChannels = configuration.getChannelGroup() != null + ? configuration.getChannelGroup() + : new DefaultChannelGroup(SingleTCPNettyServerBootstrapFactory.class.getName()); } public void addChannel(Channel channel) { http://git-wip-us.apache.org/repos/asf/camel/blob/58b0f8d6/components/camel-netty/src/main/java/org/apache/camel/component/netty/SingleUDPNettyServerBootstrapFactory.java ---------------------------------------------------------------------- diff --git a/components/camel-netty/src/main/java/org/apache/camel/component/netty/SingleUDPNettyServerBootstrapFactory.java b/components/camel-netty/src/main/java/org/apache/camel/component/netty/SingleUDPNettyServerBootstrapFactory.java index 00b8440..ada56d1 100644 --- a/components/camel-netty/src/main/java/org/apache/camel/component/netty/SingleUDPNettyServerBootstrapFactory.java +++ b/components/camel-netty/src/main/java/org/apache/camel/component/netty/SingleUDPNettyServerBootstrapFactory.java @@ -49,7 +49,7 @@ public class SingleUDPNettyServerBootstrapFactory extends ServiceSupport impleme protected static final Logger LOG = LoggerFactory.getLogger(SingleUDPNettyServerBootstrapFactory.class); private static final String LOOPBACK_INTERFACE = "lo"; private static final String MULTICAST_SUBNET = "224.0.0.0/4"; - private final ChannelGroup allChannels; + private ChannelGroup allChannels; private CamelContext camelContext; private ThreadFactory threadFactory; private NettyServerBootstrapConfiguration configuration; @@ -62,19 +62,26 @@ public class SingleUDPNettyServerBootstrapFactory extends ServiceSupport impleme private WorkerPool workerPool; public SingleUDPNettyServerBootstrapFactory() { - this.allChannels = new DefaultChannelGroup(SingleUDPNettyServerBootstrapFactory.class.getName()); } public void init(CamelContext camelContext, NettyServerBootstrapConfiguration configuration, ChannelPipelineFactory pipelineFactory) { this.camelContext = camelContext; this.configuration = configuration; this.pipelineFactory = pipelineFactory; + + this.allChannels = configuration.getChannelGroup() != null + ? configuration.getChannelGroup() + : new DefaultChannelGroup(SingleUDPNettyServerBootstrapFactory.class.getName()); } public void init(ThreadFactory threadFactory, NettyServerBootstrapConfiguration configuration, ChannelPipelineFactory pipelineFactory) { this.threadFactory = threadFactory; this.configuration = configuration; this.pipelineFactory = pipelineFactory; + + this.allChannels = configuration.getChannelGroup() != null + ? configuration.getChannelGroup() + : new DefaultChannelGroup(SingleUDPNettyServerBootstrapFactory.class.getName()); } public void addChannel(Channel channel) { http://git-wip-us.apache.org/repos/asf/camel/blob/58b0f8d6/components/camel-netty4/src/main/java/org/apache/camel/component/netty4/NettyServerBootstrapConfiguration.java ---------------------------------------------------------------------- diff --git a/components/camel-netty4/src/main/java/org/apache/camel/component/netty4/NettyServerBootstrapConfiguration.java b/components/camel-netty4/src/main/java/org/apache/camel/component/netty4/NettyServerBootstrapConfiguration.java index 5221040..5db1452 100644 --- a/components/camel-netty4/src/main/java/org/apache/camel/component/netty4/NettyServerBootstrapConfiguration.java +++ b/components/camel-netty4/src/main/java/org/apache/camel/component/netty4/NettyServerBootstrapConfiguration.java @@ -20,6 +20,7 @@ import java.io.File; import java.util.Map; import io.netty.channel.EventLoopGroup; +import io.netty.channel.group.ChannelGroup; import io.netty.handler.ssl.SslHandler; import org.apache.camel.spi.Metadata; import org.apache.camel.spi.UriParam; @@ -97,6 +98,8 @@ public class NettyServerBootstrapConfiguration implements Cloneable { @UriParam(label = "consumer,advanced") protected EventLoopGroup workerGroup; @UriParam(label = "consumer,advanced") + protected ChannelGroup channelGroup; + @UriParam(label = "consumer,advanced") protected String networkInterface; @UriParam(label = "consumer", defaultValue = "true") private boolean reconnect = true; @@ -485,6 +488,17 @@ public class NettyServerBootstrapConfiguration implements Cloneable { this.workerGroup = workerGroup; } + public ChannelGroup getChannelGroup() { + return channelGroup; + } + + /** + * To use a explicit ChannelGroup. + */ + public void setChannelGroup(ChannelGroup channelGroup) { + this.channelGroup = channelGroup; + } + public String getNetworkInterface() { return networkInterface; } http://git-wip-us.apache.org/repos/asf/camel/blob/58b0f8d6/components/camel-netty4/src/main/java/org/apache/camel/component/netty4/SingleTCPNettyServerBootstrapFactory.java ---------------------------------------------------------------------- diff --git a/components/camel-netty4/src/main/java/org/apache/camel/component/netty4/SingleTCPNettyServerBootstrapFactory.java b/components/camel-netty4/src/main/java/org/apache/camel/component/netty4/SingleTCPNettyServerBootstrapFactory.java index d97150b..9e10ced 100644 --- a/components/camel-netty4/src/main/java/org/apache/camel/component/netty4/SingleTCPNettyServerBootstrapFactory.java +++ b/components/camel-netty4/src/main/java/org/apache/camel/component/netty4/SingleTCPNettyServerBootstrapFactory.java @@ -41,7 +41,7 @@ import org.slf4j.LoggerFactory; public class SingleTCPNettyServerBootstrapFactory extends ServiceSupport implements NettyServerBootstrapFactory { protected static final Logger LOG = LoggerFactory.getLogger(SingleTCPNettyServerBootstrapFactory.class); - private final ChannelGroup allChannels; + private ChannelGroup allChannels; private CamelContext camelContext; private ThreadFactory threadFactory; private NettyServerBootstrapConfiguration configuration; @@ -52,20 +52,26 @@ public class SingleTCPNettyServerBootstrapFactory extends ServiceSupport impleme private EventLoopGroup workerGroup; public SingleTCPNettyServerBootstrapFactory() { - // The executor just execute tasks in the callers thread - this.allChannels = new DefaultChannelGroup(SingleTCPNettyServerBootstrapFactory.class.getName(), ImmediateEventExecutor.INSTANCE); } public void init(CamelContext camelContext, NettyServerBootstrapConfiguration configuration, ChannelInitializer<Channel> pipelineFactory) { this.camelContext = camelContext; this.configuration = configuration; this.pipelineFactory = pipelineFactory; + + this.allChannels = configuration.getChannelGroup() != null + ? configuration.getChannelGroup() + : new DefaultChannelGroup(SingleTCPNettyServerBootstrapFactory.class.getName(), ImmediateEventExecutor.INSTANCE); } public void init(ThreadFactory threadFactory, NettyServerBootstrapConfiguration configuration, ChannelInitializer<Channel> pipelineFactory) { this.threadFactory = threadFactory; this.configuration = configuration; this.pipelineFactory = pipelineFactory; + + this.allChannels = configuration.getChannelGroup() != null + ? configuration.getChannelGroup() + : new DefaultChannelGroup(SingleTCPNettyServerBootstrapFactory.class.getName(), ImmediateEventExecutor.INSTANCE); } public void addChannel(Channel channel) { http://git-wip-us.apache.org/repos/asf/camel/blob/58b0f8d6/components/camel-netty4/src/test/java/org/apache/camel/component/netty4/NettyProducerHangTest.java ---------------------------------------------------------------------- diff --git a/components/camel-netty4/src/test/java/org/apache/camel/component/netty4/NettyProducerHangTest.java b/components/camel-netty4/src/test/java/org/apache/camel/component/netty4/NettyProducerHangTest.java index 2f61963..d3a7b24 100644 --- a/components/camel-netty4/src/test/java/org/apache/camel/component/netty4/NettyProducerHangTest.java +++ b/components/camel-netty4/src/test/java/org/apache/camel/component/netty4/NettyProducerHangTest.java @@ -90,4 +90,4 @@ public class NettyProducerHangTest extends CamelTestSupport { log.info("Close socket"); } -} +} \ No newline at end of file