You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2015/11/06 15:39:43 UTC

[3/5] camel git commit: CAMEL-9276: camel-netty4 - When bind then use sync instead of await as that is how Netty recommend, and also it will propagate bind exceptions which the await may hide. Thanks to Darshan Sundaresh for patch.

CAMEL-9276: camel-netty4 - When bind then use sync instead of await as that is how Netty recommend, and also it will propagate bind exceptions which the await may hide. Thanks to Darshan Sundaresh for patch.


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/a73ce367
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/a73ce367
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/a73ce367

Branch: refs/heads/camel-2.16.x
Commit: a73ce36794794c44fb24582c62a7ff1241867503
Parents: 54e396a
Author: Claus Ibsen <da...@apache.org>
Authored: Fri Nov 6 15:29:06 2015 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Fri Nov 6 15:41:35 2015 +0100

----------------------------------------------------------------------
 .../apache/camel/component/netty4/NettyProducer.java  |  4 +---
 .../netty4/SingleTCPNettyServerBootstrapFactory.java  | 14 +++++---------
 .../netty4/SingleUDPNettyServerBootstrapFactory.java  |  6 ++----
 3 files changed, 8 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/a73ce367/components/camel-netty4/src/main/java/org/apache/camel/component/netty4/NettyProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-netty4/src/main/java/org/apache/camel/component/netty4/NettyProducer.java b/components/camel-netty4/src/main/java/org/apache/camel/component/netty4/NettyProducer.java
index 14dab4b..6292ede 100644
--- a/components/camel-netty4/src/main/java/org/apache/camel/component/netty4/NettyProducer.java
+++ b/components/camel-netty4/src/main/java/org/apache/camel/component/netty4/NettyProducer.java
@@ -396,8 +396,7 @@ public class NettyProducer extends DefaultAsyncProducer {
                 answer = connectionlessClientBootstrap.connect(new InetSocketAddress(configuration.getHost(), configuration.getPort()));
             } else {
                 // bind and store channel so we can close it when stopping
-                answer = connectionlessClientBootstrap.bind(new InetSocketAddress(0));
-                answer.awaitUninterruptibly();
+                answer = connectionlessClientBootstrap.bind(new InetSocketAddress(0)).sync();
                 Channel channel = answer.channel();
                 allChannels.add(channel);
             }
@@ -431,7 +430,6 @@ public class NettyProducer extends DefaultAsyncProducer {
                                      + configuration.getAddress());
         }
 
-
         if (!channelFuture.isDone() || !channelFuture.isSuccess()) {
             ConnectException cause = new ConnectException("Cannot connect to " + configuration.getAddress());
             if (channelFuture.cause() != null) {

http://git-wip-us.apache.org/repos/asf/camel/blob/a73ce367/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 3c53d4e..d97150b 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
@@ -106,8 +106,7 @@ public class SingleTCPNettyServerBootstrapFactory extends ServiceSupport impleme
             if (!future.isSuccess()) {
                 // if we cannot bind, the re-create channel
                 allChannels.remove(channel);
-                future = serverBootstrap.bind(new InetSocketAddress(configuration.getHost(), configuration.getPort()));
-                future.awaitUninterruptibly();
+                future = serverBootstrap.bind(new InetSocketAddress(configuration.getHost(), configuration.getPort())).sync();
                 channel = future.channel();
                 allChannels.add(channel);
             }
@@ -124,7 +123,7 @@ public class SingleTCPNettyServerBootstrapFactory extends ServiceSupport impleme
         }
     }
 
-    protected void startServerBootstrap() {
+    protected void startServerBootstrap() throws Exception {
         // prefer using explicit configured thread pools
         EventLoopGroup bg = configuration.getBossGroup();
         EventLoopGroup wg = configuration.getWorkerGroup();
@@ -170,9 +169,8 @@ public class SingleTCPNettyServerBootstrapFactory extends ServiceSupport impleme
         LOG.debug("Created ServerBootstrap {}", serverBootstrap);
 
         LOG.info("ServerBootstrap binding to {}:{}", configuration.getHost(), configuration.getPort());
-        ChannelFuture channelFutrue = serverBootstrap.bind(new InetSocketAddress(configuration.getHost(), configuration.getPort()));
-        channelFutrue.awaitUninterruptibly();
-        channel = channelFutrue.channel();
+        ChannelFuture channelFuture = serverBootstrap.bind(new InetSocketAddress(configuration.getHost(), configuration.getPort())).sync();
+        channel = channelFuture.channel();
         // to keep track of all channels in use
         allChannels.add(channel);
     }
@@ -182,9 +180,7 @@ public class SingleTCPNettyServerBootstrapFactory extends ServiceSupport impleme
         LOG.info("ServerBootstrap unbinding from {}:{}", configuration.getHost(), configuration.getPort());
         
         LOG.trace("Closing {} channels", allChannels.size());
-        if (allChannels != null) {
-            allChannels.close().awaitUninterruptibly();
-        }
+        allChannels.close().awaitUninterruptibly();
 
         // and then shutdown the thread pools
         if (bossGroup != null) {

http://git-wip-us.apache.org/repos/asf/camel/blob/a73ce367/components/camel-netty4/src/main/java/org/apache/camel/component/netty4/SingleUDPNettyServerBootstrapFactory.java
----------------------------------------------------------------------
diff --git a/components/camel-netty4/src/main/java/org/apache/camel/component/netty4/SingleUDPNettyServerBootstrapFactory.java b/components/camel-netty4/src/main/java/org/apache/camel/component/netty4/SingleUDPNettyServerBootstrapFactory.java
index 13d2166..e3b262e 100644
--- a/components/camel-netty4/src/main/java/org/apache/camel/component/netty4/SingleUDPNettyServerBootstrapFactory.java
+++ b/components/camel-netty4/src/main/java/org/apache/camel/component/netty4/SingleUDPNettyServerBootstrapFactory.java
@@ -161,8 +161,7 @@ public class SingleUDPNettyServerBootstrapFactory extends ServiceSupport impleme
         SubnetUtils multicastSubnet = new SubnetUtils(MULTICAST_SUBNET);
 
         if (multicastSubnet.getInfo().isInRange(configuration.getHost())) {
-            ChannelFuture channelFuture = bootstrap.bind(configuration.getPort());
-            channelFuture.awaitUninterruptibly();
+            ChannelFuture channelFuture = bootstrap.bind(configuration.getPort()).sync();
             channel = channelFuture.channel();
             DatagramChannel datagramChannel = (DatagramChannel) channel;
             String networkInterface = configuration.getNetworkInterface() == null ? LOOPBACK_INTERFACE : configuration.getNetworkInterface();
@@ -173,8 +172,7 @@ public class SingleUDPNettyServerBootstrapFactory extends ServiceSupport impleme
             allChannels.add(datagramChannel);
         } else {
             LOG.info("ConnectionlessBootstrap binding to {}:{}", configuration.getHost(), configuration.getPort());
-            ChannelFuture channelFuture = bootstrap.bind(hostAddress);
-            channelFuture.awaitUninterruptibly();
+            ChannelFuture channelFuture = bootstrap.bind(hostAddress).sync();
             channel = channelFuture.channel();
             allChannels.add(channel);
         }