[dependency-shot] r393 committed - Add event broadcast on singleton scope

0 views
Skip to first unread message

depende...@googlecode.com

unread,
Mar 17, 2011, 3:52:27 PM3/17/11
to depende...@googlegroups.com
Revision: 393
Author: mathieu.ancelin
Date: Thu Mar 17 12:22:40 2011
Log: Add event broadcast on singleton scope
http://code.google.com/p/dependency-shot/source/detail?r=393

Modified:

/trunk/dependency-shot-core/src/main/java/cx/ath/mancel01/dependencyshot/scope/SingletonScope.java

=======================================
---
/trunk/dependency-shot-core/src/main/java/cx/ath/mancel01/dependencyshot/scope/SingletonScope.java
Tue Feb 22 13:21:54 2011
+++
/trunk/dependency-shot-core/src/main/java/cx/ath/mancel01/dependencyshot/scope/SingletonScope.java
Thu Mar 17 12:22:40 2011
@@ -18,6 +18,9 @@
package cx.ath.mancel01.dependencyshot.scope;

import cx.ath.mancel01.dependencyshot.api.InjectionPoint;
+import cx.ath.mancel01.dependencyshot.api.event.EventManager;
+import cx.ath.mancel01.dependencyshot.event.InjectionStartedEvent;
+import cx.ath.mancel01.dependencyshot.event.InjectionStoppedEvent;
import cx.ath.mancel01.dependencyshot.injection.InjectorImpl;
import cx.ath.mancel01.dependencyshot.spi.CustomScopeHandler;
import java.lang.annotation.Annotation;
@@ -36,6 +39,8 @@
*/
private Map<Class<?>, Object> singletonContext;

+ private EventManager eventManager;
+
public SingletonScope() {
singletonContext = new HashMap<Class<?>, Object>();
}
@@ -48,12 +53,24 @@
@Override
public <T> T getScopedInstance(Class<T> interf, Class<? extends T>
clazz,
InjectionPoint p, InjectorImpl injector) {
+ if (eventManager == null) {
+ eventManager = injector.getInstance(EventManager.class);
+ }
// check if the singleton is present in the singleton context
T result = clazz.cast(singletonContext.get(clazz));
// if not, create one
if (result == null) {
+ InjectionStartedEvent start = new InjectionStartedEvent();
+ InjectionStoppedEvent stop = new InjectionStoppedEvent();
+ start.setBeanType(interf);
+ stop.setBeanType(interf);
+ eventManager.fireAsyncEvent(start);
+
result = injector.createInstance(clazz);
singletonContext.put(clazz, result);
+
+ stop.setBeanInstance(result);
+ eventManager.fireAsyncEvent(stop);
}
return result;
}

Reply all
Reply to author
Forward
0 new messages