[jboss-cvs] JBossAS SVN: r71182 - in projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop: advice and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Sun Mar 23 21:24:49 EDT 2008


Author: flavia.rainone at jboss.com
Date: 2008-03-23 21:24:49 -0400 (Sun, 23 Mar 2008)
New Revision: 71182

Added:
   projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/JoinPointManager.java
   projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/JoinPointRegistry.java
Modified:
   projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/AspectManager.java
   projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/ClassAdvisor.java
   projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/JoinPointInfo.java
   projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/advice/AdviceBinding.java
Log:
[JBAOP-509] Added some integration code.

Modified: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/AspectManager.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/AspectManager.java	2008-03-24 01:22:29 UTC (rev 71181)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/AspectManager.java	2008-03-24 01:24:49 UTC (rev 71182)
@@ -173,8 +173,12 @@
    protected volatile LinkedHashMap precedenceDefs = UnmodifiableEmptyCollections.EMPTY_LINKED_HASHMAP;
    protected PrecedenceDefEntry[] sortedPrecedenceDefEntries;
    protected WeavingStrategy weavingStrategy;
-
+   
+   // handles dynamic weaving on dynamic aop operations
    protected DynamicAOPStrategy dynamicStrategy = new LoadInterceptedClassesStrategy();
+   // manages the joinpoint interceptor chains during dynamic aop operations
+   protected JoinPointManager joinPointManager = new AdvisedJoinPointManager(this);
+   
    // indicates that the transformation process has begun
    protected boolean transformationStarted = false;
    
@@ -1316,8 +1320,7 @@
       AdviceBinding binding = internalRemoveBinding(name);
       if (binding != null)
       {
-         binding.clearAdvisors();
-         dynamicStrategy.interceptorChainsUpdated();
+         this.joinPointManager.bindingRemoved(binding);
       }
    }
 
@@ -1325,7 +1328,6 @@
    {
       clearUnregisteredClassLoaders();
 
-      HashSet bindingAdvisors = new HashSet();
       ArrayList removedBindings = new ArrayList();
       synchronized (bindings)
       {
@@ -1341,39 +1343,13 @@
                continue;
             }
             ArrayList ads = binding.getAdvisors();
-            bindingAdvisors.addAll(ads);
             bindings.remove(binding.getName());
             Pointcut pointcut = binding.getPointcut();
             this.removePointcut(pointcut.getName());
             removedBindings.add(binding);
          }
       }
-      Iterator it = bindingAdvisors.iterator();
-      while (it.hasNext())
-      {
-         Advisor advisor = (Advisor) it.next();
-         if (!isAdvisorRegistered(advisor))
-         {
-            //Check sub domains in case of generated advisors
-
-            WeakReference ref = (WeakReference)getSubDomainsPerClass().get(advisor.getClazz());
-            Domain domain = null;
-            if (ref != null) domain = (Domain)ref.get();
-            if (domain != null)
-            {
-               if (subscribedSubDomains.containsKey(domain) || subscribedSubDomainsQueue.containsKey(domain))
-               {
-                  if (!domain.isAdvisorRegistered(advisor))continue;
-               }
-               else
-               {
-                  continue;//If advisor does not belong to a subscribed subdomain, we should not rebuild
-               }
-            }
-         }
-         advisor.removeAdviceBindings(removedBindings);
-      }
-      dynamicStrategy.interceptorChainsUpdated();
+      joinPointManager.bindingsRemoved(removedBindings);
    }
 
    /**
@@ -1382,7 +1358,6 @@
    public synchronized void addBinding(AdviceBinding binding)
    {
       AdviceBinding removedBinding = internalRemoveBinding(binding.getName());
-      Set affectedAdvisors = removedBinding == null? new HashSet(): new HashSet(removedBinding.getAdvisors());
       initBindingsMap();
       synchronized (bindings)
       {
@@ -1398,19 +1373,15 @@
          pointcutInfos.put(pointcut.getName(), new PointcutInfo(pointcut, binding, this.transformationStarted));
          updatePointcutStats(pointcut);
       }
-
-      synchronized (advisors)
+      
+      if (removedBinding == null)
       {
-         updateAdvisorsForAddedBinding(binding);
-
-         for (Iterator i = affectedAdvisors.iterator(); i.hasNext(); )
-         {
-            Advisor advisor = (Advisor) i.next();
-            if (isAdvisorRegistered(advisor))
-               advisor.removeAdviceBinding(removedBinding);
-         }
+         this.joinPointManager.bindingAdded(binding);
       }
-      this.dynamicStrategy.interceptorChainsUpdated();
+      else
+      {
+         this.joinPointManager.bindingUpdated(binding, removedBinding);
+      }
    }
 
 

Modified: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/ClassAdvisor.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/ClassAdvisor.java	2008-03-24 01:22:29 UTC (rev 71181)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/ClassAdvisor.java	2008-03-24 01:24:49 UTC (rev 71182)
@@ -1774,7 +1774,7 @@
     */
    protected void setInterceptorChainObserver(InterceptorChainObserver observer)
    {
-      if (observer != null)
+      if (observer != null && this.initialized)
       {
          observer.initialInterceptorChains(this.clazz, fieldReadInterceptors, fieldWriteInterceptors,
                constructorInterceptors, methodInterceptors);

Modified: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/JoinPointInfo.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/JoinPointInfo.java	2008-03-24 01:22:29 UTC (rev 71181)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/JoinPointInfo.java	2008-03-24 01:24:49 UTC (rev 71182)
@@ -28,11 +28,15 @@
 import org.jboss.aop.advice.GeneratedAdvisorInterceptor;
 import org.jboss.aop.advice.Interceptor;
 import org.jboss.aop.joinpoint.JoinPointBean;
+import org.jboss.aop.joinpoint.JoinPointRegistry;
 import org.jboss.aop.joinpoint.Joinpoint;
-import org.jboss.aop.pointcut.Pointcut;
 
 public abstract class JoinPointInfo implements JoinPointBean
 {
+   // This field must be initialized by the JoinPointManager
+   // Every subclass must register itself in this registry
+   static JoinPointRegistry REGISTRY;
+   
    private ReentrantReadWriteLock interceptorChainLock = new ReentrantReadWriteLock();
    
    private Interceptor[] interceptors;

Added: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/JoinPointManager.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/JoinPointManager.java	                        (rev 0)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/JoinPointManager.java	2008-03-24 01:24:49 UTC (rev 71182)
@@ -0,0 +1,322 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.aop;
+
+import java.lang.ref.WeakReference;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.jboss.aop.advice.AdviceBinding;
+import org.jboss.aop.advice.Interceptor;
+import org.jboss.aop.advice.InterceptorFactory;
+import org.jboss.aop.advice.PrecedenceSorter;
+import org.jboss.aop.joinpoint.ConstructorCalledByConstructorJoinpoint;
+import org.jboss.aop.joinpoint.ConstructorCalledByMethodJoinpoint;
+import org.jboss.aop.joinpoint.ConstructorJoinpoint;
+import org.jboss.aop.joinpoint.FieldJoinpoint;
+import org.jboss.aop.joinpoint.JoinPointRegistry;
+import org.jboss.aop.joinpoint.Joinpoint;
+import org.jboss.aop.joinpoint.MethodCalledByConstructorJoinpoint;
+import org.jboss.aop.joinpoint.MethodCalledByMethodJoinpoint;
+import org.jboss.aop.joinpoint.MethodJoinpoint;
+import org.jboss.aop.joinpoint.graph.JoinPointGraph;
+import org.jboss.aop.joinpoint.graph.SearchKey;
+import org.jboss.aop.joinpoint.graph.SearchKeyParser;
+
+/**
+ * Now the RebuldingChainTestCase has two flavours: with joins and without joins (both test different deadlock scenarios)
+ * 
+ * @author  <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ */
+abstract class JoinPointManager
+{
+   protected AspectManager domain;
+   protected DynamicAOPStrategy dynamicWeavingStrategy;
+   
+   public JoinPointManager(AspectManager domain)
+   {
+      this.domain = domain;
+      this.dynamicWeavingStrategy = domain.getDynamicAOPStrategy();
+      JoinPointInfo.REGISTRY = getRegistry();
+   }
+   
+   protected abstract JoinPointRegistry getRegistry();
+   
+   public synchronized void bindingAdded(AdviceBinding binding)
+   {
+      this.internalBindingAdded(binding);
+      dynamicWeavingStrategy.interceptorChainsUpdated();
+   }
+   
+   public synchronized void bindingUpdated(AdviceBinding newBinding, AdviceBinding oldBinding)
+   {
+      this.internalBindingUpdated(newBinding, oldBinding);
+      dynamicWeavingStrategy.interceptorChainsUpdated();
+   }
+   
+   public synchronized void bindingRemoved(AdviceBinding binding)
+   {
+      this.internalBindingRemoved(binding);
+      this.dynamicWeavingStrategy.interceptorChainsUpdated();
+   }
+   
+   public synchronized void bindingsRemoved(Collection<AdviceBinding> bindings)
+   {
+      this.internalBindingsRemoved(bindings);
+      this.dynamicWeavingStrategy.interceptorChainsUpdated();
+   }
+   
+   protected abstract void internalBindingAdded(AdviceBinding binding);
+   protected abstract void internalBindingUpdated(AdviceBinding newBinding, AdviceBinding oldBinding);
+   protected abstract void internalBindingRemoved(AdviceBinding binding);
+   protected abstract void internalBindingsRemoved(Collection<AdviceBinding> bindings);
+}
+
+class AdvisedJoinPointManager extends JoinPointManager
+{
+
+   public AdvisedJoinPointManager(AspectManager domain)
+   {
+      super(domain);
+   }
+   
+   @Override
+   protected JoinPointRegistry getRegistry()
+   {
+      return new JoinPointRegistry() {};
+   }
+
+   @Override
+   protected void internalBindingAdded(AdviceBinding binding)
+   {
+      synchronized (domain.getAdvisors())
+      {
+         domain.updateAdvisorsForAddedBinding(binding);
+      }
+   }
+
+   @Override
+   protected void internalBindingUpdated(AdviceBinding newBinding, AdviceBinding oldBinding)
+   {
+      synchronized (domain.getAdvisors())
+      {
+         domain.updateAdvisorsForAddedBinding(newBinding);
+         ArrayList<Advisor> affectedAdvisors = oldBinding.getAdvisors();
+         if (affectedAdvisors != null && affectedAdvisors.size() > 0)
+         {
+            for (Advisor advisor : affectedAdvisors)
+            {
+               if (domain.isAdvisorRegistered(advisor))
+                  advisor.removeAdviceBinding(oldBinding);
+            }
+         }
+      }
+   }
+
+   @Override
+   protected void internalBindingRemoved(AdviceBinding binding)
+   {
+      for (Advisor advisor: binding.getAdvisors())
+      {
+         if (advisor.getManager().isAdvisorRegistered(advisor))
+         {
+            advisor.rebuildInterceptors();
+         }
+      }
+      binding.clearAdvisors();
+   }
+
+   @Override
+   protected void internalBindingsRemoved(Collection<AdviceBinding> bindings)
+   {
+      Collection<Advisor> advisors = new HashSet<Advisor>();
+      for (AdviceBinding binding: bindings)
+      {
+         advisors.addAll(binding.getAdvisors());
+      }
+      
+      for (Advisor advisor: advisors)
+      {
+         if (!domain.isAdvisorRegistered(advisor))
+         {
+            //Check sub domains in case of generated advisors
+            WeakReference ref = (WeakReference) domain.getSubDomainsPerClass().
+               get(advisor.getClazz());
+            if (ref == null)
+            {
+               continue;
+               
+            }
+            Domain domain = (Domain)ref.get();
+            if (domain == null)
+            {
+               continue;
+            }
+            // If advisor does not belong to a subscribed subdomain, we should not rebuild
+            if ((domain.getSubscribedSubDomains().containsKey(domain) ||
+                domain.subscribedSubDomainsQueue.containsKey(domain))
+               && domain.isAdvisorRegistered(advisor))
+            {
+               advisor.rebuildInterceptors();
+            }
+         }
+      }
+   }
+}
+
+class IndexedJoinPointManager extends JoinPointManager
+{
+   Map<String,Interceptor[]> createdInterceptors;
+   
+   public IndexedJoinPointManager(AspectManager domain)
+   {
+      super(domain);
+      this.createdInterceptors = new HashMap<String,Interceptor[]>();
+   }
+
+   @Override
+   protected JoinPointRegistry getRegistry()
+   {
+      return JoinPointGraph.getInstance();
+   }
+
+
+   @Override
+   protected void internalBindingAdded(AdviceBinding binding)
+   {
+      SearchKey searchKey = SearchKeyParser.parse(binding.getPointcut());
+      Collection<JoinPointInfo> affectedJoinPoints = JoinPointGraph.getInstance().search(searchKey);
+      for (JoinPointInfo joinPointInfo: affectedJoinPoints)
+      {
+         joinPointInfo.getInterceptorChainReadWriteLock().writeLock().lock();
+         try
+         {
+            // add the interceptors to the chain
+            joinPointInfo.getAdvisor().pointcutResolved(joinPointInfo, binding,
+                  joinPointInfo.getJoinpoint());
+
+            // add the created interceptors to the map
+            ArrayList<Interceptor> interceptors = joinPointInfo.getInterceptorChain();
+            InterceptorFactory[] factories = binding.getInterceptorFactories();
+            int initialIndex = interceptors.size() - factories.length; 
+            Interceptor[] created = new Interceptor[factories.length];
+            int i = 0;
+            for (Iterator<Interceptor> iterator = interceptors.listIterator(initialIndex);
+               iterator.hasNext(); i++)
+            {
+               created[i] = iterator.next();
+            }
+            this.createdInterceptors.put(binding.getName(), created);
+            
+            // set the chain in the appropriate order
+            joinPointInfo.setInterceptors(PrecedenceSorter.applyPrecedence(
+                  interceptors.toArray(new Interceptor[interceptors.size()]), domain));
+         }
+         finally
+         {
+            joinPointInfo.getInterceptorChainReadWriteLock().writeLock().unlock();
+         }
+      }
+   }
+
+
+   /* (non-Javadoc)
+    * @see org.jboss.aop.JoinPointManager#internalBindingRemoved(org.jboss.aop.advice.AdviceBinding)
+    */
+   @Override
+   protected void internalBindingRemoved(AdviceBinding binding)
+   {
+      //Interceptor[]
+   }
+
+
+   /* (non-Javadoc)
+    * @see org.jboss.aop.JoinPointManager#internalBindingUpdated(org.jboss.aop.advice.AdviceBinding, org.jboss.aop.advice.AdviceBinding)
+    */
+   @Override
+   protected void internalBindingUpdated(AdviceBinding newBinding, AdviceBinding oldBinding)
+   {
+      // TODO
+   }
+
+
+   /* (non-Javadoc)
+    * @see org.jboss.aop.JoinPointManager#internalBindingsRemoved(java.util.Collection)
+    */
+   @Override
+   protected void internalBindingsRemoved(Collection<AdviceBinding> bindings)
+   {
+      // TODO
+   }
+   
+   private Joinpoint createJoinpoint(JoinPointInfo joinPointInfo)
+   {
+      if (joinPointInfo instanceof FieldInfo)
+      {
+         return new FieldJoinpoint(((FieldInfo) joinPointInfo).getField());
+      }
+      if (joinPointInfo instanceof ConstructorInfo)
+      {
+         return new ConstructorJoinpoint(
+               ((ConstructorInfo) joinPointInfo).getConstructor());
+      }
+      if (joinPointInfo instanceof ConstructionInfo)
+      {
+         return new ConstructorJoinpoint(
+               ((ConstructionInfo) joinPointInfo).getConstructor());
+      }
+      if (joinPointInfo instanceof MethodInfo)
+      {
+         return new MethodJoinpoint(((MethodInfo) joinPointInfo).getMethod());
+      }
+      if (joinPointInfo instanceof ConByConInfo)
+      {
+         return new ConstructorCalledByConstructorJoinpoint(
+               ((ConByConInfo) joinPointInfo).getCallingConstructor(),
+               ((ConByConInfo) joinPointInfo).getConstructor());
+      }
+      if (joinPointInfo instanceof ConByMethodInfo)
+      {
+         return new ConstructorCalledByMethodJoinpoint(
+               ((ConByMethodInfo) joinPointInfo).getCallingMethod(),
+               ((ConByMethodInfo) joinPointInfo).getConstructor());
+      }
+      if (joinPointInfo instanceof MethodByConInfo)
+      {
+         return new MethodCalledByConstructorJoinpoint(
+               ((MethodByConInfo) joinPointInfo).getCallingConstructor(),
+               ((MethodByConInfo) joinPointInfo).getMethod());
+      }
+      if (joinPointInfo instanceof MethodByMethodInfo)
+      {
+         return new MethodCalledByMethodJoinpoint(
+               ((MethodByMethodInfo) joinPointInfo).getCallingMethod(),
+               ((MethodByMethodInfo) joinPointInfo).getMethod());
+      }
+      throw new RuntimeException("Unexpected JoinPointInfo type: " +
+               joinPointInfo.getClass());
+   }
+}
\ No newline at end of file

Modified: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/advice/AdviceBinding.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/advice/AdviceBinding.java	2008-03-24 01:22:29 UTC (rev 71181)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/advice/AdviceBinding.java	2008-03-24 01:24:49 UTC (rev 71182)
@@ -376,14 +376,6 @@
    {
       synchronized (advisors)
       {
-         for (Iterator it = advisors.keySet().iterator(); it.hasNext();)
-         {
-            Advisor advisor = (Advisor) it.next();
-            if (advisor.getManager().isAdvisorRegistered(advisor))
-            {
-               advisor.removeAdviceBinding(this);
-            }
-         }
          advisors.clear();
       }
    }

Added: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/JoinPointRegistry.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/JoinPointRegistry.java	                        (rev 0)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/JoinPointRegistry.java	2008-03-24 01:24:49 UTC (rev 71182)
@@ -0,0 +1,31 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.aop.joinpoint;
+
+/**
+ * @author  <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ *
+ */
+public interface JoinPointRegistry
+{
+
+}
\ No newline at end of file




More information about the jboss-cvs-commits mailing list