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 2019/08/25 11:43:10 UTC

[camel] branch master updated (483b0d4 -> 8138706)

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

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


    from 483b0d4  Fixed CS for Camel-support
     new 4b71a46  CAMEL-13907: Lets clear bean introspection cache after bootstrap of Camel as the cache was used during initialization.
     new 8138706  CAMEL-13907: Lets clear bean introspection cache after bootstrap of Camel as the cache was used during initialization.

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.


Summary of changes:
 .../org/apache/camel/spi/BeanIntrospection.java    | 30 +++++++++++++--
 .../camel/impl/engine/AbstractCamelContext.java    |  9 ++++-
 .../impl/engine/CamelPostProcessorHelper.java      |  4 +-
 .../impl/engine/DefaultBeanIntrospection.java      | 43 ++++++++++++----------
 .../mbean/ManagedBeanIntrospectionMBean.java       |  6 +++
 .../management/mbean/ManagedBeanIntrospection.java | 10 +++++
 .../management/ManagedBeanIntrospectionTest.java   |  2 +-
 .../apache/camel/support/IntrospectionSupport.java | 11 ++++++
 .../camel/support/PropertyBindingSupport.java      |  2 +-
 9 files changed, 88 insertions(+), 29 deletions(-)


[camel] 01/02: CAMEL-13907: Lets clear bean introspection cache after bootstrap of Camel as the cache was used during initialization.

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

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

commit 4b71a46ac6672b4fc8fcf6e9ce4dfde440646972
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Sun Aug 25 09:39:23 2019 +0200

    CAMEL-13907: Lets clear bean introspection cache after bootstrap of Camel as the cache was used during initialization.
---
 .../org/apache/camel/spi/BeanIntrospection.java    | 25 +++++++++++++--
 .../impl/engine/CamelPostProcessorHelper.java      |  4 +--
 .../impl/engine/DefaultBeanIntrospection.java      | 37 ++++++++++------------
 .../management/ManagedBeanIntrospectionTest.java   |  2 +-
 .../camel/support/PropertyBindingSupport.java      |  2 +-
 5 files changed, 43 insertions(+), 27 deletions(-)

diff --git a/core/camel-api/src/main/java/org/apache/camel/spi/BeanIntrospection.java b/core/camel-api/src/main/java/org/apache/camel/spi/BeanIntrospection.java
index d4a5192..9680037 100644
--- a/core/camel-api/src/main/java/org/apache/camel/spi/BeanIntrospection.java
+++ b/core/camel-api/src/main/java/org/apache/camel/spi/BeanIntrospection.java
@@ -129,12 +129,31 @@ public interface BeanIntrospection extends StaticService {
      */
     ClassInfo cacheClass(Class<?> clazz);
 
-    Object getOrElseProperty(Object target, String propertyName, Object defaultValue);
+    /**
+     * Clears the introspection cache.
+     */
+    void clearCache();
 
+    /**
+     * Gets the property or else returning the default value.
+     *
+     * @param target         the target bean
+     * @param propertyName   the property name
+     * @param defaultValue   the default value
+     * @param ignoreCase     whether to ignore case for matching the property name
+     * @return the property value, or the default value if the target does not have a property with the given name
+     */
     Object getOrElseProperty(Object target, String propertyName, Object defaultValue, boolean ignoreCase);
 
-    Method getPropertyGetter(Class<?> type, String propertyName) throws NoSuchMethodException;
-
+    /**
+     * Gets the getter method for the property.
+     *
+     * @param type            the target class
+     * @param propertyName    the property name
+     * @param ignoreCase      whether to ignore case for matching the property name
+     * @return                the getter method
+     * @throws NoSuchMethodException  is thrown if there are no getter method for the property
+     */
     Method getPropertyGetter(Class<?> type, String propertyName, boolean ignoreCase) throws NoSuchMethodException;
 
     /**
diff --git a/core/camel-base/src/main/java/org/apache/camel/impl/engine/CamelPostProcessorHelper.java b/core/camel-base/src/main/java/org/apache/camel/impl/engine/CamelPostProcessorHelper.java
index b28cf0f..c6e65dd 100644
--- a/core/camel-base/src/main/java/org/apache/camel/impl/engine/CamelPostProcessorHelper.java
+++ b/core/camel-base/src/main/java/org/apache/camel/impl/engine/CamelPostProcessorHelper.java
@@ -178,10 +178,10 @@ public class CamelPostProcessorHelper implements CamelContextAware {
         // 2. then the getter with Endpoint as postfix
         // 3. then if start with on then try step 1 and 2 again, but omit the on prefix
         try {
-            Object value = getCamelContext().adapt(ExtendedCamelContext.class).getBeanIntrospection().getOrElseProperty(bean, propertyName, null);
+            Object value = getCamelContext().adapt(ExtendedCamelContext.class).getBeanIntrospection().getOrElseProperty(bean, propertyName, null, false);
             if (value == null) {
                 // try endpoint as postfix
-                value = getCamelContext().adapt(ExtendedCamelContext.class).getBeanIntrospection().getOrElseProperty(bean, propertyName + "Endpoint", null);
+                value = getCamelContext().adapt(ExtendedCamelContext.class).getBeanIntrospection().getOrElseProperty(bean, propertyName + "Endpoint", null, false);
             }
             if (value == null && propertyName.startsWith("on")) {
                 // retry but without the on as prefix
diff --git a/core/camel-base/src/main/java/org/apache/camel/impl/engine/DefaultBeanIntrospection.java b/core/camel-base/src/main/java/org/apache/camel/impl/engine/DefaultBeanIntrospection.java
index ca8bca9..2d02c38 100644
--- a/core/camel-base/src/main/java/org/apache/camel/impl/engine/DefaultBeanIntrospection.java
+++ b/core/camel-base/src/main/java/org/apache/camel/impl/engine/DefaultBeanIntrospection.java
@@ -77,41 +77,47 @@ public class DefaultBeanIntrospection extends ServiceSupport implements BeanIntr
         if (args != null && args.length > 0) {
             obj = Arrays.asList(args);
         }
-        logger.log("Invoked: " + invoked.get() + " times (overall) [Method: " + method + ", Target: " + target + ", Arguments: " + obj + " ]");
+        if (target == null) {
+            logger.log("Invoked: " + invoked.get() + " times (overall) [Method: " + method + " ]");
+        } else if (args == null) {
+            logger.log("Invoked: " + invoked.get() + " times (overall) [Method: " + method + ", Target: " + target + "]");
+        } else {
+            logger.log("Invoked: " + invoked.get() + " times (overall) [Method: " + method + ", Target: " + target + ", Arguments: " + obj + " ]");
+        }
     }
 
     @Override
     public ClassInfo cacheClass(Class<?> clazz) {
-        log("cacheClass", clazz);
+        if (logger.shouldLog()) {
+            log("cacheClass", clazz);
+        }
         invoked.incrementAndGet();
         return IntrospectionSupport.cacheClass(clazz);
     }
 
     @Override
-    public boolean getProperties(Object target, Map<String, Object> properties, String optionPrefix) {
-        invoked.incrementAndGet();
+    public void clearCache() {
         if (logger.shouldLog()) {
-            log("getProperties", target);
+            log("clearCache", null);
         }
-        return IntrospectionSupport.getProperties(target, properties, optionPrefix);
     }
 
     @Override
-    public boolean getProperties(Object target, Map<String, Object> properties, String optionPrefix, boolean includeNull) {
+    public boolean getProperties(Object target, Map<String, Object> properties, String optionPrefix) {
         invoked.incrementAndGet();
         if (logger.shouldLog()) {
             log("getProperties", target);
         }
-        return IntrospectionSupport.getProperties(target, properties, optionPrefix, includeNull);
+        return IntrospectionSupport.getProperties(target, properties, optionPrefix);
     }
 
     @Override
-    public Object getOrElseProperty(Object target, String propertyName, Object defaultValue) {
+    public boolean getProperties(Object target, Map<String, Object> properties, String optionPrefix, boolean includeNull) {
         invoked.incrementAndGet();
         if (logger.shouldLog()) {
-            log("getOrElseProperty", target, propertyName);
+            log("getProperties", target);
         }
-        return IntrospectionSupport.getOrElseProperty(target, propertyName, defaultValue);
+        return IntrospectionSupport.getProperties(target, properties, optionPrefix, includeNull);
     }
 
     @Override
@@ -124,15 +130,6 @@ public class DefaultBeanIntrospection extends ServiceSupport implements BeanIntr
     }
 
     @Override
-    public Method getPropertyGetter(Class<?> type, String propertyName) throws NoSuchMethodException {
-        invoked.incrementAndGet();
-        if (logger.shouldLog()) {
-            log("getPropertyGetter", type, propertyName);
-        }
-        return IntrospectionSupport.getPropertyGetter(type, propertyName);
-    }
-
-    @Override
     public Method getPropertyGetter(Class<?> type, String propertyName, boolean ignoreCase) throws NoSuchMethodException {
         invoked.incrementAndGet();
         if (logger.shouldLog()) {
diff --git a/core/camel-management-impl/src/test/java/org/apache/camel/management/ManagedBeanIntrospectionTest.java b/core/camel-management-impl/src/test/java/org/apache/camel/management/ManagedBeanIntrospectionTest.java
index 0ec992b..3e356a8 100644
--- a/core/camel-management-impl/src/test/java/org/apache/camel/management/ManagedBeanIntrospectionTest.java
+++ b/core/camel-management-impl/src/test/java/org/apache/camel/management/ManagedBeanIntrospectionTest.java
@@ -65,7 +65,7 @@ public class ManagedBeanIntrospectionTest extends ManagementTestSupport {
         Long counter = (Long) mbeanServer.getAttribute(on, "InvokedCounter");
         assertEquals("Should not have been invoked", 0, counter.intValue());
 
-        Object dummy = context.adapt(ExtendedCamelContext.class).getBeanIntrospection().getOrElseProperty(this, "dummy", null);
+        Object dummy = context.adapt(ExtendedCamelContext.class).getBeanIntrospection().getOrElseProperty(this, "dummy", null, false);
         assertEquals("MyDummy", dummy);
 
         counter = (Long) mbeanServer.getAttribute(on, "InvokedCounter");
diff --git a/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java b/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java
index 3974bb1..0d70e88 100644
--- a/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java
+++ b/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java
@@ -713,7 +713,7 @@ public final class PropertyBindingSupport {
                     return getter.getReturnType();
                 }
             } else {
-                Method getter = context.adapt(ExtendedCamelContext.class).getBeanIntrospection().getPropertyGetter(target.getClass(), name);
+                Method getter = context.adapt(ExtendedCamelContext.class).getBeanIntrospection().getPropertyGetter(target.getClass(), name, false);
                 if (getter != null) {
                     return getter.getReturnType();
                 }


[camel] 02/02: CAMEL-13907: Lets clear bean introspection cache after bootstrap of Camel as the cache was used during initialization.

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

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

commit 8138706e7498b9e5974ebfa50f177a56de10f4b9
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Sun Aug 25 12:40:46 2019 +0200

    CAMEL-13907: Lets clear bean introspection cache after bootstrap of Camel as the cache was used during initialization.
---
 .../src/main/java/org/apache/camel/spi/BeanIntrospection.java |  5 +++++
 .../org/apache/camel/impl/engine/AbstractCamelContext.java    |  9 +++++++--
 .../apache/camel/impl/engine/DefaultBeanIntrospection.java    |  6 ++++++
 .../api/management/mbean/ManagedBeanIntrospectionMBean.java   |  6 ++++++
 .../camel/management/mbean/ManagedBeanIntrospection.java      | 10 ++++++++++
 .../java/org/apache/camel/support/IntrospectionSupport.java   | 11 +++++++++++
 6 files changed, 45 insertions(+), 2 deletions(-)

diff --git a/core/camel-api/src/main/java/org/apache/camel/spi/BeanIntrospection.java b/core/camel-api/src/main/java/org/apache/camel/spi/BeanIntrospection.java
index 9680037..aad2886 100644
--- a/core/camel-api/src/main/java/org/apache/camel/spi/BeanIntrospection.java
+++ b/core/camel-api/src/main/java/org/apache/camel/spi/BeanIntrospection.java
@@ -135,6 +135,11 @@ public interface BeanIntrospection extends StaticService {
     void clearCache();
 
     /**
+     * Number of classes in the introspection cache.
+     */
+    long getCachedClassesCounter();
+
+    /**
      * Gets the property or else returning the default value.
      *
      * @param target         the target bean
diff --git a/core/camel-base/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java b/core/camel-base/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java
index 43b229c..56eac80 100644
--- a/core/camel-base/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java
+++ b/core/camel-base/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java
@@ -2639,10 +2639,15 @@ public abstract class AbstractCamelContext extends ServiceSupport implements Ext
             log.debug("Skip starting routes as CamelContext has been configured with autoStartup=false");
         }
 
-        // invoke this logic to warmup the routes and if possible also start the
-        // routes
+        // invoke this logic to warmup the routes and if possible also start the routes
         doStartOrResumeRoutes(routeServices, true, !doNotStartRoutesOnFirstStart, false, true);
 
+        long cacheCounter = getBeanIntrospection().getCachedClassesCounter();
+        if (cacheCounter > 0) {
+            log.debug("Clearing BeanIntrospection cache with {} objects using during starting Camel", cacheCounter);
+            getBeanIntrospection().clearCache();
+        }
+
         // starting will continue in the start method
     }
 
diff --git a/core/camel-base/src/main/java/org/apache/camel/impl/engine/DefaultBeanIntrospection.java b/core/camel-base/src/main/java/org/apache/camel/impl/engine/DefaultBeanIntrospection.java
index 2d02c38..383e654 100644
--- a/core/camel-base/src/main/java/org/apache/camel/impl/engine/DefaultBeanIntrospection.java
+++ b/core/camel-base/src/main/java/org/apache/camel/impl/engine/DefaultBeanIntrospection.java
@@ -100,6 +100,12 @@ public class DefaultBeanIntrospection extends ServiceSupport implements BeanIntr
         if (logger.shouldLog()) {
             log("clearCache", null);
         }
+        IntrospectionSupport.clearCache();
+    }
+
+    @Override
+    public long getCachedClassesCounter() {
+        return IntrospectionSupport.getCacheCounter();
     }
 
     @Override
diff --git a/core/camel-management-api/src/main/java/org/apache/camel/api/management/mbean/ManagedBeanIntrospectionMBean.java b/core/camel-management-api/src/main/java/org/apache/camel/api/management/mbean/ManagedBeanIntrospectionMBean.java
index 3cdac97..eb7cddd 100644
--- a/core/camel-management-api/src/main/java/org/apache/camel/api/management/mbean/ManagedBeanIntrospectionMBean.java
+++ b/core/camel-management-api/src/main/java/org/apache/camel/api/management/mbean/ManagedBeanIntrospectionMBean.java
@@ -33,4 +33,10 @@ public interface ManagedBeanIntrospectionMBean extends ManagedServiceMBean {
     @ManagedOperation(description = "Rests the statistic counters")
     void resetCounters();
 
+    @ManagedAttribute(description = "Number of cached introspected bean classes")
+    Long getCachedClasses();
+
+    @ManagedOperation(description = "Clears the cache for introspected bean classes")
+    void clearCache();
+
 }
diff --git a/core/camel-management-impl/src/main/java/org/apache/camel/management/mbean/ManagedBeanIntrospection.java b/core/camel-management-impl/src/main/java/org/apache/camel/management/mbean/ManagedBeanIntrospection.java
index caa235f..8717138 100644
--- a/core/camel-management-impl/src/main/java/org/apache/camel/management/mbean/ManagedBeanIntrospection.java
+++ b/core/camel-management-impl/src/main/java/org/apache/camel/management/mbean/ManagedBeanIntrospection.java
@@ -57,4 +57,14 @@ public class ManagedBeanIntrospection extends ManagedService implements ManagedB
     public void resetCounters() {
         beanIntrospection.resetCounters();
     }
+
+    @Override
+    public Long getCachedClasses() {
+        return beanIntrospection.getCachedClassesCounter();
+    }
+
+    @Override
+    public void clearCache() {
+        beanIntrospection.clearCache();
+    }
 }
diff --git a/core/camel-support/src/main/java/org/apache/camel/support/IntrospectionSupport.java b/core/camel-support/src/main/java/org/apache/camel/support/IntrospectionSupport.java
index 9ae6457..5cfed94 100644
--- a/core/camel-support/src/main/java/org/apache/camel/support/IntrospectionSupport.java
+++ b/core/camel-support/src/main/java/org/apache/camel/support/IntrospectionSupport.java
@@ -114,6 +114,13 @@ public final class IntrospectionSupport {
      * This implementation will clear its introspection cache.
      */
     public static void stop() {
+        clearCache();
+    }
+
+    /**
+     * Clears the introspection cache.
+     */
+    public static void clearCache() {
         if (LOG.isDebugEnabled() && CACHE instanceof LRUCache) {
             LRUCache localCache = (LRUCache) IntrospectionSupport.CACHE;
             LOG.debug("Clearing cache[size={}, hits={}, misses={}, evicted={}]", localCache.size(), localCache.getHits(), localCache.getMisses(), localCache.getEvicted());
@@ -121,6 +128,10 @@ public final class IntrospectionSupport {
         CACHE.clear();
     }
 
+    public static long getCacheCounter() {
+        return CACHE.size();
+    }
+
     public static boolean isGetter(Method method) {
         String name = method.getName();
         Class<?> type = method.getReturnType();