Updated Branches: refs/heads/master 1bb480f57 -> cf1273af0
CAMEL-6327: More work on new camel-netty-http component. Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/2e278438 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/2e278438 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/2e278438 Branch: refs/heads/master Commit: 2e2784384d3dc2052f42803a33f4576a59d38afe Parents: 1bb480f Author: Claus Ibsen <davscl...@apache.org> Authored: Tue Jun 18 12:03:16 2013 +0200 Committer: Claus Ibsen <davscl...@apache.org> Committed: Tue Jun 18 12:03:16 2013 +0200 ---------------------------------------------------------------------- .../http/HttpNettyServerBootstrapFactory.java | 15 +++++++++------ .../component/netty/http/NettyHttpComponent.java | 3 ++- .../camel/component/netty/NettyConsumer.java | 5 +++-- .../netty/NettyServerBootstrapFactory.java | 7 +++++++ .../SingleTCPNettyServerBootstrapFactory.java | 18 ++++++++++++------ .../SingleUDPNettyServerBootstrapFactory.java | 18 ++++++++++++------ 6 files changed, 45 insertions(+), 21 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/2e278438/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/HttpNettyServerBootstrapFactory.java ---------------------------------------------------------------------- diff --git a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/HttpNettyServerBootstrapFactory.java b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/HttpNettyServerBootstrapFactory.java index f0c724c..3bcc7ab 100644 --- a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/HttpNettyServerBootstrapFactory.java +++ b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/HttpNettyServerBootstrapFactory.java @@ -19,19 +19,22 @@ package org.apache.camel.component.netty.http; import org.apache.camel.CamelContext; import org.apache.camel.component.netty.NettyConfiguration; import org.apache.camel.component.netty.NettyConsumer; -import org.apache.camel.component.netty.ServerPipelineFactory; import org.apache.camel.component.netty.SingleTCPNettyServerBootstrapFactory; +import org.jboss.netty.channel.ChannelPipelineFactory; public class HttpNettyServerBootstrapFactory extends SingleTCPNettyServerBootstrapFactory { private final NettyHttpComponent component; - private final int port; + private int port; - public HttpNettyServerBootstrapFactory(CamelContext camelContext, NettyConfiguration nettyConfiguration, ServerPipelineFactory pipelineFactory, - NettyHttpComponent component) { - super(camelContext, nettyConfiguration, pipelineFactory); + public HttpNettyServerBootstrapFactory(NettyHttpComponent component) { this.component = component; - this.port = nettyConfiguration.getPort(); + } + + @Override + public void init(CamelContext camelContext, NettyConfiguration configuration, ChannelPipelineFactory pipelineFactory) { + super.init(camelContext, configuration, pipelineFactory); + this.port = configuration.getPort(); } public void addConsumer(NettyConsumer consumer) { http://git-wip-us.apache.org/repos/asf/camel/blob/2e278438/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpComponent.java ---------------------------------------------------------------------- diff --git a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpComponent.java b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpComponent.java index 23762a8..4c775ae 100644 --- a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpComponent.java +++ b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpComponent.java @@ -131,7 +131,8 @@ public class NettyHttpComponent extends NettyComponent implements HeaderFilterSt String key = consumer.getConfiguration().getAddress(); HttpNettyServerBootstrapFactory answer = bootstrapFactories.get(key); if (answer == null) { - answer = new HttpNettyServerBootstrapFactory(getCamelContext(), consumer.getConfiguration(), new HttpServerPipelineFactory(consumer), this); + answer = new HttpNettyServerBootstrapFactory(this); + answer.init(getCamelContext(), consumer.getConfiguration(), new HttpServerPipelineFactory(consumer)); bootstrapFactories.put(key, answer); } return answer; http://git-wip-us.apache.org/repos/asf/camel/blob/2e278438/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyConsumer.java ---------------------------------------------------------------------- diff --git a/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyConsumer.java b/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyConsumer.java index b2ca07c..6234cba 100644 --- a/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyConsumer.java +++ b/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyConsumer.java @@ -58,10 +58,11 @@ public class NettyConsumer extends DefaultConsumer { if (nettyServerBootstrapFactory == null) { if (isTcp()) { - nettyServerBootstrapFactory = new SingleTCPNettyServerBootstrapFactory(context, getConfiguration(), pipelineFactory); + nettyServerBootstrapFactory = new SingleTCPNettyServerBootstrapFactory(); } else { - nettyServerBootstrapFactory = new SingleUDPNettyServerBootstrapFactory(context, getConfiguration(), pipelineFactory); + nettyServerBootstrapFactory = new SingleUDPNettyServerBootstrapFactory(); } + nettyServerBootstrapFactory.init(context, configuration, pipelineFactory); } ServiceHelper.startServices(nettyServerBootstrapFactory); http://git-wip-us.apache.org/repos/asf/camel/blob/2e278438/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyServerBootstrapFactory.java ---------------------------------------------------------------------- diff --git a/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyServerBootstrapFactory.java b/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyServerBootstrapFactory.java index 675f70e..6dbb817 100644 --- a/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyServerBootstrapFactory.java +++ b/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyServerBootstrapFactory.java @@ -16,8 +16,10 @@ */ package org.apache.camel.component.netty; +import org.apache.camel.CamelContext; import org.apache.camel.Service; import org.jboss.netty.channel.Channel; +import org.jboss.netty.channel.ChannelPipelineFactory; /** * Factory for setting up Netty {@link org.jboss.netty.bootstrap.ServerBootstrap} and all @@ -29,6 +31,11 @@ import org.jboss.netty.channel.Channel; public interface NettyServerBootstrapFactory extends Service { /** + * Initializes this {@link NettyServerBootstrapFactory}. + */ + void init(CamelContext camelContext, NettyConfiguration configuration, ChannelPipelineFactory pipelineFactory); + + /** * When a new {@link Channel} is opened. */ void addChannel(Channel channel); http://git-wip-us.apache.org/repos/asf/camel/blob/2e278438/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 57df5d0..22b2d49 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 @@ -22,9 +22,11 @@ import java.util.concurrent.ExecutorService; import org.apache.camel.CamelContext; import org.apache.camel.support.ServiceSupport; +import org.apache.camel.util.ObjectHelper; import org.jboss.netty.bootstrap.ServerBootstrap; import org.jboss.netty.channel.Channel; import org.jboss.netty.channel.ChannelFactory; +import org.jboss.netty.channel.ChannelPipelineFactory; import org.jboss.netty.channel.group.ChannelGroup; import org.jboss.netty.channel.group.ChannelGroupFuture; import org.jboss.netty.channel.group.DefaultChannelGroup; @@ -38,21 +40,24 @@ import org.slf4j.LoggerFactory; public class SingleTCPNettyServerBootstrapFactory extends ServiceSupport implements NettyServerBootstrapFactory { protected static final Logger LOG = LoggerFactory.getLogger(SingleTCPNettyServerBootstrapFactory.class); - private final CamelContext camelContext; - private final NettyConfiguration configuration; private final ChannelGroup allChannels; - private final ServerPipelineFactory pipelineFactory; + private CamelContext camelContext; + private NettyConfiguration configuration; + private ChannelPipelineFactory pipelineFactory; private ChannelFactory channelFactory; private ServerBootstrap serverBootstrap; private Channel channel; private ExecutorService bossExecutor; private ExecutorService workerExecutor; - public SingleTCPNettyServerBootstrapFactory(CamelContext camelContext, NettyConfiguration nettyConfiguration, ServerPipelineFactory pipelineFactory) { + public SingleTCPNettyServerBootstrapFactory() { + this.allChannels = new DefaultChannelGroup(SingleTCPNettyServerBootstrapFactory.class.getName()); + } + + public void init(CamelContext camelContext, NettyConfiguration configuration, ChannelPipelineFactory pipelineFactory) { this.camelContext = camelContext; - this.configuration = nettyConfiguration; + this.configuration = configuration; this.pipelineFactory = pipelineFactory; - this.allChannels = new DefaultChannelGroup(SingleTCPNettyServerBootstrapFactory.class.getName()); } public void addChannel(Channel channel) { @@ -73,6 +78,7 @@ public class SingleTCPNettyServerBootstrapFactory extends ServiceSupport impleme @Override protected void doStart() throws Exception { + ObjectHelper.notNull(camelContext, "CamelContext"); startServerBoostrap(); } http://git-wip-us.apache.org/repos/asf/camel/blob/2e278438/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 8c43990..ea6e5a0 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 @@ -22,8 +22,10 @@ import java.util.concurrent.ExecutorService; import org.apache.camel.CamelContext; import org.apache.camel.support.ServiceSupport; +import org.apache.camel.util.ObjectHelper; import org.jboss.netty.bootstrap.ConnectionlessBootstrap; import org.jboss.netty.channel.Channel; +import org.jboss.netty.channel.ChannelPipelineFactory; import org.jboss.netty.channel.FixedReceiveBufferSizePredictorFactory; import org.jboss.netty.channel.group.ChannelGroup; import org.jboss.netty.channel.group.ChannelGroupFuture; @@ -39,21 +41,24 @@ import org.slf4j.LoggerFactory; public class SingleUDPNettyServerBootstrapFactory extends ServiceSupport implements NettyServerBootstrapFactory { protected static final Logger LOG = LoggerFactory.getLogger(SingleUDPNettyServerBootstrapFactory.class); - private final CamelContext camelContext; - private final NettyConfiguration configuration; private final ChannelGroup allChannels; - private final ServerPipelineFactory pipelineFactory; + private CamelContext camelContext; + private NettyConfiguration configuration; + private ChannelPipelineFactory pipelineFactory; private DatagramChannelFactory datagramChannelFactory; private ConnectionlessBootstrap connectionlessServerBootstrap; private Channel channel; private ExecutorService bossExecutor; private ExecutorService workerExecutor; - public SingleUDPNettyServerBootstrapFactory(CamelContext camelContext, NettyConfiguration nettyConfiguration, ServerPipelineFactory pipelineFactory) { + public SingleUDPNettyServerBootstrapFactory() { + this.allChannels = new DefaultChannelGroup(SingleUDPNettyServerBootstrapFactory.class.getName()); + } + + public void init(CamelContext camelContext, NettyConfiguration configuration, ChannelPipelineFactory pipelineFactory) { this.camelContext = camelContext; - this.configuration = nettyConfiguration; + this.configuration = configuration; this.pipelineFactory = pipelineFactory; - this.allChannels = new DefaultChannelGroup(SingleUDPNettyServerBootstrapFactory.class.getName()); } public void addChannel(Channel channel) { @@ -74,6 +79,7 @@ public class SingleUDPNettyServerBootstrapFactory extends ServiceSupport impleme @Override protected void doStart() throws Exception { + ObjectHelper.notNull(camelContext, "CamelContext"); startServerBootstrap(); }