This is an automated email from the ASF dual-hosted git repository.
ggrzybek pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-karaf.git
The following commit(s) were added to refs/heads/master by this push:
new 10c8987 [CAMEL-15061] Cache failed attempts to load classes to
greatly improve performance (#8)
10c8987 is described below
commit 10c898715aaaded9f7d9f072b7ce8c827a74deb7
Author: Grzegorz Grzybek <[email protected]>
AuthorDate: Thu May 14 16:29:44 2020 +0200
[CAMEL-15061] Cache failed attempts to load classes to greatly improve
performance (#8)
---
.../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());
}