[jboss-cvs] JBossAS SVN: r69354 - in projects/aop/trunk/aop/src: test/org/jboss/test/aop/container and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Jan 25 13:25:53 EST 2008


Author: kabir.khan at jboss.com
Date: 2008-01-25 13:25:53 -0500 (Fri, 25 Jan 2008)
New Revision: 69354

Added:
   projects/aop/trunk/aop/src/test/org/jboss/test/aop/container/TestContainer.java
Modified:
   projects/aop/trunk/aop/src/main/org/jboss/aop/Advisor.java
   projects/aop/trunk/aop/src/main/org/jboss/aop/AspectManager.java
   projects/aop/trunk/aop/src/main/org/jboss/aop/ClassAdvisor.java
   projects/aop/trunk/aop/src/main/org/jboss/aop/GeneratedClassAdvisor.java
   projects/aop/trunk/aop/src/main/org/jboss/aop/HotSwapStrategy.java
   projects/aop/trunk/aop/src/main/org/jboss/aop/InterceptorChainObserver.java
   projects/aop/trunk/aop/src/main/org/jboss/aop/MethodInterceptors.java
   projects/aop/trunk/aop/src/test/org/jboss/test/aop/container/ContainerTestCase.java
Log:
[JBAOP-517] Enable the Advisor.methodInterceptors field if running on JBoss 4 for backwards compatibility with EJB 3

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/Advisor.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/Advisor.java	2008-01-25 18:24:25 UTC (rev 69353)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/Advisor.java	2008-01-25 18:25:53 UTC (rev 69354)
@@ -150,7 +150,9 @@
    // The method signatures are sorted at transformation and load time to
    // make sure the tables line up.
    //Common sense suggests that this should be lazily initialised for generated advisors, profiling shows that is a major performance hit...
-   /** @deprecated use methodInfos instead */
+   /** @deprecated use methodInfos instead. These remain here for compatibility with EJB 3 in JBoss 4.x. See JBAOP-517
+    * @see AspectManager#maintainAdvisorMethodInterceptors
+    */
    protected TLongObjectHashMap methodInterceptors = new TLongObjectHashMap();
    protected MethodInterceptors methodInfos = new MethodInterceptors(this);;
    protected AspectManager manager;
@@ -963,6 +965,9 @@
    
    protected void finalizeMethodChain()
    {
+      boolean maintain = AspectManager.maintainAdvisorMethodInterceptors;
+      TLongObjectHashMap newMethodInfos = (maintain) ? new TLongObjectHashMap() : null;
+      
       long[] keys = methodInfos.keys();
       for (int i = 0; i < keys.length; i++)
       {
@@ -976,7 +981,13 @@
             interceptors = applyPrecedence(list.toArray(new Interceptor[list.size()]));
          }
          info.setInterceptors(interceptors);
+         
+         if (maintain)
+         {
+            newMethodInfos.put(keys[i], info);
+         }
       }
+      methodInterceptors = newMethodInfos;
    }
 
    public InvocationResponse dynamicInvoke(Object target, Invocation invocation)

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/AspectManager.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/AspectManager.java	2008-01-25 18:24:25 UTC (rev 69353)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/AspectManager.java	2008-01-25 18:25:53 UTC (rev 69354)
@@ -199,6 +199,13 @@
     * logging switch.  We don't use log4j to avoid another heavy library
     */
    public static boolean verbose = false;
+   
+   /**
+    * Whether or not we should maintain the deprecated Advisor.methodInterceptors field
+    * This is required in jboss 4.x for backwards compatibility with EJB 3
+    * See JBAOP-517 
+    */
+   public static boolean maintainAdvisorMethodInterceptors;
 
    /**
     * Get the top level aspect manager
@@ -332,6 +339,8 @@
                {
                   classicOrder = (new Boolean(classic)).booleanValue();
                }
+               
+               maintainAdvisorMethodInterceptors = (new Boolean(System.getProperty("jboss.aop.advisor.methodInterceptors", "false"))).booleanValue();
 
 
                Deployment.deploy();

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/ClassAdvisor.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/ClassAdvisor.java	2008-01-25 18:24:25 UTC (rev 69353)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/ClassAdvisor.java	2008-01-25 18:25:53 UTC (rev 69354)
@@ -613,7 +613,7 @@
       if (this.interceptorChainObserver != null)
       {
          this.interceptorChainObserver.interceptorChainsUpdated(fieldReadInterceptors, fieldWriteInterceptors,
-               constructorInterceptors, methodInterceptors);
+               constructorInterceptors, methodInfos);
       }
    }
    
@@ -669,7 +669,7 @@
       if (this.interceptorChainObserver != null)
       {
          this.interceptorChainObserver.interceptorChainsUpdated(fieldReadInterceptors, fieldWriteInterceptors,
-               constructorInterceptors, methodInterceptors);
+               constructorInterceptors, methodInfos);
       }
    }
 
@@ -1777,7 +1777,7 @@
       if (observer != null)
       {
          observer.initialInterceptorChains(this.clazz, fieldReadInterceptors, fieldWriteInterceptors,
-               constructorInterceptors, methodInterceptors);
+               constructorInterceptors, methodInfos);
       }
       this.interceptorChainObserver = observer;
    }

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/GeneratedClassAdvisor.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/GeneratedClassAdvisor.java	2008-01-25 18:24:25 UTC (rev 69353)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/GeneratedClassAdvisor.java	2008-01-25 18:25:53 UTC (rev 69354)
@@ -611,7 +611,10 @@
          MethodJoinPointGenerator generator = getJoinPointGenerator(info);
          finalizeChainAndRebindJoinPoint(oldInfos, info, generator, OldInfoMaps.INFOS);
       }
-      methodInterceptors = newMethodInfos;
+      if (AspectManager.maintainAdvisorMethodInterceptors)
+      {
+         methodInterceptors = newMethodInfos;
+      }
       
       //Handle the overridden methods
       if (overriddenMethods != null && overriddenMethods.size() > 0)

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/HotSwapStrategy.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/HotSwapStrategy.java	2008-01-25 18:24:25 UTC (rev 69353)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/HotSwapStrategy.java	2008-01-25 18:25:53 UTC (rev 69354)
@@ -247,7 +247,7 @@
       private Interceptor[][] fieldReadInterceptors;
       private Interceptor[][] fieldWriteInterceptors;
       private Interceptor[][] constructorInterceptors;
-      private TLongObjectHashMap methodInterceptors;
+      private MethodInterceptors methodInterceptors;
       private int[] constructorIndexMap;
       
       /**
@@ -265,7 +265,7 @@
        * @see org.jboss.aop.InterceptorChainObserver#initialInterceptorChains(Interceptor[][], Interceptor[][], Interceptor[][], TLongObjectHashMap)
        */
       public synchronized void initialInterceptorChains(final Class reflectionClass, Interceptor[][] fieldReadInterceptors, Interceptor[][] fieldWriteInterceptors,
-            Interceptor[][] constructorInterceptors, TLongObjectHashMap methodInterceptors)
+            Interceptor[][] constructorInterceptors, MethodInterceptors methodInterceptors)
       {
          Constructor[] declaredConstructors = null;
          if (System.getSecurityManager() == null)
@@ -322,10 +322,10 @@
       
       /**
        * Notification method.
-       * @see InterceptorChainObserver#interceptorChainsUpdated(Interceptor[][], Interceptor[][], Interceptor[][], TLongObjectHashMap)
+       * @see InterceptorChainObserver#interceptorChainsUpdated(Interceptor[][], Interceptor[][], Interceptor[][], MethodInterceptors)
        */
       public synchronized void interceptorChainsUpdated(Interceptor[][] newFieldReadInterceptors, Interceptor[][] newFieldWriteInterceptors,
-            Interceptor[][] newConstructorInterceptors, TLongObjectHashMap newMethodInterceptors)
+            Interceptor[][] newConstructorInterceptors, MethodInterceptors newMethodInterceptors)
       {
          if (instanceInterceptors == 0)
          {
@@ -333,8 +333,8 @@
             for (int i = 0; i < methodKeys.length; i++)
             {
                long key = methodKeys[i];
-               MethodInfo oldMethodInfo = (MethodInfo) methodInterceptors.get(key);
-               MethodInfo newMethodInfo = (MethodInfo) newMethodInterceptors.get(key);
+               MethodInfo oldMethodInfo = (MethodInfo) methodInterceptors.getMethodInfo(key);
+               MethodInfo newMethodInfo = newMethodInterceptors.getMethodInfo(key);
                if (oldMethodInfo.getInterceptorChain().isEmpty() && !newMethodInfo.getInterceptorChain().isEmpty())
                {
                   newlyAdvised.methodExecutions.add(newMethodInfo);  
@@ -521,7 +521,7 @@
             for (int i = 0; i < methodKeys.length; i++)
             {
                long key = methodKeys[i];
-               MethodInfo methodInfo = (MethodInfo) this.methodInterceptors.get(key);
+               MethodInfo methodInfo = (MethodInfo) this.methodInterceptors.getMethodInfo(key);
                if (methodInfo.getInterceptorChain().isEmpty())
                {
                   joinpoints.methodExecutions.add(methodInfo);  

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/InterceptorChainObserver.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/InterceptorChainObserver.java	2008-01-25 18:24:25 UTC (rev 69353)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/InterceptorChainObserver.java	2008-01-25 18:25:53 UTC (rev 69354)
@@ -43,7 +43,7 @@
     * @param clazz the reflection class whose joinpoints the interceptor chains will be applied to.
     */
    public void initialInterceptorChains(Class clazz, Interceptor[][] fieldReadInterceptors, Interceptor[][] fieldWriteInterceptors,
-         Interceptor[][] constructorInterceptors, TLongObjectHashMap methodInterceptors);
+         Interceptor[][] constructorInterceptors, MethodInterceptors methodInterceptors);
 
    /**
     * Notifies the observer that the class interceptor chains were updated.
@@ -53,7 +53,7 @@
     * @param newMethodInterceptors new interceptor chains to be applied at methods' executions.
     */
    public void interceptorChainsUpdated(Interceptor[][] newFieldReadInterceptors, Interceptor[][] newFieldWriteInterceptors,
-         Interceptor[][] newConstructorInterceptors, TLongObjectHashMap newMethodInterceptors);
+         Interceptor[][] newConstructorInterceptors, MethodInterceptors newMethodInterceptors);
    
    /**
     * Notifies that an interceptor was added to an instance of

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/MethodInterceptors.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/MethodInterceptors.java	2008-01-25 18:24:25 UTC (rev 69353)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/MethodInterceptors.java	2008-01-25 18:25:53 UTC (rev 69354)
@@ -40,7 +40,7 @@
 
    public long[] keys()
    {
-      return infos.keys();
+      return infos.keys ();
    }
    
    public MethodInfo getMethodInfo(long hash)
@@ -67,4 +67,9 @@
    {
       infos.clear();
    }
+   
+   public int size()
+   {
+      return infos.size();
+   }
 }

Modified: projects/aop/trunk/aop/src/test/org/jboss/test/aop/container/ContainerTestCase.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/container/ContainerTestCase.java	2008-01-25 18:24:25 UTC (rev 69353)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/container/ContainerTestCase.java	2008-01-25 18:25:53 UTC (rev 69354)
@@ -21,6 +21,8 @@
   */
 package org.jboss.test.aop.container;
 
+import gnu.trove.TLongObjectHashMap;
+
 import java.lang.reflect.Method;
 
 import junit.framework.Test;
@@ -69,8 +71,20 @@
       invokeContainer(true);
    }
 
-   public void invokeContainer(boolean overriding) throws Throwable
+   public void testMethodInterceptorsPopulated() throws Throwable
    {
+      AspectManager.maintainAdvisorMethodInterceptors = true;
+      checkMethodInterceptors(true);
+   }
+   
+   public void testMethodInterceptorsNotPopulated() throws Throwable
+   {
+      AspectManager.maintainAdvisorMethodInterceptors = false;
+      checkMethodInterceptors(false);      
+   }
+   
+   private void invokeContainer(boolean overriding) throws Throwable
+   {
          AspectManager manager = AspectManager.instance();
          ClassContainer container = (overriding ) ? new ContainerWithChainOverriding("X", manager) : new ClassContainer("X", manager);
          container.setClass(Child.class);
@@ -88,6 +102,32 @@
          assertEquals(overriding, TestInterceptor.invoked);
    }
    
+   private void checkMethodInterceptors(boolean maintainAdvisorMethodInterceptors) throws Exception
+   {
+      AspectManager manager = AspectManager.instance();
+      TestContainer advisor = new TestContainer("X", manager);
+      advisor.setClass(Child.class);
+      advisor.initializeClassContainer();
+      Child child = new Child();
+      Method method = child.getClass().getMethod("childMethod", new Class[0]);
+      long hash = MethodHashing.calculateHash(method);
+      MethodInfo info = advisor.getMethodInfo(hash);
+      
+      TLongObjectHashMap methodInterceptors = advisor.getMethodInterceptors();
+      if (!maintainAdvisorMethodInterceptors)
+      {
+         assertNull(methodInterceptors);
+      }
+      else
+      {
+         assertNotNull(methodInterceptors);
+         MethodInfo info2 = (MethodInfo)methodInterceptors.get(hash);
+         assertNotNull(info2);
+         assertEquals(info, info2);
+      }
+      
+   }
+   
    private MethodInvocation getMethodInvocation(ClassContainer advisor, String methodName, Object target) throws Exception
    {
       Method method = target.getClass().getMethod(methodName, new Class[0]);

Added: projects/aop/trunk/aop/src/test/org/jboss/test/aop/container/TestContainer.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/container/TestContainer.java	                        (rev 0)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/container/TestContainer.java	2008-01-25 18:25:53 UTC (rev 69354)
@@ -0,0 +1,45 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.test.aop.container;
+
+import gnu.trove.TLongObjectHashMap;
+
+import org.jboss.aop.AspectManager;
+import org.jboss.aop.ClassContainer;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class TestContainer extends ClassContainer
+{
+   public TestContainer(String name, AspectManager manager)
+   {
+      super(name, manager);
+   }
+
+   public TLongObjectHashMap getMethodInterceptors()
+   {
+      return super.methodInterceptors;
+   }
+}




More information about the jboss-cvs-commits mailing list