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 2013/06/14 11:31:19 UTC

[2/2] git commit: CAMEL-6442 fix the IllegalStateException issue in camel-netty-http route

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

Branch: refs/heads/camel-2.10.x
Commit: ea3823a58e4fef59dd0a66c5b5cbe40fd0754fe1
Parents: 78d10b6
Author: Willem Jiang <ni...@apache.org>
Authored: Sat Jun 8 22:33:01 2013 +0800
Committer: Claus Ibsen <da...@apache.org>
Committed: Fri Jun 14 11:30:49 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/ea3823a5/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 f790bf3..a5cb5ad 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;
@@ -381,7 +383,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());