Commit 59dfafdaf4f0f8d557d8e834c0fae78c9e596501
1 parent
f2d5c422
Exists in
master
Criação de cache para proxy por classloader
Showing
1 changed file
with
30 additions
and
7 deletions
Show diff stats
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/ConfigurationBootstrap.java
| ... | ... | @@ -38,7 +38,9 @@ package br.gov.frameworkdemoiselle.internal.bootstrap; |
| 38 | 38 | |
| 39 | 39 | import java.util.ArrayList; |
| 40 | 40 | import java.util.Collections; |
| 41 | +import java.util.HashMap; | |
| 41 | 42 | import java.util.List; |
| 43 | +import java.util.Map; | |
| 42 | 44 | |
| 43 | 45 | import javassist.ClassPool; |
| 44 | 46 | import javassist.CtClass; |
| ... | ... | @@ -60,6 +62,8 @@ public class ConfigurationBootstrap implements Extension { |
| 60 | 62 | |
| 61 | 63 | private final List<Class<Object>> cache = Collections.synchronizedList(new ArrayList<Class<Object>>()); |
| 62 | 64 | |
| 65 | + private static final Map<ClassLoader, List<String>> cacheClassLoader = Collections.synchronizedMap(new HashMap<ClassLoader, List<String>>()); | |
| 66 | + | |
| 63 | 67 | public void processAnnotatedType(@Observes final ProcessAnnotatedType<Object> event) { |
| 64 | 68 | final AnnotatedType<Object> annotatedType = event.getAnnotatedType(); |
| 65 | 69 | |
| ... | ... | @@ -74,7 +78,9 @@ public class ConfigurationBootstrap implements Extension { |
| 74 | 78 | |
| 75 | 79 | for (Class<Object> config : cache) { |
| 76 | 80 | proxy = createProxy(config); |
| 77 | - event.addBean(new CustomBean(proxy, beanManager)); | |
| 81 | + if (proxy != null) { | |
| 82 | + event.addBean(new CustomBean(proxy, beanManager)); | |
| 83 | + } | |
| 78 | 84 | } |
| 79 | 85 | } |
| 80 | 86 | |
| ... | ... | @@ -83,11 +89,27 @@ public class ConfigurationBootstrap implements Extension { |
| 83 | 89 | String superClassName = type.getCanonicalName(); |
| 84 | 90 | String chieldClassName = superClassName + "__DemoiselleProxy"; |
| 85 | 91 | |
| 86 | - ClassPool pool = ClassPool.getDefault(); | |
| 87 | - CtClass ctChieldClass = pool.getOrNull(chieldClassName); | |
| 88 | - | |
| 92 | + Class<Object> clazz = null; | |
| 93 | + | |
| 94 | + Boolean loaded = true; | |
| 89 | 95 | ClassLoader classLoader = type.getClassLoader(); |
| 90 | - if (ctChieldClass == null) { | |
| 96 | + if (cacheClassLoader.containsKey(classLoader)) { | |
| 97 | + if (!cacheClassLoader.get(classLoader).contains(chieldClassName)) { | |
| 98 | + loaded = false; | |
| 99 | + } | |
| 100 | + } | |
| 101 | + else{ | |
| 102 | + List<String> strings = Collections.synchronizedList(new ArrayList<String>()); | |
| 103 | + cacheClassLoader.put(classLoader, strings); | |
| 104 | + loaded = false; | |
| 105 | + } | |
| 106 | + | |
| 107 | + if (!loaded){ | |
| 108 | + cacheClassLoader.get(classLoader).add(chieldClassName); | |
| 109 | + | |
| 110 | + ClassPool pool = new ClassPool(); | |
| 111 | + CtClass ctChieldClass = pool.getOrNull(chieldClassName); | |
| 112 | + | |
| 91 | 113 | pool.appendClassPath(new LoaderClassPath(classLoader)); |
| 92 | 114 | CtClass ctSuperClass = pool.get(superClassName); |
| 93 | 115 | |
| ... | ... | @@ -101,8 +123,9 @@ public class ConfigurationBootstrap implements Extension { |
| 101 | 123 | |
| 102 | 124 | ctChieldClass.addMethod(ctChieldMethod); |
| 103 | 125 | } |
| 126 | + clazz = ctChieldClass.toClass(classLoader, type.getProtectionDomain()); | |
| 104 | 127 | } |
| 105 | 128 | |
| 106 | - return ctChieldClass.toClass(classLoader, type.getProtectionDomain()); | |
| 107 | - } | |
| 129 | + return clazz; | |
| 130 | + } | |
| 108 | 131 | } | ... | ... |