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 2021/02/18 15:12:45 UTC

[camel] 02/03: CAMEL-16222: PooledExchangeFactory experiment

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

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

commit 870df82be40b0e5b13606b60e0ded2e75f6861f2
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Thu Feb 18 16:00:20 2021 +0100

    CAMEL-16222: PooledExchangeFactory experiment
---
 .../camel/component/disruptor/DisruptorConsumer.java    | 11 +++++++++++
 .../camel/component/master/EndpointUriEncodingTest.java |  2 +-
 .../main/java/org/apache/camel/spi/ExchangeFactory.java | 17 +++++++++++------
 3 files changed, 23 insertions(+), 7 deletions(-)

diff --git a/components/camel-disruptor/src/main/java/org/apache/camel/component/disruptor/DisruptorConsumer.java b/components/camel-disruptor/src/main/java/org/apache/camel/component/disruptor/DisruptorConsumer.java
index 77b74e4..29cb921 100644
--- a/components/camel-disruptor/src/main/java/org/apache/camel/component/disruptor/DisruptorConsumer.java
+++ b/components/camel-disruptor/src/main/java/org/apache/camel/component/disruptor/DisruptorConsumer.java
@@ -192,6 +192,17 @@ public class DisruptorConsumer extends ServiceSupport implements Consumer, Suspe
         }
     }
 
+    @Override
+    public Exchange createExchange(boolean autoRelease) {
+        // noop
+        return null;
+    }
+
+    @Override
+    public void releaseExchange(Exchange exchange) {
+        // noop
+    }
+
     /**
      * Implementation of the {@link LifecycleAwareExchangeEventHandler} interface that passes all Exchanges to the
      * {@link Processor} registered at this {@link DisruptorConsumer}.
diff --git a/components/camel-master/src/test/java/org/apache/camel/component/master/EndpointUriEncodingTest.java b/components/camel-master/src/test/java/org/apache/camel/component/master/EndpointUriEncodingTest.java
index 37c701c..c78a06c 100644
--- a/components/camel-master/src/test/java/org/apache/camel/component/master/EndpointUriEncodingTest.java
+++ b/components/camel-master/src/test/java/org/apache/camel/component/master/EndpointUriEncodingTest.java
@@ -86,7 +86,7 @@ public class EndpointUriEncodingTest extends CamelTestSupport {
                     return new DefaultConsumer(this, processor) {
                         @Override
                         public void start() {
-                            Exchange exchange = createExchange();
+                            Exchange exchange = createExchange(true);
                             exchange.getMessage().setHeader("foo", foo);
                             exchange.getMessage().setHeader("bar", bar);
                             try {
diff --git a/core/camel-api/src/main/java/org/apache/camel/spi/ExchangeFactory.java b/core/camel-api/src/main/java/org/apache/camel/spi/ExchangeFactory.java
index 8e429f2..a666bdd 100644
--- a/core/camel-api/src/main/java/org/apache/camel/spi/ExchangeFactory.java
+++ b/core/camel-api/src/main/java/org/apache/camel/spi/ExchangeFactory.java
@@ -21,17 +21,22 @@ import org.apache.camel.Endpoint;
 import org.apache.camel.Exchange;
 
 /**
- * Factory for creating {@link Exchange}.
- *
+ * Factory used by {@link Consumer} to create Camel {@link Exchange} holding the incoming message received by the consumer.
+ * <p/>
+ * This factory is only for {@link Consumer}'s to give control on how {@link Exchange} are created and comes into Camel.
+ * Each Camel component that provides a {@link Consumer} should use this {@link ExchangeFactory}.
+ * There may be other parts in Camel that creates {@link Exchange} such as sub exchanges from Splitter EIP,
+ * but they are not part of this contract as we only want to control the created {@link Exchange} that comes
+ * into Camel via {@link Consumer} or {@link org.apache.camel.PollingConsumer}.
+ * <p/>
  * The factory is pluggable which allows to use different strategies. The default factory will create a new
  * {@link Exchange} instance, and the pooled factory will pool and reuse exchanges.
  */
 public interface ExchangeFactory {
 
-    // TODO: new factory per consumer so there is no single race bottleneck
-    // TODO: only use factory on route consumer to limit its scope to most significant impact
     // TODO: release from extended exchange without onCompletion (overhead)
     // TODO: reuse unit of work (expensive to create)
+    // TODO: release via DoneUoW in less expensive way
 
     /**
      * Service factory key.
@@ -41,8 +46,8 @@ public interface ExchangeFactory {
     /**
      * Creates a new {@link ExchangeFactory} that is private for the given consumer.
      *
-     * @param consumer the consumer that will use the created {@link ExchangeFactory}
-     * @return the created factory.
+     * @param  consumer the consumer that will use the created {@link ExchangeFactory}
+     * @return          the created factory.
      */
     ExchangeFactory newExchangeFactory(Consumer consumer);