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 2023/10/24 10:41:40 UTC

[camel] branch bean-leak created (now cb76fac82c7)

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

davsclaus pushed a change to branch bean-leak
in repository https://gitbox.apache.org/repos/asf/camel.git


      at cb76fac82c7 CAMEL-20035: camel-bean - Fix bean info cache gets populated per instance instead of per class. Only in special use-case use per instance.

This branch includes the following new commits:

     new 25cd55742cc CAMEL-20035: Added javadoc
     new cb76fac82c7 CAMEL-20035: camel-bean - Fix bean info cache gets populated per instance instead of per class. Only in special use-case use per instance.

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[camel] 01/02: CAMEL-20035: Added javadoc

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 25cd55742cc1c82cdd55665e06aa777711d4fd40
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Tue Oct 24 09:16:14 2023 +0200

    CAMEL-20035: Added javadoc
---
 .../java/org/apache/camel/support/LRUCache.java     | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/core/camel-support/src/main/java/org/apache/camel/support/LRUCache.java b/core/camel-support/src/main/java/org/apache/camel/support/LRUCache.java
index bc474a98793..e4bd04f6395 100644
--- a/core/camel-support/src/main/java/org/apache/camel/support/LRUCache.java
+++ b/core/camel-support/src/main/java/org/apache/camel/support/LRUCache.java
@@ -18,18 +18,39 @@ package org.apache.camel.support;
 
 import java.util.Map;
 
+/**
+ * A least-recently-used cache.
+ */
 public interface LRUCache<K, V> extends Map<K, V> {
 
+    /**
+     * Clears the cache
+     */
     void cleanUp();
 
+    /**
+     * Reset usage statistics
+     */
     void resetStatistics();
 
+    /**
+     * Gets the number of evicted elements
+     */
     long getEvicted();
 
+    /**
+     * Gets the number of cache misses.
+     */
     long getMisses();
 
+    /**
+     * Gets the number of cache hits.
+     */
     long getHits();
 
+    /**
+     * Maximum cache capacity.
+     */
     int getMaxCacheSize();
 
 }


[camel] 02/02: CAMEL-20035: camel-bean - Fix bean info cache gets populated per instance instead of per class. Only in special use-case use per instance.

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit cb76fac82c785a78037c6fe351d446cb837c5549
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Tue Oct 24 12:41:26 2023 +0200

    CAMEL-20035: camel-bean - Fix bean info cache gets populated per instance instead of per class. Only in special use-case use per instance.
---
 .../org/apache/camel/component/bean/BeanComponent.java   |  2 +-
 .../java/org/apache/camel/component/bean/BeanInfo.java   | 16 ++++++++++++++--
 .../component/bean/DefaultBeanProcessorFactory.java      |  3 +++
 3 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/components/camel-bean/src/main/java/org/apache/camel/component/bean/BeanComponent.java b/components/camel-bean/src/main/java/org/apache/camel/component/bean/BeanComponent.java
index 7fb4a8f1e54..b05ee04b8fe 100644
--- a/components/camel-bean/src/main/java/org/apache/camel/component/bean/BeanComponent.java
+++ b/components/camel-bean/src/main/java/org/apache/camel/component/bean/BeanComponent.java
@@ -92,7 +92,7 @@ public class BeanComponent extends DefaultComponent {
     }
 
     void addBeanInfoToCache(BeanInfoCacheKey key, BeanInfo beanInfo) {
-        if (beanInfoCache != null) {
+        if (beanInfoCache != null && beanInfo != null) {
             beanInfoCache.put(key, beanInfo);
         }
     }
diff --git a/components/camel-bean/src/main/java/org/apache/camel/component/bean/BeanInfo.java b/components/camel-bean/src/main/java/org/apache/camel/component/bean/BeanInfo.java
index f6fcb2cbd6b..5e0a27b908f 100644
--- a/components/camel-bean/src/main/java/org/apache/camel/component/bean/BeanInfo.java
+++ b/components/camel-bean/src/main/java/org/apache/camel/component/bean/BeanInfo.java
@@ -109,9 +109,13 @@ public class BeanInfo {
         this.component = beanComponent;
 
         final BeanInfoCacheKey key = new BeanInfoCacheKey(type, instance, explicitMethod);
+        final BeanInfoCacheKey key2 = instance != null ? new BeanInfoCacheKey(type, null, explicitMethod) : null;
 
         // lookup if we have a bean info cache
         BeanInfo beanInfo = component.getBeanInfoFromCache(key);
+        if (key2 != null && beanInfo == null) {
+            beanInfo = component.getBeanInfoFromCache(key2);
+        }
         if (beanInfo != null) {
             // copy the values from the cache we need
             defaultMethod = beanInfo.defaultMethod;
@@ -156,8 +160,16 @@ public class BeanInfo {
         operationsWithHandlerAnnotation = Collections.unmodifiableList(operationsWithHandlerAnnotation);
         methodMap = Collections.unmodifiableMap(methodMap);
 
-        // add new bean info to cache
-        component.addBeanInfoToCache(key, this);
+        // key must be instance based for custom/handler annotations
+        boolean instanceBased = !operationsWithCustomAnnotation.isEmpty() || !operationsWithHandlerAnnotation.isEmpty();
+        if (instanceBased) {
+            // add new bean info to cache (instance based)
+            component.addBeanInfoToCache(key, this);
+        } else {
+            // add new bean info to cache (not instance based, favour key2 if possible)
+            BeanInfoCacheKey k = key2 != null ? key2 : key;
+            component.addBeanInfoToCache(k, this);
+        }
     }
 
     public Class<?> getType() {
diff --git a/components/camel-bean/src/main/java/org/apache/camel/component/bean/DefaultBeanProcessorFactory.java b/components/camel-bean/src/main/java/org/apache/camel/component/bean/DefaultBeanProcessorFactory.java
index 9ff2ee574b6..7931d9a66d7 100644
--- a/components/camel-bean/src/main/java/org/apache/camel/component/bean/DefaultBeanProcessorFactory.java
+++ b/components/camel-bean/src/main/java/org/apache/camel/component/bean/DefaultBeanProcessorFactory.java
@@ -28,6 +28,7 @@ import org.apache.camel.StaticService;
 import org.apache.camel.spi.BeanProcessorFactory;
 import org.apache.camel.spi.annotations.JdkService;
 import org.apache.camel.support.CamelContextHelper;
+import org.apache.camel.support.service.ServiceHelper;
 import org.apache.camel.support.service.ServiceSupport;
 import org.apache.camel.util.ObjectHelper;
 import org.slf4j.Logger;
@@ -205,6 +206,8 @@ public final class DefaultBeanProcessorFactory extends ServiceSupport
     @Override
     protected void doInit() throws Exception {
         parameterMappingStrategy = ParameterMappingStrategyHelper.createParameterMappingStrategy(getCamelContext());
+
         beanComponent = getCamelContext().getComponent("bean", BeanComponent.class);
+        ServiceHelper.initService(beanComponent);
     }
 }