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
The following commit(s) were added to refs/heads/exchange-factory by this push:
new 862be97 CAMEL-16222: PooledExchangeFactory experiment
862be97 is described below
commit 862be975322d355dc3ee5be44329b9e7e25810b2
Author: Claus Ibsen <[email protected]>
AuthorDate: Fri Feb 19 17:21:04 2021 +0100
CAMEL-16222: PooledExchangeFactory experiment
---
.../camel/component/timer/TimerConsumer.java | 3 ++-
.../src/main/java/org/apache/camel/Consumer.java | 9 ++++----
.../src/main/java/org/apache/camel/Endpoint.java | 8 +++----
.../org/apache/camel/support/DefaultExchange.java | 25 ++++++++++++++++------
4 files changed, 28 insertions(+), 17 deletions(-)
diff --git
a/components/camel-timer/src/main/java/org/apache/camel/component/timer/TimerConsumer.java
b/components/camel-timer/src/main/java/org/apache/camel/component/timer/TimerConsumer.java
index 8fd997c..30a1d70 100644
---
a/components/camel-timer/src/main/java/org/apache/camel/component/timer/TimerConsumer.java
+++
b/components/camel-timer/src/main/java/org/apache/camel/component/timer/TimerConsumer.java
@@ -204,7 +204,8 @@ public class TimerConsumer extends DefaultConsumer
implements StartupListener, S
public void done(boolean cbDoneSync) {
// handle any thrown exception
if (exchange.getException() != null) {
-
TimerConsumer.this.getExceptionHandler().handleException("Error processing
exchange", exchange, exchange.getException());
+
TimerConsumer.this.getExceptionHandler().handleException("Error processing
exchange", exchange,
+ exchange.getException());
}
// sync wil release outside this callback
if (!cbDoneSync) {
diff --git a/core/camel-api/src/main/java/org/apache/camel/Consumer.java
b/core/camel-api/src/main/java/org/apache/camel/Consumer.java
index 4d15bf0..25c24f6 100644
--- a/core/camel-api/src/main/java/org/apache/camel/Consumer.java
+++ b/core/camel-api/src/main/java/org/apache/camel/Consumer.java
@@ -35,11 +35,10 @@ public interface Consumer extends Service, EndpointAware {
/**
* Creates an {@link Exchange} that was consumed.
* <p/>
- * <b>Important:</b> If the auto release parameter is set to
<tt>false</tt> then
- * the consumer is responsible for calling the {@link
#releaseExchange(Exchange, boolean)} when the {@link Exchange}
- * is done being routed. This is for advanced consumers that need to have
this control in their own hands.
- * For normal use-cases then a consumer can use autoRelease <tt>true</tt>
and then Camel will automatic
- * release the exchange after routing.
+ * <b>Important:</b> If the auto release parameter is set to
<tt>false</tt> then the consumer is responsible for
+ * calling the {@link #releaseExchange(Exchange, boolean)} when the {@link
Exchange} is done being routed. This is
+ * for advanced consumers that need to have this control in their own
hands. For normal use-cases then a consumer
+ * can use autoRelease <tt>true</tt> and then Camel will automatic release
the exchange after routing.
*
* @param autoRelease whether to auto release the exchange when routing is
complete via {@link UnitOfWork}
*/
diff --git a/core/camel-api/src/main/java/org/apache/camel/Endpoint.java
b/core/camel-api/src/main/java/org/apache/camel/Endpoint.java
index ea85f3e..a8301dc 100644
--- a/core/camel-api/src/main/java/org/apache/camel/Endpoint.java
+++ b/core/camel-api/src/main/java/org/apache/camel/Endpoint.java
@@ -65,8 +65,8 @@ public interface Endpoint extends IsSingleton, Service {
/**
* Create a new exchange for communicating with this endpoint.
* <p/>
- * <b>Important:</b> Consumers should use {@link
Consumer#createExchange(boolean)} to create
- * an exchange for which the consumer received a message.
+ * <b>Important:</b> Consumers should use {@link
Consumer#createExchange(boolean)} to create an exchange for which
+ * the consumer received a message.
*
* @return a new exchange
*/
@@ -76,8 +76,8 @@ public interface Endpoint extends IsSingleton, Service {
* Create a new exchange for communicating with this endpoint with the
specified {@link ExchangePattern} such as
* whether its going to be an {@link ExchangePattern#InOnly} or {@link
ExchangePattern#InOut} exchange
* <p/>
- * <b>Important:</b> Consumers should use {@link
Consumer#createExchange(boolean)} to create
- * an exchange for which the consumer received a message.
+ * <b>Important:</b> Consumers should use {@link
Consumer#createExchange(boolean)} to create an exchange for which
+ * the consumer received a message.
*
* @param pattern the message exchange pattern for the exchange
* @return a new exchange
diff --git
a/core/camel-support/src/main/java/org/apache/camel/support/DefaultExchange.java
b/core/camel-support/src/main/java/org/apache/camel/support/DefaultExchange.java
index 371b991..a6955b1 100644
---
a/core/camel-support/src/main/java/org/apache/camel/support/DefaultExchange.java
+++
b/core/camel-support/src/main/java/org/apache/camel/support/DefaultExchange.java
@@ -52,6 +52,7 @@ public final class DefaultExchange implements
ExtendedExchange {
private final Map<String, Object> properties = new ConcurrentHashMap<>(8);
private Class originalInClassType;
private Message in;
+ private Message originalOut;
private Message out;
private Exception exception;
private String exchangeId;
@@ -149,12 +150,14 @@ public final class DefaultExchange implements
ExtendedExchange {
} else {
this.in = null;
}
- this.out = null;
- this.exception = null;
- // reset uow
+ if (out != null) {
+ out.reset();
+ this.out = null;
+ }
if (this.unitOfWork != null) {
this.unitOfWork.reset();
}
+ this.exception = null;
// reset pattern to original
this.pattern = originalPattern;
if (this.onCompletions != null) {
@@ -434,9 +437,14 @@ public final class DefaultExchange implements
ExtendedExchange {
public Message getOut() {
// lazy create
if (out == null) {
- out = (in instanceof MessageSupport)
- ? ((MessageSupport) in).newInstance() : new
DefaultMessage(getContext());
- configureMessage(out);
+ if (originalOut != null) {
+ out = originalOut;
+ } else {
+ // we can only optimize OUT when its using a default message
instance
+ out = new DefaultMessage(this);
+ configureMessage(out);
+ originalOut = out;
+ }
}
return out;
}
@@ -467,7 +475,10 @@ public final class DefaultExchange implements
ExtendedExchange {
@Override
public void setOut(Message out) {
this.out = out;
- configureMessage(out);
+ if (out != null) {
+ configureMessage(out);
+ this.originalOut = null; // we use custom out
+ }
}
@Override