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 2024/10/02 06:35:16 UTC

(camel) branch camel-4.4.x updated: Add a cache for JAXB ObjectFactory lookup (#15707)

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

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


The following commit(s) were added to refs/heads/camel-4.4.x by this push:
     new 4fdef7156ff Add a cache for JAXB ObjectFactory lookup (#15707)
4fdef7156ff is described below

commit 4fdef7156ffc9f615ceabc4cb6b446e8566358f6
Author: Adriano Machado <60...@users.noreply.github.com>
AuthorDate: Wed Oct 2 02:33:53 2024 -0400

    Add a cache for JAXB ObjectFactory lookup (#15707)
---
 .../src/main/java/org/apache/camel/converter/jaxb/JaxbHelper.java | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/JaxbHelper.java b/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/JaxbHelper.java
index cf032921b76..f1991ca1a5c 100644
--- a/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/JaxbHelper.java
+++ b/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/JaxbHelper.java
@@ -17,13 +17,17 @@
 package org.apache.camel.converter.jaxb;
 
 import java.lang.reflect.Method;
+import java.util.Map;
 
 import jakarta.xml.bind.annotation.XmlElementDecl;
 
 import org.apache.camel.CamelContext;
+import org.apache.camel.support.LRUCacheFactory;
 
 public final class JaxbHelper {
 
+    private static final Map<Class<?>, Method> JAXB_ELEMENT_FACTORY_METHODS = LRUCacheFactory.newLRUSoftCache(10, 100, true);
+
     private JaxbHelper() {
     }
 
@@ -32,6 +36,10 @@ public final class JaxbHelper {
             return null;
         }
 
+        return JAXB_ELEMENT_FACTORY_METHODS.computeIfAbsent(type, t -> findJaxbElementFactoryMethod(camelContext, t));
+    }
+
+    private static <T> Method findJaxbElementFactoryMethod(CamelContext camelContext, Class<T> type) {
         // find the first method that has @XmlElementDecl with one parameter that matches the type
         Class<?> factory = getObjectFactory(camelContext, type);
         if (factory != null) {