[jboss-cvs] JBossAS SVN: r69272 - in projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors: container and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Jan 24 05:37:04 EST 2008


Author: wolfc
Date: 2008-01-24 05:37:04 -0500 (Thu, 24 Jan 2008)
New Revision: 69272

Added:
   projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/aop/NopInterceptor.java
Modified:
   projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/aop/AbstractInterceptorFactory.java
   projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/aop/InjectInterceptorsFactory.java
   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/ManagedObjectAdvisor.java
Log:
Decoupled postConstruct and fixed WEIRDNESS IN AOP

Modified: projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/aop/AbstractInterceptorFactory.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/aop/AbstractInterceptorFactory.java	2008-01-24 10:04:17 UTC (rev 69271)
+++ projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/aop/AbstractInterceptorFactory.java	2008-01-24 10:37:04 UTC (rev 69272)
@@ -51,7 +51,7 @@
 
    public Object createPerJoinpoint(Advisor advisor, InstanceAdvisor instanceAdvisor, Joinpoint jp)
    {
-      throw new IllegalStateException("Per joinpoint instance scope not supported");
+      throw new IllegalStateException("Per joinpoint instance scope not supported on " + this);
    }
 
    public Object createPerVM()

Modified: projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/aop/InjectInterceptorsFactory.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/aop/InjectInterceptorsFactory.java	2008-01-24 10:04:17 UTC (rev 69271)
+++ projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/aop/InjectInterceptorsFactory.java	2008-01-24 10:37:04 UTC (rev 69272)
@@ -26,6 +26,7 @@
 import java.util.Collection;
 import java.util.List;
 
+import javax.annotation.PostConstruct;
 import javax.interceptor.ExcludeClassInterceptors;
 import javax.interceptor.ExcludeDefaultInterceptors;
 
@@ -103,9 +104,11 @@
       {
          // postConstruct
          
-         // FIXME: currently still handled by InterceptorsFactory
+         List<Interceptor> interceptors = InterceptorsFactory.getLifeCycleInterceptors(instanceAdvisor, PostConstruct.class);
          
-         return new InterceptorSequencer(new Interceptor[0]);
+         log.debug("PostConstruct interceptors " + interceptors);
+         
+         return new InterceptorSequencer(interceptors);
       }
    }
    
@@ -114,6 +117,13 @@
    {
       log.warn("WEIRDNESS IN AOP: advisor " + advisor);
       return new InterceptorSequencer(new Interceptor[0]);
+      // If we're not running instrumented classes there is no instance advisor during
+      // construction. (I've no clue why.)
+      // Luckily our advisor is on the case.
+//      InstanceAdvisor instanceAdvisor = (InstanceAdvisor) advisor;
+//      return createPerJoinpoint(advisor, instanceAdvisor, jp);
+      // Can't do that, because the instance interceptors are not there yet (InterceptorsFactory)
+      // so the hack is in ManagedObjectAdvisor.createInterceptorChain.
    }
    
    private static final boolean isExcludeClassInterceptors(Advisor advisor, Method method)

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-24 10:04:17 UTC (rev 69271)
+++ projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/aop/InterceptorsFactory.java	2008-01-24 10:37:04 UTC (rev 69272)
@@ -205,12 +205,10 @@
          log.debug("Found bean interceptors " + beanInterceptors);
          instanceAdvisor.getMetaData().addMetaData(InterceptorsFactory.class, "beanInterceptors", beanInterceptors);
          
+         log.debug("Found life cycle interceptors " + lifeCycleInterceptors);
          instanceAdvisor.getMetaData().addMetaData(InterceptorsFactory.class, "lifeCycleInterceptors", Collections.unmodifiableMap(lifeCycleInterceptors));
          
-         // Put the postConstructs interceptors here in the chain
-         // TODO: why? We may need more control
-         return new InterceptorSequencer(lifeCycleInterceptors.get(PostConstruct.class).toArray(new Interceptor[0]));
-         //return null;
+         return new NopInterceptor();
       }
       catch(InstantiationException e)
       {

Added: projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/aop/NopInterceptor.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/aop/NopInterceptor.java	                        (rev 0)
+++ projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/aop/NopInterceptor.java	2008-01-24 10:37:04 UTC (rev 69272)
@@ -0,0 +1,47 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2007, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.interceptors.aop;
+
+import org.jboss.aop.advice.Interceptor;
+import org.jboss.aop.joinpoint.Invocation;
+import org.jboss.logging.Logger;
+
+/**
+ * Does nothing.
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class NopInterceptor implements Interceptor
+{
+   private static final Logger log = Logger.getLogger(NopInterceptor.class);
+
+   public String getName()
+   {
+      return getClass().getName();
+   }
+
+   public Object invoke(Invocation invocation) throws Throwable
+   {
+      return invocation.invokeNext();
+   }
+}


Property changes on: projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/aop/NopInterceptor.java
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Modified: projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/container/ManagedObjectAdvisor.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/container/ManagedObjectAdvisor.java	2008-01-24 10:04:17 UTC (rev 69271)
+++ projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/container/ManagedObjectAdvisor.java	2008-01-24 10:37:04 UTC (rev 69272)
@@ -24,6 +24,7 @@
 import java.lang.annotation.Annotation;
 import java.lang.reflect.AnnotatedElement;
 import java.lang.reflect.Member;
+import java.util.ArrayList;
 import java.util.List;
 
 import org.jboss.aop.AspectManager;
@@ -33,8 +34,11 @@
 import org.jboss.aop.InstanceAdvisorDelegate;
 import org.jboss.aop.advice.AspectDefinition;
 import org.jboss.aop.advice.Interceptor;
+import org.jboss.aop.advice.InterceptorFactory;
+import org.jboss.aop.advice.Scope;
 import org.jboss.aop.annotation.AnnotationRepository;
 import org.jboss.aop.introduction.AnnotationIntroduction;
+import org.jboss.aop.joinpoint.ConstructorJoinpoint;
 import org.jboss.aop.joinpoint.Joinpoint;
 import org.jboss.aop.metadata.SimpleMetaData;
 import org.jboss.ejb3.interceptors.ManagedObject;
@@ -43,7 +47,9 @@
 import org.jboss.logging.Logger;
 
 /**
- * Comment
+ * 
+ * Invariant:
+ * - there is always an instance advisor delegate
  *
  * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
  * @version $Revision: $
@@ -89,6 +95,30 @@
       annotations.addClassAnnotation(ManagedObject.class, annotation);
    }
    
+   @Override
+   protected void createInterceptorChain(InterceptorFactory[] factories, ArrayList newinterceptors, Joinpoint joinpoint)
+   {
+      // This is an ugly hack to make sure we have got an PER_JOINPOINT_INSTANCE interceptor.
+      // Normally AOP won't create a per joinpoint instance interceptor if the join point is
+      // a constructor and we're not running instrument (I've no clue why).
+      
+      if(joinpoint instanceof ConstructorJoinpoint)
+      {
+         for(InterceptorFactory factory : factories)
+         {
+            AspectDefinition def = factory.getAspect();
+            if(def.getScope() == Scope.PER_JOINPOINT)
+            {
+               //addPerInstanceJoinpointAspect(joinpoint, def);
+               newinterceptors.add(def.getFactory().createPerJoinpoint(this, this, joinpoint));
+               return;
+            }
+         }
+      }
+      
+      super.createInterceptorChain(factories, newinterceptors, joinpoint);
+   }
+   
    private void deployAnnotationIntroduction(AnnotationIntroduction introduction)
    {
       log.debug("deploy annotation introduction " + introduction);
@@ -120,8 +150,6 @@
       
       // Poking starts here
       attachClass(beanClass);
-      
-      this.instanceAdvisorDelegate = new InstanceAdvisorDelegate(this, this);
    }
    
    @Override
@@ -133,7 +161,29 @@
       deployAnnotationIntroductions();
    }
    
+   /**
+    * attachClass will want simpleMetaData at some point, which needs
+    * an instanceAdvisorDelegate. So we have detached construction.
+    * 
+    * @return the instance advisor delegate, never null
+    */
+   private final InstanceAdvisorDelegate getInstanceAdvisorDelegate()
+   {
+      if(instanceAdvisorDelegate != null)
+         return instanceAdvisorDelegate;
+
+      synchronized (this)
+      {
+         if(instanceAdvisorDelegate == null)
+         {
+            instanceAdvisorDelegate = new InstanceAdvisorDelegate(this, this);
+            instanceAdvisorDelegate.initialize();
+         }
+      }
+      return instanceAdvisorDelegate;
+   }
    
+   
    public void appendInterceptor(Interceptor interceptor)
    {
       throw new RuntimeException("NYI");
@@ -171,23 +221,23 @@
 
    public SimpleMetaData getMetaData()
    {
-      return instanceAdvisorDelegate.getMetaData();
+      return getInstanceAdvisorDelegate().getMetaData();
    }
 
    public Object getPerInstanceAspect(String aspectName)
    {
       // TODO: is this correct?
-      return instanceAdvisorDelegate.getPerInstanceAspect(aspectName);
+      return getInstanceAdvisorDelegate().getPerInstanceAspect(aspectName);
    }
 
    public Object getPerInstanceAspect(AspectDefinition def)
    {
-      return instanceAdvisorDelegate.getPerInstanceAspect(def);
+      return getInstanceAdvisorDelegate().getPerInstanceAspect(def);
    }
 
    public Object getPerInstanceJoinpointAspect(Joinpoint joinpoint, AspectDefinition def)
    {
-      return instanceAdvisorDelegate.getPerInstanceJoinpointAspect(joinpoint, def);
+      return getInstanceAdvisorDelegate().getPerInstanceJoinpointAspect(joinpoint, def);
    }
 
    public boolean hasInterceptors()




More information about the jboss-cvs-commits mailing list