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 2019/06/07 10:14:22 UTC

[camel] 05/09: CAMEL-13515: Allow producer to lazy start until first message

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

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

commit 98ba75b1b7f89d3cb316305cbcf9b23d72646f14
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Fri Jun 7 11:17:23 2019 +0200

    CAMEL-13515: Allow producer to lazy start until first message
---
 .../ValidatorLazyStartProducerTest.java}                    | 13 ++++++++++---
 .../main/java/org/apache/camel/support/DefaultEndpoint.java |  1 -
 .../java/org/apache/camel/support/LazyStartProducer.java    |  5 +++--
 3 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/core/camel-core/src/test/java/org/apache/camel/component/bean/BeanLazyStartProducerTest.java b/core/camel-core/src/test/java/org/apache/camel/component/validator/ValidatorLazyStartProducerTest.java
similarity index 77%
rename from core/camel-core/src/test/java/org/apache/camel/component/bean/BeanLazyStartProducerTest.java
rename to core/camel-core/src/test/java/org/apache/camel/component/validator/ValidatorLazyStartProducerTest.java
index 4a69211..34c15a3 100644
--- a/core/camel-core/src/test/java/org/apache/camel/component/bean/BeanLazyStartProducerTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/component/validator/ValidatorLazyStartProducerTest.java
@@ -14,17 +14,24 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.camel.component.bean;
+package org.apache.camel.component.validator;
+
+import java.io.FileNotFoundException;
 
 import org.apache.camel.ContextTestSupport;
 import org.apache.camel.builder.RouteBuilder;
 import org.junit.Test;
 
-public class BeanLazyStartProducerTest extends ContextTestSupport {
+public class ValidatorLazyStartProducerTest extends ContextTestSupport {
 
     @Test
     public void testLazyStartProducer() throws Exception {
-        template.sendBody("direct:start", "Hello World");
+        try {
+            template.sendBody("direct:start", "Hello World");
+            fail("Should throw exception");
+        } catch (Exception e) {
+            assertIsInstanceOf(FileNotFoundException.class, e.getCause());
+        }
     }
 
     @Override
diff --git a/core/camel-support/src/main/java/org/apache/camel/support/DefaultEndpoint.java b/core/camel-support/src/main/java/org/apache/camel/support/DefaultEndpoint.java
index f4d37d7..941199e 100644
--- a/core/camel-support/src/main/java/org/apache/camel/support/DefaultEndpoint.java
+++ b/core/camel-support/src/main/java/org/apache/camel/support/DefaultEndpoint.java
@@ -189,7 +189,6 @@ public abstract class DefaultEndpoint extends ServiceSupport implements Endpoint
     @Override
     public AsyncProducer createAsyncProducer() throws Exception {
         if (isLazyStartProducer()) {
-            
             return new LazyStartProducer(this);
         } else {
             return AsyncProcessorConverterHelper.convert(createProducer());
diff --git a/core/camel-support/src/main/java/org/apache/camel/support/LazyStartProducer.java b/core/camel-support/src/main/java/org/apache/camel/support/LazyStartProducer.java
index 97f20fb..257e11a 100644
--- a/core/camel-support/src/main/java/org/apache/camel/support/LazyStartProducer.java
+++ b/core/camel-support/src/main/java/org/apache/camel/support/LazyStartProducer.java
@@ -22,11 +22,10 @@ import org.apache.camel.DelegateProcessor;
 import org.apache.camel.Endpoint;
 import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
-import org.apache.camel.Producer;
 import org.apache.camel.support.service.ServiceHelper;
 
 /**
- * A {@link org.apache.camel.Producer} which is started lazy, on the first message being processed.
+ * A {@link org.apache.camel.Producer} which is created and started lazy, on the first message processed.
  */
 public final class LazyStartProducer extends DefaultAsyncProducer implements DelegateProcessor {
 
@@ -39,6 +38,7 @@ public final class LazyStartProducer extends DefaultAsyncProducer implements Del
     @Override
     public boolean process(Exchange exchange, AsyncCallback callback) {
         try {
+            // create and start producer lazy
             if (delegate == null) {
                 synchronized (lock) {
                     if (delegate == null) {
@@ -51,6 +51,7 @@ public final class LazyStartProducer extends DefaultAsyncProducer implements Del
             }
         } catch (Throwable e) {
             exchange.setException(e);
+            callback.done(true);
             return true;
         }
         return delegate.process(exchange, callback);