MentaContainer

Compare Revisions

Ignore whitespace Rev 63 → Rev 64

/trunk/src/main/java/org/mentacontainer/impl/MentaContainer.java
6,6 → 6,7
import java.util.Map;
import java.util.Set;
 
import org.mentacontainer.Clearable;
import org.mentacontainer.Component;
import org.mentacontainer.ConfigurableComponent;
import org.mentacontainer.Container;
35,10 → 36,40
if (scope == Scope.SINGLETON) {
for(String key : singletonsCache.keySet()) {
Component comp = beans.get(key);
if (comp instanceof Clearable) {
Clearable<Object> c = (Clearable<Object>) comp;
Object value = singletonsCache.get(key);
c.onCleared(value);
}
}
singletonsCache.clear();
} else if (scope == Scope.THREAD) {
for(String key : threadLocalsCache.keySet()) {
Component comp = beans.get(key);
if (comp instanceof Clearable) {
Clearable<Object> c = (Clearable<Object>) comp;
ThreadLocal<Object> t = threadLocalsCache.get(key);
Object value = t.get();
if (value != null) c.onCleared(value);
}
}
for(ThreadLocal<Object> t : threadLocalsCache.values()) {
t.set(null);
54,8 → 85,22
if (scope == Scope.SINGLETON) {
return (T) singletonsCache.remove(key);
Object value = singletonsCache.remove(key);
if (value != null) {
Component comp = beans.get(key);
if (comp instanceof Clearable) {
Clearable<Object> c = (Clearable<Object>) comp;
c.onCleared(value);
}
}
return (T) value;
} else if (scope == Scope.THREAD) {
ThreadLocal<Object> t = threadLocalsCache.get(key);
66,6 → 111,15
if (o != null) {
Component comp = beans.get(key);
if (comp instanceof Clearable) {
Clearable<Object> c = (Clearable<Object>) comp;
c.onCleared(o);
}
t.set(null);
return (T) o;