You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2022/03/07 14:38:23 UTC

[camel] 02/03: camel-core - Resumable DSL keep same type in Java DSL as it has no mo… (#7134)

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

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

commit b7118b498200cc75e54da323e0137e2116c44329
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Mon Mar 7 15:13:40 2022 +0100

    camel-core - Resumable DSL keep same type in Java DSL as it has no mo… (#7134)
    
    * camel-core - Resumable DSL keep same type in Java DSL as it has no more configuration, and changing types can cause problems for Java DSL. Add string parameter variant to make it easy to use.
---
 .../docs/modules/eips/pages/resume-strategies.adoc |  8 +++---
 .../apache/camel/model/ProcessorDefinition.java    | 32 +++++++++++++++++-----
 .../apache/camel/model/ResumableDefinition.java    |  3 ++
 .../FileConsumerResumeFromOffsetStrategyTest.java  |  5 ++--
 .../file/FileConsumerResumeStrategyTest.java       |  2 +-
 5 files changed, 36 insertions(+), 14 deletions(-)

diff --git a/core/camel-core-engine/src/main/docs/modules/eips/pages/resume-strategies.adoc b/core/camel-core-engine/src/main/docs/modules/eips/pages/resume-strategies.adoc
index a1e151b..214157b 100644
--- a/core/camel-core-engine/src/main/docs/modules/eips/pages/resume-strategies.adoc
+++ b/core/camel-core-engine/src/main/docs/modules/eips/pages/resume-strategies.adoc
@@ -33,7 +33,7 @@ This instance can be bound in the Context registry as follows:
 getCamelContext().getRegistry().bind("testResumeStrategy", new MyTestResumeStrategy());
 
 from("some:component")
-    .resumable().resumableStrategy("testResumeStrategy")
+    .resumable("testResumeStrategy")
     .process(this::process);
 ----
 
@@ -42,8 +42,8 @@ Or the instance can be constructed as follows:
 [source,java]
 ----
 from("some:component")
+    .resumable(new MyTestResumeStrategy())
     .process(this::process)
-    .resumable().resumableStrategy(new MyTestResumeStrategy());
 ----
 
 == The Resume API Interfaces
@@ -175,7 +175,7 @@ For instance, the behavior of:
 [source,java]
 ----
 from("file:{{input.dir}}?noop=true&fileName={{input.file}}")
-    .resumable().resumableStrategy("testResumeStrategy")
+    .resumable("testResumeStrategy")
     .convertBodyTo(Reader.class)
     .process(this::process);
 ----
@@ -185,7 +185,7 @@ Is different from the behavior of:
 [source,java]
 ----
 from("file:{{input.dir}}?noop=true&fileName={{input.file}}")
-    .resumable().resumableStrategyRef("testResumeStrategy")
+    .resumable("testResumeStrategy")
     .convertBodyTo(InputStream.class)
     .process(this::process);
 ----
diff --git a/core/camel-core-model/src/main/java/org/apache/camel/model/ProcessorDefinition.java b/core/camel-core-model/src/main/java/org/apache/camel/model/ProcessorDefinition.java
index 611eed2..ca37b7a 100644
--- a/core/camel-core-model/src/main/java/org/apache/camel/model/ProcessorDefinition.java
+++ b/core/camel-core-model/src/main/java/org/apache/camel/model/ProcessorDefinition.java
@@ -3815,24 +3815,42 @@ public abstract class ProcessorDefinition<Type extends ProcessorDefinition<Type>
 
     /**
      * This defines the route as resumable, which allows the route to work with the endpoints and components to manage
-     * the state of consumers and resume upon restart
-     * 
-     * @return The expression to create the Resumable
+     * the state of consumers and resume upon restart.
+     *
+     * @return                     the builder
      */
     public ResumableDefinition resumable() {
         ResumableDefinition answer = new ResumableDefinition();
-
         addOutput(answer);
         return answer;
     }
 
-    public ResumableDefinition resumable(ResumeStrategy resumeStrategy) {
+    /**
+     * This defines the route as resumable, which allows the route to work with the endpoints and components to manage
+     * the state of consumers and resume upon restart.
+     *
+     * @param  resumeStrategy      the resume strategy
+     * @return                     the builder
+     */
+    public Type resumable(ResumeStrategy resumeStrategy) {
         ResumableDefinition answer = new ResumableDefinition();
-
         answer.setResumeStrategy(resumeStrategy);
+        addOutput(answer);
+        return asType();
+    }
 
+    /**
+     * This defines the route as resumable, which allows the route to work with the endpoints and components to manage
+     * the state of consumers and resume upon restart.
+     *
+     * @param  resumeStrategy      the resume strategy
+     * @return                     the builder
+     */
+    public Type resumable(String resumeStrategy) {
+        ResumableDefinition answer = new ResumableDefinition();
+        answer.setResumeStrategy(resumeStrategy);
         addOutput(answer);
-        return answer;
+        return asType();
     }
 
     // Properties
diff --git a/core/camel-core-model/src/main/java/org/apache/camel/model/ResumableDefinition.java b/core/camel-core-model/src/main/java/org/apache/camel/model/ResumableDefinition.java
index c0c5f26..63ed0f1 100644
--- a/core/camel-core-model/src/main/java/org/apache/camel/model/ResumableDefinition.java
+++ b/core/camel-core-model/src/main/java/org/apache/camel/model/ResumableDefinition.java
@@ -77,6 +77,9 @@ public class ResumableDefinition extends NoOutputDefinition<ResumableDefinition>
         return this;
     }
 
+    /**
+     * Sets the resume strategy to use
+     */
     public ResumableDefinition resumeStrategy(ResumeStrategy resumeStrategy) {
         setResumeStrategy(resumeStrategy);
         return this;
diff --git a/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerResumeFromOffsetStrategyTest.java b/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerResumeFromOffsetStrategyTest.java
index 044b79e..f258e5e 100644
--- a/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerResumeFromOffsetStrategyTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerResumeFromOffsetStrategyTest.java
@@ -37,6 +37,7 @@ import org.junit.jupiter.api.DisplayName;
 import org.junit.jupiter.api.Test;
 
 public class FileConsumerResumeFromOffsetStrategyTest extends ContextTestSupport {
+
     private static class TestResumeStrategy implements GenericFileResumeStrategy<File> {
         @Override
         public void resume(GenericFileResumable<File> resumable) {
@@ -126,11 +127,11 @@ public class FileConsumerResumeFromOffsetStrategyTest extends ContextTestSupport
             @Override
             public void configure() {
 
-                bindToRegistry("resumeStrategy", new TestResumeStrategy());
+                bindToRegistry("myResumeStrategy", new TestResumeStrategy());
                 bindToRegistry("resumeNotToBeCalledStrategy", FAIL_RESUME_STRATEGY);
 
                 from(fileUri("resumeOff?noop=true&recursive=true"))
-                        .resumable().resumeStrategy("resumeStrategy")
+                        .resumable("myResumeStrategy")
                         .setHeader(Exchange.OFFSET,
                                 constant(Resumables.of("resume-none.txt", 3)))
                         .log("${body}")
diff --git a/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerResumeStrategyTest.java b/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerResumeStrategyTest.java
index 77e4e9d..c8308b0 100644
--- a/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerResumeStrategyTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerResumeStrategyTest.java
@@ -102,7 +102,7 @@ public class FileConsumerResumeStrategyTest extends ContextTestSupport {
                 bindToRegistry("testResumeStrategy", new TestResumeStrategy());
 
                 from(fileUri("resume?noop=true&recursive=true"))
-                        .resumable().resumeStrategy("testResumeStrategy")
+                        .resumable("testResumeStrategy")
                         .process(e -> setOffset(e))
                         .convertBodyTo(String.class)
                         .to("mock:result");