[jboss-cvs] JBossAS SVN: r69210 - in projects/ejb3/trunk/interceptors/src: main/java/org/jboss/ejb3/interceptors/container and 2 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Jan 22 14:37:21 EST 2008
Author: wolfc
Date: 2008-01-22 14:37:21 -0500 (Tue, 22 Jan 2008)
New Revision: 69210
Modified:
projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/aop/InterceptorsFactory.java
projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/container/AbstractContainer.java
projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/direct/AbstractDirectContainer.java
projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/metadata/unit/MetadataTestCase.java
Log:
Implemented PreDestroy
Modified: projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/aop/InterceptorsFactory.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/aop/InterceptorsFactory.java 2008-01-22 18:26:25 UTC (rev 69209)
+++ projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/aop/InterceptorsFactory.java 2008-01-22 19:37:21 UTC (rev 69210)
@@ -23,11 +23,13 @@
import java.lang.reflect.Method;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
import javax.interceptor.AroundInvoke;
import javax.interceptor.Interceptors;
@@ -46,13 +48,13 @@
* Comment
*
* @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
- * @version $Revision: $
+ * @version $Revision$
*/
public class InterceptorsFactory extends AbstractInterceptorFactory
{
private static final Logger log = Logger.getLogger(InterceptorsFactory.class);
- private List<? extends Interceptor> createInterceptors(Advisor advisor, InterceptorFactory interceptorFactory, Class<?>[] interceptorClasses, List<BusinessMethodInterceptorMethodInterceptor> interceptors, Map<Class<?>, Object> existingInterceptors, List<LifecycleCallbackInterceptorMethodInterceptor> postConstructs) throws InstantiationException, IllegalAccessException
+ private List<? extends Interceptor> createInterceptors(Advisor advisor, InterceptorFactory interceptorFactory, Class<?>[] interceptorClasses, List<BusinessMethodInterceptorMethodInterceptor> interceptors, Map<Class<?>, Object> existingInterceptors, List<LifecycleCallbackInterceptorMethodInterceptor> postConstructs, List<LifecycleCallbackInterceptorMethodInterceptor> preDestroys) throws InstantiationException, IllegalAccessException
{
if(interceptorClasses != null)
{
@@ -77,6 +79,10 @@
{
postConstructs.add(new LifecycleCallbackInterceptorMethodInterceptor(interceptor, method));
}
+ if(interceptorAdvisor.isAnnotationPresent(interceptorClass, method, PreDestroy.class))
+ {
+ preDestroys.add(new LifecycleCallbackInterceptorMethodInterceptor(interceptor, method));
+ }
if(interceptorAdvisor.isAnnotationPresent(interceptorClass, method, AroundInvoke.class))
{
interceptors.add(new BusinessMethodInterceptorMethodInterceptor(interceptor, method));
@@ -107,11 +113,12 @@
Map<Class<?>, Object> interceptors = new HashMap<Class<?>, Object>();
List<LifecycleCallbackInterceptorMethodInterceptor> postConstructs = new ArrayList<LifecycleCallbackInterceptorMethodInterceptor>();
+ List<LifecycleCallbackInterceptorMethodInterceptor> preDestroys = new ArrayList<LifecycleCallbackInterceptorMethodInterceptor>();
DefaultInterceptors defaultInterceptorsAnnotation = (DefaultInterceptors) advisor.resolveAnnotation(DefaultInterceptors.class);
List<BusinessMethodInterceptorMethodInterceptor> defaultInterceptors = new ArrayList<BusinessMethodInterceptorMethodInterceptor>();
if(defaultInterceptorsAnnotation != null)
- createInterceptors(advisor, interceptorFactory, defaultInterceptorsAnnotation.value(), defaultInterceptors, interceptors, postConstructs);
+ createInterceptors(advisor, interceptorFactory, defaultInterceptorsAnnotation.value(), defaultInterceptors, interceptors, postConstructs, preDestroys);
log.debug("Found class interceptors " + defaultInterceptors);
// Default Interceptors
@@ -120,7 +127,7 @@
Interceptors interceptorsAnnotation = (Interceptors) advisor.resolveAnnotation(Interceptors.class);
List<BusinessMethodInterceptorMethodInterceptor> classInterceptors = new ArrayList<BusinessMethodInterceptorMethodInterceptor>();
if(interceptorsAnnotation != null)
- createInterceptors(advisor, interceptorFactory, interceptorsAnnotation.value(), classInterceptors, interceptors, postConstructs);
+ createInterceptors(advisor, interceptorFactory, interceptorsAnnotation.value(), classInterceptors, interceptors, postConstructs, preDestroys);
log.debug("Found class interceptors " + classInterceptors);
// Class Interceptors
@@ -171,6 +178,8 @@
log.debug("Found bean interceptors " + beanInterceptors);
instanceAdvisor.getMetaData().addMetaData(InterceptorsFactory.class, "beanInterceptors", beanInterceptors);
+ instanceAdvisor.getMetaData().addMetaData(InterceptorsFactory.class, "preDestroys", Collections.unmodifiableList(preDestroys));
+
// Put the postConstructs interceptors here in the chain
// TODO: why? We may need more control
return new InterceptorSequencer(postConstructs.toArray(new Interceptor[0]));
@@ -231,6 +240,12 @@
return (List<Interceptor>) instanceAdvisor.getMetaData().getMetaData(InterceptorsFactory.class, "defaultInterceptors");
}
+ @SuppressWarnings("unchecked")
+ public static List<Interceptor> getPreDestroys(InstanceAdvisor instanceAdvisor)
+ {
+ return (List<Interceptor>) instanceAdvisor.getMetaData().getMetaData(InterceptorsFactory.class, "preDestroys");
+ }
+
private String toString(Object obj)
{
return obj.getClass().getName() + "@" + System.identityHashCode(obj);
Modified: projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/container/AbstractContainer.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/container/AbstractContainer.java 2008-01-22 18:26:25 UTC (rev 69209)
+++ projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/container/AbstractContainer.java 2008-01-22 19:37:21 UTC (rev 69210)
@@ -23,6 +23,8 @@
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.List;
import org.jboss.aop.Advisor;
import org.jboss.aop.AspectManager;
@@ -30,6 +32,7 @@
import org.jboss.aop.DomainDefinition;
import org.jboss.aop.MethodInfo;
import org.jboss.aop.advice.Interceptor;
+import org.jboss.aop.advice.PerVmAdvice;
import org.jboss.aop.annotation.AnnotationRepository;
import org.jboss.aop.joinpoint.ConstructionInvocation;
import org.jboss.aop.joinpoint.MethodInvocation;
@@ -37,6 +40,8 @@
import org.jboss.ejb3.interceptors.InterceptorFactoryRef;
import org.jboss.ejb3.interceptors.annotation.AnnotationAdvisor;
import org.jboss.ejb3.interceptors.annotation.AnnotationAdvisorSupport;
+import org.jboss.ejb3.interceptors.aop.InterceptorsFactory;
+import org.jboss.ejb3.interceptors.aop.InvocationContextInterceptor;
import org.jboss.ejb3.interceptors.lang.ClassHelper;
import org.jboss.logging.Logger;
@@ -47,7 +52,7 @@
* Note that it's up to the actual implementation to expose any methods.
*
* @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
- * @version $Revision: $
+ * @version $Revision$
*/
public abstract class AbstractContainer<T, C extends AbstractContainer<T, C>> extends AnnotationAdvisorSupport implements AnnotationAdvisor
{
@@ -105,6 +110,28 @@
return interceptorClass.newInstance();
}
+ protected void destroy(T bean)
+ {
+ try
+ {
+ // TODO: speed up
+ List<Interceptor> interceptors = new ArrayList<Interceptor>(InterceptorsFactory.getPreDestroys(advisor));
+ interceptors.add(0, PerVmAdvice.generateInterceptor(null, new InvocationContextInterceptor(), "setup"));
+
+ DestructionInvocation invocation = new DestructionInvocation(interceptors.toArray(new Interceptor[0]));
+ invocation.setAdvisor(advisor);
+ invocation.setTargetObject(bean);
+ invocation.invokeNext();
+ }
+ catch(Throwable t)
+ {
+ // TODO: disect
+ if(t instanceof RuntimeException)
+ throw (RuntimeException) t;
+ throw new RuntimeException(t);
+ }
+ }
+
/**
* Finalize construction of the abstract container by setting the advisor.
*
Modified: projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/direct/AbstractDirectContainer.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/direct/AbstractDirectContainer.java 2008-01-22 18:26:25 UTC (rev 69209)
+++ projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/direct/AbstractDirectContainer.java 2008-01-22 19:37:21 UTC (rev 69210)
@@ -40,7 +40,7 @@
* classloader and still have control on how instances are called.
*
* @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
- * @version $Revision: $
+ * @version $Revision$
*/
public abstract class AbstractDirectContainer<T, C extends AbstractDirectContainer<T, C>> extends AbstractContainer<T, C>
{
@@ -79,6 +79,12 @@
return targetObject;
}
+ @Override
+ public void destroy(T bean)
+ {
+ super.destroy(bean);
+ }
+
/**
* Do not call, for use in indirect container implementations.
* @return
Modified: projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/metadata/unit/MetadataTestCase.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/metadata/unit/MetadataTestCase.java 2008-01-22 18:26:25 UTC (rev 69209)
+++ projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/metadata/unit/MetadataTestCase.java 2008-01-22 19:37:21 UTC (rev 69210)
@@ -58,7 +58,7 @@
* are routed through the direct container.
*
* @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
- * @version $Revision: $
+ * @version $Revision$
*/
public class MetadataTestCase extends TestCase
{
@@ -164,7 +164,9 @@
// 12.7 footnote 57
assertEquals("DirectMethodInterceptor.postConstruct must not have been called", 0, DirectMethodInterceptor.postConstructs);
- //((Destructable) bean)._preDestroy();
+ container.destroy(bean);
+ assertEquals(1, CommonInterceptor.preDestroys);
+
bean = null;
}
}
More information about the jboss-cvs-commits
mailing list