CAMEL-6377: Optimized routing engine to reduce stack frames in use during 
routing. Work in progress.


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

Branch: refs/heads/master
Commit: 37bfa9e7c7dc95648875124433ef0df0493f85c4
Parents: c64f94a
Author: Claus Ibsen <davscl...@apache.org>
Authored: Wed May 29 10:42:25 2013 +0200
Committer: Claus Ibsen <davscl...@apache.org>
Committed: Wed May 29 10:42:25 2013 +0200

----------------------------------------------------------------------
 .../apache/camel/processor/UnitOfWorkProducer.java |   34 +++++++++++++--
 1 files changed, 30 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/37bfa9e7/camel-core/src/main/java/org/apache/camel/processor/UnitOfWorkProducer.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/main/java/org/apache/camel/processor/UnitOfWorkProducer.java 
b/camel-core/src/main/java/org/apache/camel/processor/UnitOfWorkProducer.java
index 9662983..03af6c3 100644
--- 
a/camel-core/src/main/java/org/apache/camel/processor/UnitOfWorkProducer.java
+++ 
b/camel-core/src/main/java/org/apache/camel/processor/UnitOfWorkProducer.java
@@ -16,12 +16,17 @@
  */
 package org.apache.camel.processor;
 
+import java.util.concurrent.CountDownLatch;
+
+import org.apache.camel.AsyncCallback;
+import org.apache.camel.AsyncProcessor;
 import org.apache.camel.Endpoint;
 import org.apache.camel.Exchange;
 import org.apache.camel.ExchangePattern;
-import org.apache.camel.Processor;
 import org.apache.camel.Producer;
 import org.apache.camel.util.ServiceHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * Ensures a {@link Producer} is executed within an {@link 
org.apache.camel.spi.UnitOfWork}.
@@ -30,8 +35,9 @@ import org.apache.camel.util.ServiceHelper;
  */
 public final class UnitOfWorkProducer implements Producer {
 
+    private static final transient Logger LOG = 
LoggerFactory.getLogger(UnitOfWorkProducer.class);
     private final Producer producer;
-    private final Processor processor;
+    private final AsyncProcessor processor;
 
     /**
      * The producer which should be executed within an {@link 
org.apache.camel.spi.UnitOfWork}.
@@ -62,8 +68,28 @@ public final class UnitOfWorkProducer implements Producer {
         return producer.createExchange(exchange);
     }
 
-    public void process(Exchange exchange) throws Exception {
-        processor.process(exchange);
+    public void process(final Exchange exchange) throws Exception {
+        final CountDownLatch latch = new CountDownLatch(1);
+        boolean sync = processor.process(exchange, new AsyncCallback() {
+            public void done(boolean doneSync) {
+                if (!doneSync) {
+                    LOG.trace("Asynchronous callback received for exchangeId: 
{}", exchange.getExchangeId());
+                    latch.countDown();
+                }
+            }
+
+            @Override
+            public String toString() {
+                return "Done " + processor;
+            }
+        });
+        if (!sync) {
+            LOG.trace("Waiting for asynchronous callback before continuing for 
exchangeId: {} -> {}",
+                    exchange.getExchangeId(), exchange);
+            latch.await();
+            LOG.trace("Asynchronous callback received, will continue routing 
exchangeId: {} -> {}",
+                    exchange.getExchangeId(), exchange);
+        }
     }
 
     public void start() throws Exception {

Reply via email to