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:45 UTC

[5/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/71af8450
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/71af8450
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/71af8450

Branch: refs/heads/camel-2.15.x
Commit: 71af845046e60562e85f9e1fc50a338d2197a30c
Parents: e330b65
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:53 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/71af8450/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/71af8450/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/71af8450/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);
         }