Author: davsclaus Date: Sat Jun 16 06:58:56 2012 New Revision: 1350874 URL: http://svn.apache.org/viewvc?rev=1350874&view=rev Log: CAMEL-5370: Added direct-vm component to act as synchronous direct calls between multiple camel contexts in the same JVM (eg like direct + vm together). Can be used to support transactions spanning multiple camel contextes / bundles.
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/directvm/DirectVmComponent.java camel/trunk/camel-core/src/main/java/org/apache/camel/component/directvm/DirectVmProcessor.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/component/directvm/DirectVmComponent.java URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/directvm/DirectVmComponent.java?rev=1350874&r1=1350873&r2=1350874&view=diff ============================================================================== --- camel/trunk/camel-core/src/main/java/org/apache/camel/component/directvm/DirectVmComponent.java (original) +++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/directvm/DirectVmComponent.java Sat Jun 16 06:58:56 2012 @@ -33,7 +33,7 @@ public class DirectVmComponent extends D private static final AtomicInteger START_COUNTER = new AtomicInteger(); // must keep a map of consumers on the component to ensure endpoints can lookup old consumers - // later in case the DirectEndpoint was re-created due the old was evicted from the endpoints LRUCache + // later in case the DirectVmEndpoint was re-created due the old was evicted from the endpoints LRUCache // on DefaultCamelContext private static final ConcurrentMap<String, DirectVmConsumer> CONSUMERS = new ConcurrentHashMap<String, DirectVmConsumer>(); Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/directvm/DirectVmProcessor.java URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/directvm/DirectVmProcessor.java?rev=1350874&r1=1350873&r2=1350874&view=diff ============================================================================== --- camel/trunk/camel-core/src/main/java/org/apache/camel/component/directvm/DirectVmProcessor.java (original) +++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/directvm/DirectVmProcessor.java Sat Jun 16 06:58:56 2012 @@ -52,8 +52,8 @@ public final class DirectVmProcessor ext * @return the exchange to process by this consumer. */ protected Exchange prepareExchange(Exchange exchange) { - // send a new copied exchange with new camel context - Exchange newExchange = ExchangeHelper.copyExchangeAndSetCamelContext(exchange, endpoint.getCamelContext()); + // send a new copied exchange with new camel context (do not handover completions) + Exchange newExchange = ExchangeHelper.copyExchangeAndSetCamelContext(exchange, endpoint.getCamelContext(), false); // set the from endpoint newExchange.setFromEndpoint(endpoint); return newExchange; 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=1350874&r1=1350873&r2=1350874&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 Jun 16 06:58:56 2012 @@ -784,19 +784,32 @@ public final class ExchangeHelper { * @return a copy with the given camel context */ public static Exchange copyExchangeAndSetCamelContext(Exchange exchange, CamelContext context) { + return copyExchangeAndSetCamelContext(exchange, context, true); + } + + /** + * Copies the exchange but the copy will be tied to the given context + * + * @param exchange the source exchange + * @param context the camel context + * @param handover whether to handover on completions from the source to the copy + * @return a copy with the given camel context + */ + public static Exchange copyExchangeAndSetCamelContext(Exchange exchange, CamelContext context, boolean handover) { DefaultExchange answer = new DefaultExchange(context, exchange.getPattern()); if (exchange.hasProperties()) { answer.setProperties(safeCopy(exchange.getProperties())); } - // Need to hand over the completion for async invocation - exchange.handoverCompletions(answer); + if (handover) { + // Need to hand over the completion for async invocation + exchange.handoverCompletions(answer); + } answer.setIn(exchange.getIn().copy()); if (exchange.hasOut()) { answer.setOut(exchange.getOut().copy()); } answer.setException(exchange.getException()); return answer; - } private static Map<String, Object> safeCopy(Map<String, Object> properties) {