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:12 UTC
[camel] 02/02: CAMEL-13907: Lets clear bean introspection cache
after bootstrap of Camel as the cache was used during initialization.
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();