Updated Branches: refs/heads/camel-2.10.x 78d10b6ec -> ea3823a58 refs/heads/camel-2.11.x 2344ec3f0 -> f092d4886
CAMEL-6442 fix the IllegalStateException issue in camel-netty-http route Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/f092d488 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/f092d488 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/f092d488 Branch: refs/heads/camel-2.11.x Commit: f092d4886e65f55e0d91d300a5c928ae1d740998 Parents: 2344ec3 Author: Willem Jiang <ningji...@apache.org> Authored: Sat Jun 8 22:33:01 2013 +0800 Committer: Claus Ibsen <davscl...@apache.org> Committed: Fri Jun 14 11:30:20 2013 +0200 ---------------------------------------------------------------------- .../camel/component/netty/NettyProducer.java | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/f092d488/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyProducer.java ---------------------------------------------------------------------- diff --git a/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyProducer.java b/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyProducer.java index 80a804b..d3012e3 100644 --- a/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyProducer.java +++ b/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyProducer.java @@ -18,8 +18,10 @@ package org.apache.camel.component.netty; import java.net.InetSocketAddress; import java.util.Map; +import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutorService; import java.util.concurrent.RejectedExecutionException; +import java.util.concurrent.TimeUnit; import org.apache.camel.AsyncCallback; import org.apache.camel.CamelContext; @@ -383,7 +385,22 @@ public class NettyProducer extends DefaultAsyncProducer { if (LOG.isTraceEnabled()) { LOG.trace("Waiting for operation to complete {} for {} millis", channelFuture, configuration.getConnectTimeout()); } - channelFuture.awaitUninterruptibly(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()); + } + if (!channelFuture.isDone() || !channelFuture.isSuccess()) { throw new CamelException("Cannot connect to " + configuration.getAddress(), channelFuture.getCause());