Commit a2538005f103c1ff771d8e363664f4a317e2d597
1 parent
f0b8315f
Exists in
master
Alterações no cache de proxy do ConfiguartionBootstrap
Showing
1 changed file
with
22 additions
and
23 deletions
Show diff stats
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/ConfigurationBootstrap.java
... | ... | @@ -62,8 +62,9 @@ public class ConfigurationBootstrap implements Extension { |
62 | 62 | |
63 | 63 | private final List<Class<Object>> cache = Collections.synchronizedList(new ArrayList<Class<Object>>()); |
64 | 64 | |
65 | - private static final Map<ClassLoader, List<String>> cacheClassLoader = Collections.synchronizedMap(new HashMap<ClassLoader, List<String>>()); | |
66 | - | |
65 | + private static final Map<ClassLoader, Map<String, Class<Object>>> cacheClassLoader = Collections | |
66 | + .synchronizedMap(new HashMap<ClassLoader, Map<String, Class<Object>>>()); | |
67 | + | |
67 | 68 | public void processAnnotatedType(@Observes final ProcessAnnotatedType<Object> event) { |
68 | 69 | final AnnotatedType<Object> annotatedType = event.getAnnotatedType(); |
69 | 70 | |
... | ... | @@ -78,9 +79,7 @@ public class ConfigurationBootstrap implements Extension { |
78 | 79 | |
79 | 80 | for (Class<Object> config : cache) { |
80 | 81 | proxy = createProxy(config); |
81 | - if (proxy != null) { | |
82 | - event.addBean(new CustomBean(proxy, beanManager)); | |
83 | - } | |
82 | + event.addBean(new CustomBean(proxy, beanManager)); | |
84 | 83 | } |
85 | 84 | } |
86 | 85 | |
... | ... | @@ -89,24 +88,20 @@ public class ConfigurationBootstrap implements Extension { |
89 | 88 | String superClassName = type.getCanonicalName(); |
90 | 89 | String chieldClassName = superClassName + "__DemoiselleProxy"; |
91 | 90 | |
92 | - Class<Object> clazz = null; | |
93 | - | |
94 | - Boolean loaded = true; | |
91 | + Map<String, Class<Object>> cacheProxy = Collections.synchronizedMap(new HashMap<String, Class<Object>>());; | |
92 | + | |
93 | + Class<Object> clazzProxy = null; | |
94 | + | |
95 | 95 | ClassLoader classLoader = type.getClassLoader(); |
96 | - if (cacheClassLoader.containsKey(classLoader)) { | |
97 | - if (!cacheClassLoader.get(classLoader).contains(chieldClassName)) { | |
98 | - loaded = false; | |
96 | + if (cacheClassLoader.containsKey(classLoader)) { | |
97 | + cacheProxy = cacheClassLoader.get(classLoader); | |
98 | + if (cacheProxy.containsKey(chieldClassName)) { | |
99 | + clazzProxy = cacheProxy.get(chieldClassName); | |
99 | 100 | } |
100 | 101 | } |
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 | - | |
102 | + | |
103 | + if (clazzProxy == null) { | |
104 | + | |
110 | 105 | ClassPool pool = new ClassPool(); |
111 | 106 | CtClass ctChieldClass = pool.getOrNull(chieldClassName); |
112 | 107 | |
... | ... | @@ -123,9 +118,13 @@ public class ConfigurationBootstrap implements Extension { |
123 | 118 | |
124 | 119 | ctChieldClass.addMethod(ctChieldMethod); |
125 | 120 | } |
126 | - clazz = ctChieldClass.toClass(classLoader, type.getProtectionDomain()); | |
121 | + | |
122 | + clazzProxy = ctChieldClass.toClass(classLoader, type.getProtectionDomain()); | |
123 | + | |
124 | + cacheProxy.put(chieldClassName, clazzProxy); | |
125 | + cacheClassLoader.put(classLoader, cacheProxy); | |
127 | 126 | } |
128 | 127 | |
129 | - return clazz; | |
130 | - } | |
128 | + return clazzProxy; | |
129 | + } | |
131 | 130 | } | ... | ... |