Commit 3ba5b60a9f3a364f2ecd27cb2248dbf879e51ac5

Authored by Dancovich
1 parent 15dffee5
Exists in master

Regressão de solução para contextos não serializáveis, até encontrar

forma de identificar unicamente classloaders.
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/AbstractCustomContext.java
... ... @@ -36,7 +36,6 @@
36 36 */
37 37 package br.gov.frameworkdemoiselle.internal.context;
38 38  
39   -import java.io.Serializable;
40 39 import java.lang.annotation.Annotation;
41 40 import java.util.Collections;
42 41 import java.util.HashMap;
... ... @@ -194,40 +193,38 @@ public abstract class AbstractCustomContext implements CustomContext {
194 193 return true;
195 194 }
196 195  
197   - static class Store implements Serializable {
  196 + static class Store {
198 197  
199   - private static final long serialVersionUID = -8237464177510563034L;
200   -
201   - private final String SEPARATOR = "#";
202   -
203   - private Map<String, Object> cache = Collections.synchronizedMap(new HashMap<String, Object>());
  198 + private Map<ClassLoader, Map<Class<?>, Object>> cache = Collections
  199 + .synchronizedMap(new HashMap<ClassLoader, Map<Class<?>, Object>>());
  200 +
  201 + private Store() {
  202 + }
204 203  
205 204 private boolean contains(final Class<?> type) {
206   - return cache.containsKey( prefixId(type) );
  205 + return this.getMap().containsKey(type);
207 206 }
208 207  
209 208 private Object get(final Class<?> type) {
210   - return cache.get( prefixId(type) );
  209 + return this.getMap().get(type);
211 210 }
212 211  
213 212 private void put(final Class<?> type, final Object instance) {
214   - cache.put( prefixId(type) , instance);
  213 + this.getMap().put(type, instance);
215 214 }
216 215  
217 216 public void clear() {
218 217 cache.clear();
219 218 }
220   -
221   - private String prefixId(Class<?> type){
222   - return Thread.currentThread().getContextClassLoader().toString() + SEPARATOR + type.getCanonicalName();
223   - }
224 219  
225   - /*private Map<String, Object> getMap() {
  220 + private Map<Class<?>, Object> getMap() {
  221 + ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
  222 +
226 223 if (!cache.containsKey(classLoader)) {
227 224 cache.put(classLoader, Collections.synchronizedMap(new HashMap<Class<?>, Object>()));
228 225 }
229 226  
230 227 return cache.get(classLoader);
231   - }*/
  228 + }
232 229 }
233 230 }
... ...