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

davsclaus 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 edb10a6  CAMEL-17588: Thread local in camel context should use only 
JDK classes to not have any Camel classes leaking.
edb10a6 is described below

commit edb10a6d787d2c688652f030edc364a83625fd92
Author: Claus Ibsen <[email protected]>
AuthorDate: Thu Mar 31 15:01:39 2022 +0200

    CAMEL-17588: Thread local in camel context should use only JDK classes to 
not have any Camel classes leaking.
---
 .../org/apache/camel/impl/DefaultCamelContext.java | 30 ++++++++++++----------
 1 file changed, 16 insertions(+), 14 deletions(-)

diff --git 
a/core/camel-core-engine/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
 
b/core/camel-core-engine/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
index 1d8545e..c3c38f7 100644
--- 
a/core/camel-core-engine/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
+++ 
b/core/camel-core-engine/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
@@ -99,7 +99,14 @@ import org.slf4j.LoggerFactory;
  */
 public class DefaultCamelContext extends SimpleCamelContext implements 
ModelCamelContext {
 
-    protected static final ThreadLocal<OptionHolder> OPTIONS = new 
NamedThreadLocal<>("CamelContextOptions", OptionHolder::new);
+    // global options that can be set on CamelContext as part of concurrent 
testing
+    // which means options should be isolated via thread-locals and not a 
static instance
+    // use a HashMap to store only JDK classes in the thread-local so there 
will not be any Camel classes leaking
+    private static final ThreadLocal<Map<String, Object>> OPTIONS = new 
NamedThreadLocal<>("CamelContextOptions", HashMap::new);
+    private static final String OPTION_NO_START = "OptionNoStart";
+    private static final String OPTION_DISABLE_JMX = "OptionDisableJMX";
+    private static final String OPTION_EXCLUDE_ROUTES = "OptionExcludeRoutes";
+
     private static final Logger LOG = 
LoggerFactory.getLogger(DefaultCamelContext.class);
     private static final UuidGenerator UUID = new SimpleUuidGenerator();
 
@@ -207,19 +214,19 @@ public class DefaultCamelContext extends 
SimpleCamelContext implements ModelCame
     }
 
     public static void setNoStart(boolean b) {
-        getOptions().noStart = b;
+        getOptions().put(OPTION_NO_START, b);
     }
 
     public static boolean isNoStart() {
-        return getOptions().noStart;
+        return (Boolean) getOptions().getOrDefault(OPTION_NO_START, 
Boolean.FALSE);
     }
 
     public static void setDisableJmx(boolean b) {
-        getOptions().disableJmx = b;
+        getOptions().put(OPTION_DISABLE_JMX, b);
     }
 
     public static boolean isDisableJmx() {
-        return getOptions().disableJmx;
+        return (Boolean) getOptions().getOrDefault(OPTION_DISABLE_JMX, 
Boolean.getBoolean(JmxSystemPropertyKeys.DISABLED));
     }
 
     @Override
@@ -228,18 +235,18 @@ public class DefaultCamelContext extends 
SimpleCamelContext implements ModelCame
     }
 
     public static String getExcludeRoutes() {
-        return getOptions().excludeRoutes;
+        return (String) getOptions().get(OPTION_NO_START);
     }
 
     public static void setExcludeRoutes(String s) {
-        getOptions().excludeRoutes = s;
+        getOptions().put(OPTION_EXCLUDE_ROUTES, s);
     }
 
     public static void clearOptions() {
-        OPTIONS.set(new OptionHolder());
+        OPTIONS.get().clear();
     }
 
-    private static OptionHolder getOptions() {
+    private static Map<String, Object> getOptions() {
         return OPTIONS.get();
     }
 
@@ -1006,9 +1013,4 @@ public class DefaultCamelContext extends 
SimpleCamelContext implements ModelCame
                 : new TransformerKey(new DataType(def.getFromType()), new 
DataType(def.getToType()));
     }
 
-    protected static class OptionHolder {
-        public boolean noStart;
-        public boolean disableJmx = 
Boolean.getBoolean(JmxSystemPropertyKeys.DISABLED);
-        public String excludeRoutes;
-    }
 }

Reply via email to