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:42 UTC
[2/5] camel git commit: CAMEL-9298: camel-netty4 - Connection timeout
is already done by netty itself
CAMEL-9298: camel-netty4 - Connection timeout is already done by netty itself
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/35d8ee43
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/35d8ee43
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/35d8ee43
Branch: refs/heads/master
Commit: 35d8ee43ef844c2421b14d1fc167852f14fda45b
Parents: d90cd5d
Author: Claus Ibsen <da...@apache.org>
Authored: Fri Nov 6 15:35:50 2015 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Fri Nov 6 15:41:25 2015 +0100
----------------------------------------------------------------------
...ClientModeTCPNettyServerBootstrapFactory.java | 15 ++-------------
.../camel/component/netty4/NettyProducer.java | 19 ++-----------------
2 files changed, 4 insertions(+), 30 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/35d8ee43/components/camel-netty4/src/main/java/org/apache/camel/component/netty4/ClientModeTCPNettyServerBootstrapFactory.java
----------------------------------------------------------------------
diff --git a/components/camel-netty4/src/main/java/org/apache/camel/component/netty4/ClientModeTCPNettyServerBootstrapFactory.java b/components/camel-netty4/src/main/java/org/apache/camel/component/netty4/ClientModeTCPNettyServerBootstrapFactory.java
index 6305156..fecbf5d 100644
--- a/components/camel-netty4/src/main/java/org/apache/camel/component/netty4/ClientModeTCPNettyServerBootstrapFactory.java
+++ b/components/camel-netty4/src/main/java/org/apache/camel/component/netty4/ClientModeTCPNettyServerBootstrapFactory.java
@@ -170,20 +170,9 @@ public class ClientModeTCPNettyServerBootstrapFactory extends ServiceSupport imp
if (LOG.isTraceEnabled()) {
LOG.trace("Waiting for operation to complete {} for {} millis", channelFuture, configuration.getConnectTimeout());
}
- // here we need to wait it in other thread
- final CountDownLatch channelLatch = new CountDownLatch(1);
- channelFuture.addListener(new ChannelFutureListener() {
- @Override
- public void operationComplete(ChannelFuture cf) throws Exception {
- channelLatch.countDown();
- }
- });
- try {
- channelLatch.await(configuration.getConnectTimeout(), TimeUnit.MILLISECONDS);
- } catch (InterruptedException ex) {
- throw new CamelException("Interrupted while waiting for " + "connection to " + configuration.getAddress());
- }
+ // wait for the channel to be open (see io.netty.channel.ChannelFuture javadoc for example/recommendation)
+ channelFuture.awaitUninterruptibly();
if (!channelFuture.isDone() || !channelFuture.isSuccess()) {
//check if reconnect is enabled and schedule a reconnect, if from handler then don't schedule a reconnect
http://git-wip-us.apache.org/repos/asf/camel/blob/35d8ee43/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 6292ede..d0d8eb7 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
@@ -20,7 +20,6 @@ import java.net.ConnectException;
import java.net.InetSocketAddress;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.CountDownLatch;
import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.TimeUnit;
@@ -38,10 +37,8 @@ import io.netty.channel.socket.nio.NioDatagramChannel;
import io.netty.channel.socket.nio.NioSocketChannel;
import io.netty.handler.timeout.ReadTimeoutHandler;
import io.netty.util.concurrent.ImmediateEventExecutor;
-
import org.apache.camel.AsyncCallback;
import org.apache.camel.CamelContext;
-import org.apache.camel.CamelException;
import org.apache.camel.CamelExchangeException;
import org.apache.camel.Exchange;
import org.apache.camel.impl.DefaultAsyncProducer;
@@ -414,21 +411,9 @@ public class NettyProducer extends DefaultAsyncProducer {
if (LOG.isTraceEnabled()) {
LOG.trace("Waiting for operation to complete {} for {} millis", channelFuture, configuration.getConnectTimeout());
}
- // here we need to wait it in other thread
- final CountDownLatch channelLatch = new CountDownLatch(1);
- channelFuture.addListener(new ChannelFutureListener() {
- @Override
- public void operationComplete(ChannelFuture cf) throws Exception {
- channelLatch.countDown();
- }
- });
- try {
- channelLatch.await(configuration.getConnectTimeout(), TimeUnit.MILLISECONDS);
- } catch (InterruptedException ex) {
- throw new CamelException("Interrupted while waiting for " + "connection to "
- + configuration.getAddress());
- }
+ // wait for the channel to be open (see io.netty.channel.ChannelFuture javadoc for example/recommendation)
+ channelFuture.awaitUninterruptibly();
if (!channelFuture.isDone() || !channelFuture.isSuccess()) {
ConnectException cause = new ConnectException("Cannot connect to " + configuration.getAddress());