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 2018/02/05 15:28:28 UTC

[camel] 07/07: CAMEL-8958: Claim Check EIP with push/pop. Work in progress.

This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch 8958
in repository https://gitbox.apache.org/repos/asf/camel.git

commit b416c74809afe430e7020d788b7e3d9fa66fdb2e
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Mon Feb 5 15:50:58 2018 +0100

    CAMEL-8958: Claim Check EIP with push/pop. Work in progress.
---
 camel-core/src/main/docs/eips/claimCheck-eip.adoc  | 48 ++++++++++++++++++++--
 .../camel/impl/DefaultClaimCheckRepository.java    |  3 ++
 .../camel/processor/ClaimCheckProcessor.java       |  5 +++
 .../org/apache/camel/spi/ClaimCheckRepository.java |  9 ++--
 4 files changed, 59 insertions(+), 6 deletions(-)

diff --git a/camel-core/src/main/docs/eips/claimCheck-eip.adoc b/camel-core/src/main/docs/eips/claimCheck-eip.adoc
index f9d34e0..a250cff 100644
--- a/camel-core/src/main/docs/eips/claimCheck-eip.adoc
+++ b/camel-core/src/main/docs/eips/claimCheck-eip.adoc
@@ -1,6 +1,8 @@
 [[claimCheck-eip]]
 == Claim Check EIP
 
+Available as of Camel 2.21
+
 The Claim Check EIP allows you to replace message content with a claim check (a unique key),
 which can be used to retrieve the message content at a later time.
 
@@ -153,7 +155,17 @@ The following example shows the `Push` and `Pop` operations in action;
 
 [xml]
 ----
-TODO: XML example
+<route>
+  <from uri="direct:start"/>
+  <to uri="mock:a"/>
+  <claimCheck operation="Push"/>
+  <transform>
+    <constant>Bye World</constant>
+  </transform>
+  <to uri="mock:b"/>
+  <claimCheck operation="Pop"/>
+  <to uri="mock:c"/>
+</route>
 ----
 
 For example if the message body from the beginning is `Hello World` then that data is pushed on the stack of the Claim Check EIP.
@@ -164,7 +176,23 @@ Here is an example using `Get` and `Set` operations, which uses the key `foo`:
 
 [xml]
 ----
-TODO: XML example
+<route>
+  <from uri="direct:start"/>
+  <to uri="mock:a"/>
+  <claimCheck operation="Set" key="foo"/>
+  <transform>
+    <constant>Bye World</constant>
+  </transform>
+  <to uri="mock:b"/>
+  <claimCheck operation="Get" key="foo"/>
+  <to uri="mock:c"/>
+  <transform>
+    <constant>Hi World</constant>
+  </transform>
+  <to uri="mock:d"/>
+  <claimCheck operation="Get" key="foo"/>
+  <to uri="mock:e"/>
+</route>
 ----
 
 Notice how we can `Get` the same data twice using the `Get` operation as it will not remove the data. If you only want
@@ -174,5 +202,19 @@ The last example shows how to use the `data` option where we only want to get ba
 
 [xml]
 ----
-TODO: XML example
+<route>
+  <from uri="direct:start"/>
+  <to uri="mock:a"/>
+  <claimCheck operation="Push"/>
+  <transform>
+    <constant>Bye World</constant>
+  </transform>
+  <setHeader headerName="foo">
+    <constant>456</constant>
+  </setHeader>
+  <removeHeader headerName="bar"/>
+  <to uri="mock:b"/>
+  <claimCheck operation="Pop" data="header:(foo|bar)"/>
+  <to uri="mock:c"/>
+</route>
 ----
diff --git a/camel-core/src/main/java/org/apache/camel/impl/DefaultClaimCheckRepository.java b/camel-core/src/main/java/org/apache/camel/impl/DefaultClaimCheckRepository.java
index 91e1db2..7f1c630 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/DefaultClaimCheckRepository.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/DefaultClaimCheckRepository.java
@@ -24,6 +24,9 @@ import java.util.Map;
 import org.apache.camel.Exchange;
 import org.apache.camel.spi.ClaimCheckRepository;
 
+/**
+ * The default {@link ClaimCheckRepository} implementation that is an in-memory storage.
+ */
 public class DefaultClaimCheckRepository implements ClaimCheckRepository {
 
     private final Map<String, Exchange> map = new HashMap<>();
diff --git a/camel-core/src/main/java/org/apache/camel/processor/ClaimCheckProcessor.java b/camel-core/src/main/java/org/apache/camel/processor/ClaimCheckProcessor.java
index 4f83e53..9a904e9 100644
--- a/camel-core/src/main/java/org/apache/camel/processor/ClaimCheckProcessor.java
+++ b/camel-core/src/main/java/org/apache/camel/processor/ClaimCheckProcessor.java
@@ -35,6 +35,11 @@ import org.slf4j.LoggerFactory;
 
 /**
  * ClaimCheck EIP implementation.
+ * <p/>
+ * The current Claim Check EIP implementation in Camel is only intended for temporary memory repository. Likewise
+ * the repository is not shared among {@link Exchange}s, but a private instance is created per {@link Exchange}.
+ * This guards against concurrent and thread-safe issues. For off-memeory persistent storage of data, then use
+ * any of the many Camel components that support persistent storage, and do not use this Claim Check EIP implementation.
  */
 public class ClaimCheckProcessor extends ServiceSupport implements AsyncProcessor, IdAware, CamelContextAware {
 
diff --git a/camel-core/src/main/java/org/apache/camel/spi/ClaimCheckRepository.java b/camel-core/src/main/java/org/apache/camel/spi/ClaimCheckRepository.java
index 7292f4b..1eb133f 100644
--- a/camel-core/src/main/java/org/apache/camel/spi/ClaimCheckRepository.java
+++ b/camel-core/src/main/java/org/apache/camel/spi/ClaimCheckRepository.java
@@ -20,10 +20,13 @@ import org.apache.camel.Exchange;
 import org.apache.camel.Service;
 
 /**
- * Access to a repository of Keys to implement the
+ * Access to a repository of keys to implement the
  * <a href="http://camel.apache.org/claim-check.html">Claim Check</a> pattern.
  * <p/>
- * The <tt>add</tt> and <tt>contains</tt> methods is operating according to the {@link java.util.Set} contract.
+ * The <tt>add</tt> and <tt>contains</tt> methods is operating according to the {@link java.util.Map} contract,
+ * and the <tt>push</tt> and <tt>pop</tt> methods is operating according to the {@link java.util.Stack} contract.
+ * <p/>
+ * See important details about the Claim Check EIP implementation in Apache Camel at {@link org.apache.camel.processor.ClaimCheckProcessor}.
  */
 public interface ClaimCheckRepository extends Service {
 
@@ -64,7 +67,7 @@ public interface ClaimCheckRepository extends Service {
     void push(Exchange exchange);
 
     /**
-     * Pops the repository and returns the latest.
+     * Pops the repository and returns the latest. Or returns <tt>null</tt> if the stack is empty.
      */
     Exchange pop();
 

-- 
To stop receiving notification emails like this one, please contact
davsclaus@apache.org.