You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by gg...@apache.org on 2020/05/14 12:56:41 UTC
[camel-karaf] 01/01: [CAMEL-15061] Cache failed attempts to load
classes to greatly improve performance
This is an automated email from the ASF dual-hosted git repository.
ggrzybek pushed a commit to branch CAMEL-15061-3.4.x
in repository https://gitbox.apache.org/repos/asf/camel-karaf.git
commit f0f5863d0029ef0f9b893075982fa1fa8e692132
Author: Grzegorz Grzybek <gr...@gmail.com>
AuthorDate: Thu May 14 14:50:19 2020 +0200
[CAMEL-15061] Cache failed attempts to load classes to greatly improve performance
---
.../blueprint/BlueprintContainerBeanRepository.java | 17 ++++++++++++++++-
1 file changed, 16 insertions(+), 1 deletion(-)
diff --git a/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/BlueprintContainerBeanRepository.java b/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/BlueprintContainerBeanRepository.java
index 8c32a62..2028f4f 100644
--- a/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/BlueprintContainerBeanRepository.java
+++ b/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/BlueprintContainerBeanRepository.java
@@ -16,10 +16,12 @@
*/
package org.apache.camel.blueprint;
+import java.util.Collection;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
import org.apache.camel.NoSuchBeanException;
import org.apache.camel.spi.BeanRepository;
@@ -34,6 +36,8 @@ public class BlueprintContainerBeanRepository implements BeanRepository {
private final BlueprintContainer blueprintContainer;
+ private final Map<Class<?>, Map<String, Class<?>>> perBlueprintContainerCache = new ConcurrentHashMap<>();
+
public BlueprintContainerBeanRepository(BlueprintContainer blueprintContainer) {
this.blueprintContainer = blueprintContainer;
}
@@ -71,13 +75,24 @@ public class BlueprintContainerBeanRepository implements BeanRepository {
}
@Override
+ @SuppressWarnings("unchecked")
public <T> Map<String, T> findByTypeWithName(Class<T> type) {
- return lookupByType(blueprintContainer, type);
+ if (perBlueprintContainerCache.containsKey(type)) {
+ return (Map<String, T>) perBlueprintContainerCache.get(type);
+ }
+ Map<String, T> result = lookupByType(blueprintContainer, type);
+ perBlueprintContainerCache.put(type, (Map<String, Class<?>>) result);
+ return result;
}
@Override
+ @SuppressWarnings("unchecked")
public <T> Set<T> findByType(Class<T> type) {
+ if (perBlueprintContainerCache.containsKey(type)) {
+ return new HashSet<T>((Collection<? extends T>) perBlueprintContainerCache.get(type).values());
+ }
Map<String, T> map = lookupByType(blueprintContainer, type);
+ perBlueprintContainerCache.put(type, (Map<String, Class<?>>) map);
return new HashSet<>(map.values());
}