You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by or...@apache.org on 2023/08/28 19:36:03 UTC
[camel] branch main updated: (chores) camel-api: cleanup setting the message history (#11221)
This is an automated email from the ASF dual-hosted git repository.
orpiske pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new 4419aeefd18 (chores) camel-api: cleanup setting the message history (#11221)
4419aeefd18 is described below
commit 4419aeefd181cfc2aab2ed9270307d2b7c77649d
Author: Otavio Rodolfo Piske <or...@users.noreply.github.com>
AuthorDate: Mon Aug 28 21:35:56 2023 +0200
(chores) camel-api: cleanup setting the message history (#11221)
Signed-off-by: Otavio R. Piske <an...@gmail.com>
---
.../org/apache/camel/support/ExchangeHelper.java | 20 +++++++++++++-------
1 file changed, 13 insertions(+), 7 deletions(-)
diff --git a/core/camel-support/src/main/java/org/apache/camel/support/ExchangeHelper.java b/core/camel-support/src/main/java/org/apache/camel/support/ExchangeHelper.java
index f62e8de0403..1ab46faffed 100644
--- a/core/camel-support/src/main/java/org/apache/camel/support/ExchangeHelper.java
+++ b/core/camel-support/src/main/java/org/apache/camel/support/ExchangeHelper.java
@@ -794,6 +794,17 @@ public final class ExchangeHelper {
return copyExchangeAndSetCamelContext(exchange, context, true);
}
+ /*
+ * Safe copy message history using a defensive copy
+ */
+ private static void setMessageHistory(Exchange target, Exchange source) {
+ final Object history = source.getProperty(ExchangePropertyKey.MESSAGE_HISTORY);
+ if (history != null) {
+ // use thread-safe list as message history may be accessed concurrently
+ target.setProperty(ExchangePropertyKey.MESSAGE_HISTORY, new CopyOnWriteArrayList<>((List<MessageHistory>) history));
+ }
+ }
+
/**
* Copies the exchange but the copy will be tied to the given context
*
@@ -808,13 +819,8 @@ public final class ExchangeHelper {
answer.getExchangeExtension().setProperties(safeCopyProperties(exchange.getProperties()));
}
exchange.getExchangeExtension().copyInternalProperties(answer);
- // safe copy message history using a defensive copy
- List<MessageHistory> history
- = (List<MessageHistory>) exchange.getProperty(ExchangePropertyKey.MESSAGE_HISTORY);
- if (history != null) {
- // use thread-safe list as message history may be accessed concurrently
- answer.setProperty(ExchangePropertyKey.MESSAGE_HISTORY, new CopyOnWriteArrayList<>(history));
- }
+
+ setMessageHistory(answer, exchange);
if (handover) {
// Need to hand over the completion for async invocation