Author: davsclaus
Date: Fri Jun 15 12:02:14 2012
New Revision: 1350591

URL: http://svn.apache.org/viewvc?rev=1350591&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/package.html
    
camel/trunk/camel-core/src/test/java/org/apache/camel/component/directvm/DirectVmTwoCamelContextTest.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=1350591&r1=1350590&r2=1350591&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
 Fri Jun 15 12:02:14 2012
@@ -35,7 +35,7 @@ public class DirectVmComponent extends D
     // 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
     // on DefaultCamelContext
-    private static final ConcurrentMap<String, DirectVmConsumer> consumers = 
new ConcurrentHashMap<String, DirectVmConsumer>();
+    private static final ConcurrentMap<String, DirectVmConsumer> CONSUMERS = 
new ConcurrentHashMap<String, DirectVmConsumer>();
 
     @Override
     protected Endpoint createEndpoint(String uri, String remaining, 
Map<String, Object> parameters) throws Exception {
@@ -46,22 +46,22 @@ public class DirectVmComponent extends D
 
     public DirectVmConsumer getConsumer(DirectVmEndpoint endpoint) {
         String key = getConsumerKey(endpoint.getEndpointUri());
-        return consumers.get(key);
+        return CONSUMERS.get(key);
     }
 
     public void addConsumer(DirectVmEndpoint endpoint, DirectVmConsumer 
consumer) {
         String key = getConsumerKey(endpoint.getEndpointUri());
-        DirectVmConsumer existing = consumers.putIfAbsent(key, consumer);
+        DirectVmConsumer existing = CONSUMERS.putIfAbsent(key, consumer);
         if (existing != null) {
             String contextId = 
existing.getEndpoint().getCamelContext().getName();
             throw new IllegalStateException("A consumer " + existing + " 
already exists from CamelContext: " + contextId + ". Multiple consumers not 
supported");
         }
-        consumers.put(key, consumer);
+        CONSUMERS.put(key, consumer);
     }
 
     public void removeConsumer(DirectVmEndpoint endpoint, DirectVmConsumer 
consumer) {
         String key = getConsumerKey(endpoint.getEndpointUri());
-        consumers.remove(key);
+        CONSUMERS.remove(key);
     }
 
     private static String getConsumerKey(String uri) {
@@ -82,7 +82,7 @@ public class DirectVmComponent extends D
     protected void doStop() throws Exception {
         if (START_COUNTER.decrementAndGet() <= 0) {
             // clear queues when no more direct-vm components in use
-            consumers.clear();
+            CONSUMERS.clear();
         }
     }
 

Modified: 
camel/trunk/camel-core/src/main/java/org/apache/camel/component/directvm/package.html
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/directvm/package.html?rev=1350591&r1=1350590&r2=1350591&view=diff
==============================================================================
--- 
camel/trunk/camel-core/src/main/java/org/apache/camel/component/directvm/package.html
 (original)
+++ 
camel/trunk/camel-core/src/main/java/org/apache/camel/component/directvm/package.html
 Fri Jun 15 12:02:14 2012
@@ -19,8 +19,8 @@
 </head>
 <body>
 
-The <a href="http://camel.apache.org/directvm.html";>Direct VM Component</a> 
which synchronously invokes
-the consumer when a producer sends an exchange to the endpoint.  This also 
known as <i>strait through processing</i>.
+The <a href="http://camel.apache.org/direct-vm.html";>Direct VM Component</a> 
which synchronously invokes
+the consumer when a producer sends an exchange to the endpoint. This also 
known as <i>strait through processing</i>.
 <p/>
 This component supports messaging within the current JVM; so across 
CamelContext instances.
 Note that this communication can only take place between ClassLoaders which 
share the same camel-core.jar.

Modified: 
camel/trunk/camel-core/src/test/java/org/apache/camel/component/directvm/DirectVmTwoCamelContextTest.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/directvm/DirectVmTwoCamelContextTest.java?rev=1350591&r1=1350590&r2=1350591&view=diff
==============================================================================
--- 
camel/trunk/camel-core/src/test/java/org/apache/camel/component/directvm/DirectVmTwoCamelContextTest.java
 (original)
+++ 
camel/trunk/camel-core/src/test/java/org/apache/camel/component/directvm/DirectVmTwoCamelContextTest.java
 Fri Jun 15 12:02:14 2012
@@ -25,6 +25,8 @@ public class DirectVmTwoCamelContextTest
 
     public void testTwoCamelContext() throws Exception {
         getMockEndpoint("mock:result").expectedBodiesReceived("Bye World");
+        getMockEndpoint("mock:result").expectedHeaderReceived("name1", 
context.getName());
+        getMockEndpoint("mock:result").expectedHeaderReceived("name2", 
context2.getName());
 
         String out = template2.requestBody("direct:start", "Hello World", 
String.class);
         assertEquals("Bye World", out);
@@ -39,6 +41,7 @@ public class DirectVmTwoCamelContextTest
             public void configure() throws Exception {
                 from("direct-vm:foo")
                     .transform(constant("Bye World"))
+                    .setHeader("name1", simple("${camelId}"))
                     .log("Running on Camel ${camelId} on thread ${threadName} 
with message ${body}")
                     .to("mock:result");
             }
@@ -51,6 +54,7 @@ public class DirectVmTwoCamelContextTest
             @Override
             public void configure() throws Exception {
                 from("direct:start")
+                    .setHeader("name2", simple("${camelId}"))
                     .log("Running on Camel ${camelId} on thread ${threadName} 
with message ${body}")
                     .to("direct-vm:foo");
             }


Reply via email to