You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ha...@apache.org on 2009/08/01 19:15:20 UTC

svn commit: r799899 - in /camel/trunk/camel-core/src/main/java/org/apache/camel: ./ component/seda/ impl/ processor/ util/

Author: hadrian
Date: Sat Aug  1 17:15:20 2009
New Revision: 799899

URL: http://svn.apache.org/viewvc?rev=799899&view=rev
Log:
CAMEL-1822. Moved Exchange.copy(boolean) to ExchangeHelper

Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/Exchange.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/component/seda/SedaProducer.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultExchange.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/processor/OnCompletionProcessor.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/processor/ThreadsProcessor.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/processor/WireTapProcessor.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/util/EndpointHelper.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/util/ExchangeHelper.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/Exchange.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/Exchange.java?rev=799899&r1=799898&r2=799899&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/Exchange.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/Exchange.java Sat Aug  1 17:15:20 2009
@@ -268,16 +268,6 @@
     Exchange copy();
 
     /**
-     * Creates a new instance and copies from the current message exchange so that it can be
-     * forwarded to another destination as a new instance. Unlike regular copy this operation
-     * will not share the same {@link org.apache.camel.spi.UnitOfWork} so its should be used
-     * for async messaging, where the original and copied exchange are independent.
-     *
-     * @param handoverOnCompletion whether the on completion callbacks should be handed over to the new copy.
-     */
-    Exchange copy(boolean handoverOnCompletion);
-
-    /**
      * Returns the endpoint which originated this message exchange if a consumer on an endpoint created the message exchange
      * otherwise this property will be null
      */

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/seda/SedaProducer.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/seda/SedaProducer.java?rev=799899&r1=799898&r2=799899&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/seda/SedaProducer.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/seda/SedaProducer.java Sat Aug  1 17:15:20 2009
@@ -45,7 +45,7 @@
     public void process(final Exchange exchange) throws Exception {
         // use a new copy of the exchange to route async and handover the on completion to the new copy
         // so its the new copy that performs the on completion callback when its done
-        Exchange copy = exchange.copy(true);
+        Exchange copy = ExchangeHelper.createCorrelatedCopy(exchange, true);
         // set a new from endpoint to be the seda queue
         copy.setFromEndpoint(endpoint);
 

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultExchange.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultExchange.java?rev=799899&r1=799898&r2=799899&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultExchange.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultExchange.java Sat Aug  1 17:15:20 2009
@@ -93,19 +93,6 @@
         return exchange;
     }
 
-    public Exchange copy(boolean handoverOnCompletion) {
-        Exchange copy = copy();
-        // do not share the unit of work
-        copy.setUnitOfWork(null);
-        // hand over on completion to the copy if we got any
-        if (handoverOnCompletion && unitOfWork != null) {
-            unitOfWork.handoverSynchronization(copy);
-        }
-        // set a correlation id so we can track back the original exchange
-        copy.setProperty(Exchange.CORRELATION_ID, this.getExchangeId());
-        return copy;
-    }
-
     private static void safeCopy(Message message, Message that) {
         if (message != null) {
             message.copyFrom(that);

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/processor/OnCompletionProcessor.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/OnCompletionProcessor.java?rev=799899&r1=799898&r2=799899&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/processor/OnCompletionProcessor.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/processor/OnCompletionProcessor.java Sat Aug  1 17:15:20 2009
@@ -25,6 +25,7 @@
 import org.apache.camel.Processor;
 import org.apache.camel.impl.ServiceSupport;
 import org.apache.camel.impl.SynchronizationAdapter;
+import org.apache.camel.util.ExchangeHelper;
 import org.apache.camel.util.ServiceHelper;
 import org.apache.camel.util.concurrent.ExecutorServiceHelper;
 import org.apache.commons.logging.Log;
@@ -143,7 +144,7 @@
      */
     protected Exchange prepareExchange(Exchange exchange) {
         // must use a copy as we dont want it to cause side effects of the original exchange
-        final Exchange copy = exchange.copy(false);
+        final Exchange copy = ExchangeHelper.createCorrelatedCopy(exchange, false);
         // set MEP to InOnly as this wire tap is a fire and forget
         copy.setPattern(ExchangePattern.InOnly);
         // add a header flag to indicate its a on completion exchange

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/processor/ThreadsProcessor.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/ThreadsProcessor.java?rev=799899&r1=799898&r2=799899&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/processor/ThreadsProcessor.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/processor/ThreadsProcessor.java Sat Aug  1 17:15:20 2009
@@ -58,7 +58,7 @@
 
         // use a new copy of the exchange to route async and handover the on completion to the new copy
         // so its the new copy that performs the on completion callback when its done
-        final Exchange copy = exchange.copy(true);
+        final Exchange copy = ExchangeHelper.createCorrelatedCopy(exchange, true);
 
         // let it execute async and return the Future
         Callable<Exchange> task = createTask(output, copy);

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/processor/WireTapProcessor.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/WireTapProcessor.java?rev=799899&r1=799898&r2=799899&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/processor/WireTapProcessor.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/processor/WireTapProcessor.java Sat Aug  1 17:15:20 2009
@@ -27,6 +27,7 @@
 import org.apache.camel.Producer;
 import org.apache.camel.ProducerCallback;
 import org.apache.camel.impl.DefaultExchange;
+import org.apache.camel.util.ExchangeHelper;
 import org.apache.camel.util.ObjectHelper;
 import org.apache.camel.util.concurrent.ExecutorServiceHelper;
 
@@ -114,7 +115,7 @@
 
     private Exchange configureCopyExchange(Exchange exchange) {
         // must use a copy as we dont want it to cause side effects of the original exchange
-        Exchange copy = exchange.copy(false);
+        Exchange copy = ExchangeHelper.createCorrelatedCopy(exchange, false);
         // set MEP to InOnly as this wire tap is a fire and forget
         copy.setPattern(ExchangePattern.InOnly);
         return copy;

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/util/EndpointHelper.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/util/EndpointHelper.java?rev=799899&r1=799898&r2=799899&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/util/EndpointHelper.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/util/EndpointHelper.java Sat Aug  1 17:15:20 2009
@@ -196,5 +196,4 @@
     public static boolean isReferenceParameter(String parameter) {
         return parameter != null && parameter.startsWith("#");
     }
-
 }

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/util/ExchangeHelper.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ExchangeHelper.java?rev=799899&r1=799898&r2=799899&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/util/ExchangeHelper.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/util/ExchangeHelper.java Sat Aug  1 17:15:20 2009
@@ -36,6 +36,7 @@
 import org.apache.camel.NoSuchPropertyException;
 import org.apache.camel.NoTypeConversionAvailableException;
 import org.apache.camel.TypeConverter;
+import org.apache.camel.spi.UnitOfWork;
 
 /**
  * Some helper methods for working with {@link Exchange} objects
@@ -177,6 +178,29 @@
     }
 
     /**
+     * Creates a new instance and copies from the current message exchange so that it can be
+     * forwarded to another destination as a new instance. Unlike regular copy this operation
+     * will not share the same {@link org.apache.camel.spi.UnitOfWork} so its should be used
+     * for async messaging, where the original and copied exchange are independent.
+     *
+     * @param exchange original copy of the exchange
+     * @param handover whether the on completion callbacks should be handed over to the new copy.
+     */
+    public static Exchange createCorrelatedCopy(Exchange exchange, boolean handover) {
+        Exchange copy = exchange.copy();
+        // do not share the unit of work
+        copy.setUnitOfWork(null);
+        // hand over on completion to the copy if we got any
+        UnitOfWork uow = exchange.getUnitOfWork();
+        if (handover && uow != null) {
+            uow.handoverSynchronization(copy);
+        }
+        // set a correlation id so we can track back the original exchange
+        copy.setProperty(Exchange.CORRELATION_ID, exchange.getExchangeId());
+        return copy;
+    }
+
+    /**
      * Copies the results of a message exchange from the source exchange to the result exchange
      * which will copy the out and fault message contents and the exception
      *