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 2022/04/08 08:07:20 UTC

[camel] branch camel-3.11.x updated: CAMEL-17910: camel-jms - InOut with reply-to-type shared - race condition

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

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


The following commit(s) were added to refs/heads/camel-3.11.x by this push:
     new 455bb384e16 CAMEL-17910: camel-jms - InOut with reply-to-type shared - race condition
455bb384e16 is described below

commit 455bb384e167357eaba35f26417d7e96bc853c2f
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Fri Apr 8 10:05:50 2022 +0200

    CAMEL-17910: camel-jms - InOut with reply-to-type shared - race condition
---
 .../jms/reply/MessageSelectorCreator.java          | 57 ++++++++++++----------
 1 file changed, 31 insertions(+), 26 deletions(-)

diff --git a/components/camel-jms/src/main/java/org/apache/camel/component/jms/reply/MessageSelectorCreator.java b/components/camel-jms/src/main/java/org/apache/camel/component/jms/reply/MessageSelectorCreator.java
index b33c809a46c..59d5a6605f3 100644
--- a/components/camel-jms/src/main/java/org/apache/camel/component/jms/reply/MessageSelectorCreator.java
+++ b/components/camel-jms/src/main/java/org/apache/camel/component/jms/reply/MessageSelectorCreator.java
@@ -34,6 +34,7 @@ public class MessageSelectorCreator {
     protected final ConcurrentSkipListSet<String> correlationIds;
     protected volatile boolean dirty = true;
     protected StringBuilder expression;
+    private final Object lock = new Object();
 
     public MessageSelectorCreator(CorrelationTimeoutMap timeoutMap) {
         this.timeoutMap = timeoutMap;
@@ -44,43 +45,47 @@ public class MessageSelectorCreator {
         this.correlationIds = new ConcurrentSkipListSet<>();
     }
 
-    public synchronized String get() {
-        if (!dirty) {
-            return expression.toString();
-        }
+    public String get() {
+        synchronized (lock) {
+            if (!dirty) {
+                return expression.toString();
+            }
 
-        expression = new StringBuilder("JMSCorrelationID='");
+            expression = new StringBuilder("JMSCorrelationID='");
 
-        if (correlationIds.isEmpty()) {
-            // no id's so use a dummy to select nothing
-            expression.append("CamelDummyJmsMessageSelector'");
-        } else {
-            boolean first = true;
-            for (String value : correlationIds) {
-                if (!first) {
-                    expression.append(" OR JMSCorrelationID='");
-                }
-                expression.append(value).append("'");
-                if (first) {
-                    first = false;
+            if (correlationIds.isEmpty()) {
+                // no id's so use a dummy to select nothing
+                expression.append("CamelDummyJmsMessageSelector'");
+            } else {
+                boolean first = true;
+                for (String value : correlationIds) {
+                    if (!first) {
+                        expression.append(" OR JMSCorrelationID='");
+                    }
+                    expression.append(value).append("'");
+                    if (first) {
+                        first = false;
+                    }
                 }
             }
-        }
 
-        String answer = expression.toString();
+            String answer = expression.toString();
 
-        dirty = false;
-        return answer;
+            dirty = false;
+            return answer;
+        }
     }
 
     // Changes to live correlation-ids invalidate existing message selector
     private void timeoutEvent(TimeoutMap.Listener.Type type, String cid) {
-        if (type == Put) {
-            correlationIds.add(cid);
-        } else if (type == Remove || type == Evict) {
-            correlationIds.remove(cid);
+        synchronized (lock) {
+            if (type == Put) {
+                correlationIds.add(cid);
+            } else if (type == Remove || type == Evict) {
+                correlationIds.remove(cid);
+            }
+            dirty = true;
         }
-        dirty = true;
     }
 
 }