[jboss-cvs] JBossAS SVN: r74297 - in projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop: joinpoint and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Sun Jun 8 18:36:59 EDT 2008


Author: flavia.rainone at jboss.com
Date: 2008-06-08 18:36:59 -0400 (Sun, 08 Jun 2008)
New Revision: 74297

Added:
   projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/AdvisorManagedMatchingStrategy.java
   projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/DynamicMatchingStrategy.java
   projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/IndexedMatchingStrategy.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/Domain.java
   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
Log:
[JBAOP-509] Created a strategy for integration, temporarily named DynamicMatchingStrategy. All tests pass when
running with the old strategy.

Added: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/AdvisorManagedMatchingStrategy.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/AdvisorManagedMatchingStrategy.java	                        (rev 0)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/AdvisorManagedMatchingStrategy.java	2008-06-08 22:36:59 UTC (rev 74297)
@@ -0,0 +1,39 @@
+/*
+ * 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;
+
+/**
+ * @author  <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ *
+ */
+public class AdvisorManagedMatchingStrategy implements DynamicMatchingStrategy
+{
+   public JoinPointManager getJoinPointManager(AspectManager manager)
+   {
+      return new AdvisedJoinPointManager(manager);
+   }
+
+   public JoinPointManager getJoinPointManager(Domain domain)
+   {
+      return new AdvisedJoinPointManager(domain);
+   }
+}
\ No newline at end of file

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-06-08 22:34:18 UTC (rev 74296)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/AspectManager.java	2008-06-08 22:36:59 UTC (rev 74297)
@@ -106,6 +106,9 @@
 {
    private static final Logger logger = AOPLogger.getLogger(AspectManager.class);
 
+   /** Strategy that controls how joinpoint info objects are managed during execution. */
+   protected static DynamicMatchingStrategy dynamicMatchingStrategy = new AdvisorManagedMatchingStrategy();
+   
    /** Lock to be used when lazy creating the collections */
    Object lazyCollectionLock = new Object();
 
@@ -180,7 +183,7 @@
    // 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);
+   protected JoinPointManager joinPointManager;
    
    // indicates that the transformation process has begun
    protected boolean transformationStarted = false;
@@ -321,7 +324,6 @@
                   ArrayList<String> list = splitString(invisibleAnnotations, ",");
                   manager.setIncludedInvisibleAnnotations(list);
                }
-
                String instrument = System.getProperty("jboss.aop.instrumentor", null);
                InstrumentorFactory.initialise(instrument);
 
@@ -345,8 +347,7 @@
                {
                   maintainAdvisorMethodInterceptors = (new Boolean(methodInterceptors)).booleanValue();
                }
-
-
+               manager.joinPointManager = dynamicMatchingStrategy.getJoinPointManager(manager);
                Deployment.deploy();
                return null;
             }
@@ -1413,7 +1414,7 @@
       {
          if (removedBinding == null)
          {
-         this.joinPointManager.bindingAdded(binding);
+            this.joinPointManager.bindingAdded(binding);
          }
          else
          {
@@ -1998,6 +1999,17 @@
       }
       this.dynamicStrategy = strategy;
    }
+   
+   public void setDynamicMatchingStrategy(DynamicMatchingStrategy strategy)
+   {
+      // avoid users calling this method in run time
+      if (this.transformationStarted || this.subDomainsByName.size() > 0)
+      {
+         throw new RuntimeException("Dynamic Matching Strategy Update not allowed in run time");
+      }
+      dynamicMatchingStrategy = strategy;
+      this.joinPointManager = strategy.getJoinPointManager(this);
+   }
 
    /**
     * Removes an AdviceBinding without notifying dynamic aop strategy.

Modified: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/Domain.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/Domain.java	2008-06-08 22:34:18 UTC (rev 74296)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/Domain.java	2008-06-08 22:36:59 UTC (rev 74297)
@@ -83,6 +83,7 @@
       this.parentFirst = parentFirst;
       this.name = name;
       manager.addSubDomainByName(this);
+      this.joinPointManager = dynamicMatchingStrategy.getJoinPointManager(this);
    }
 
    // FIXME: JBAOP-107 REMOVE THIS HACK

Added: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/DynamicMatchingStrategy.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/DynamicMatchingStrategy.java	                        (rev 0)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/DynamicMatchingStrategy.java	2008-06-08 22:36:59 UTC (rev 74297)
@@ -0,0 +1,32 @@
+/*
+ * 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;
+
+/**
+ * @author  <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ *
+ */
+public interface DynamicMatchingStrategy
+{
+   JoinPointManager getJoinPointManager(AspectManager manager);
+   JoinPointManager getJoinPointManager(Domain domain);
+}
\ No newline at end of file

Added: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/IndexedMatchingStrategy.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/IndexedMatchingStrategy.java	                        (rev 0)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/IndexedMatchingStrategy.java	2008-06-08 22:36:59 UTC (rev 74297)
@@ -0,0 +1,40 @@
+/*
+ * 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;
+
+/**
+ * @author  <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ *
+ */
+public class IndexedMatchingStrategy implements DynamicMatchingStrategy
+{
+   public JoinPointManager getJoinPointManager(AspectManager manager)
+   {
+      return new IndexedJoinPointManager(manager);
+   }
+
+   public JoinPointManager getJoinPointManager(Domain domain)
+   {
+      // TODO Auto-generated method stub
+      return null;
+   }
+}
\ No newline at end of file

Modified: 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	2008-06-08 22:34:18 UTC (rev 74296)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/JoinPointManager.java	2008-06-08 22:36:59 UTC (rev 74297)
@@ -45,6 +45,7 @@
 import org.jboss.aop.joinpoint.graph.JoinPointGraph;
 import org.jboss.aop.joinpoint.graph.SearchKey;
 import org.jboss.aop.joinpoint.graph.SearchKeyParser;
+import org.jboss.aop.pointcut.Pointcut;
 
 /**
  * Now the RebuldingChainTestCase has two flavours: with joins and without joins (both test different deadlock scenarios)
@@ -60,7 +61,7 @@
    {
       this.domain = domain;
       this.dynamicWeavingStrategy = domain.getDynamicAOPStrategy();
-      JoinPointInfo.REGISTRY = getRegistry();
+      JoinPointInfo.registry = getRegistry();
    }
    
    protected abstract JoinPointRegistry getRegistry();
@@ -106,7 +107,15 @@
    @Override
    protected JoinPointRegistry getRegistry()
    {
-      return new JoinPointRegistry() {};
+      return new JoinPointRegistry() {
+         public void register(ConstructorInfo info){}
+         public void register(ConstructionInfo info){}
+         public void register(FieldInfo info){}
+         public void register(MethodInfo info){}
+         public void register(ConByConInfo info){}
+         public void register(ConByMethodInfo info){}
+         public void register(MethodByConInfo info){}
+         public void register(MethodByMethodInfo info){}};
    }
 
    @Override
@@ -170,31 +179,33 @@
                continue;
                
             }
-            Domain domain = (Domain)ref.get();
+            Domain subDomain = (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))
+            boolean isSubscribedSubDomain = domain.getSubscribedSubDomains().
+                           containsKey(subDomain) ||
+                           domain.subscribedSubDomainsQueue.containsKey(subDomain);
+            if (!isSubscribedSubDomain || (domain.isAdvisorRegistered(advisor)))
             {
-               advisor.rebuildInterceptors();
+               continue;
             }
          }
+         advisor.rebuildInterceptors();
       }
    }
 }
 
 class IndexedJoinPointManager extends JoinPointManager
 {
-   Map<String,Interceptor[]> createdInterceptors;
+   Map<AdviceBinding,Collection<CreatedInterceptorInfo>> createdInterceptors;
    
    public IndexedJoinPointManager(AspectManager domain)
    {
       super(domain);
-      this.createdInterceptors = new HashMap<String,Interceptor[]>();
+      this.createdInterceptors = new HashMap<AdviceBinding,Collection<CreatedInterceptorInfo>>();
    }
 
    @Override
@@ -203,14 +214,28 @@
       return JoinPointGraph.getInstance();
    }
 
+   protected Collection<JoinPointInfo> getMatch(Pointcut pointcut)
+   {
+      SearchKey searchKey = SearchKeyParser.parse(pointcut);
+      return JoinPointGraph.getInstance().search(searchKey);
+   }
 
    @Override
    protected void internalBindingAdded(AdviceBinding binding)
    {
-      SearchKey searchKey = SearchKeyParser.parse(binding.getPointcut());
-      Collection<JoinPointInfo> affectedJoinPoints = JoinPointGraph.getInstance().search(searchKey);
-      for (JoinPointInfo joinPointInfo: affectedJoinPoints)
+      Collection<CreatedInterceptorInfo> createdInterceptorInfos = null;
+      if (this.createdInterceptors.containsKey(binding))
       {
+         createdInterceptorInfos = this.createdInterceptors.get(binding);
+      }
+      else
+      {
+         createdInterceptorInfos = new ArrayList<CreatedInterceptorInfo>();
+         this.createdInterceptors.put(binding, createdInterceptorInfos);
+      }
+         
+      for (JoinPointInfo joinPointInfo: getMatch(binding.getPointcut()))
+      {
          joinPointInfo.getInterceptorChainReadWriteLock().writeLock().lock();
          try
          {
@@ -229,7 +254,12 @@
             {
                created[i] = iterator.next();
             }
-            this.createdInterceptors.put(binding.getName(), created);
+            //this.createdInterceptors.put(binding.getName(), created);
+            synchronized(binding)
+            {
+               
+               createdInterceptorInfos.add(new CreatedInterceptorInfo(joinPointInfo, created));
+            }
             
             // set the chain in the appropriate order
             joinPointInfo.setInterceptors(PrecedenceSorter.applyPrecedence(
@@ -250,6 +280,30 @@
    protected void internalBindingRemoved(AdviceBinding binding)
    {
       //Interceptor[]
+      synchronized(binding)
+      {
+         Collection<CreatedInterceptorInfo> createdInterceptorInfos = this.createdInterceptors.get(binding);
+         for (CreatedInterceptorInfo createdInterceptorInfo: createdInterceptorInfos)
+         {
+            JoinPointInfo info = createdInterceptorInfo.info;
+         
+            ArrayList<Interceptor> interceptors = info.getInterceptorChain();
+            for (Iterator<Interceptor> iterator = interceptors.listIterator(); iterator.hasNext();)
+            {
+               if (createdInterceptorInfos.contains(iterator.next()))
+               {
+                  iterator.remove();
+               }
+            }
+            info.setInterceptors(interceptors.toArray(new Interceptor[interceptors.size()]));
+         }
+         createdInterceptorInfos.clear();
+         for (Advisor advisor: binding.getAdvisors())
+         {
+            advisor.adviceBindingRemoved(binding);
+         }
+         binding.clearAdvisors();
+      }
    }
 
 
@@ -259,7 +313,8 @@
    @Override
    protected void internalBindingUpdated(AdviceBinding newBinding, AdviceBinding oldBinding)
    {
-      // TODO
+      this.internalBindingRemoved(oldBinding);
+      this.internalBindingAdded(newBinding);
    }
 
 
@@ -269,7 +324,10 @@
    @Override
    protected void internalBindingsRemoved(Collection<AdviceBinding> bindings)
    {
-      // TODO
+      for (AdviceBinding binding: bindings)
+      {
+         this.internalBindingRemoved(binding);
+      }
    }
    
    private Joinpoint createJoinpoint(JoinPointInfo joinPointInfo)
@@ -319,4 +377,30 @@
       throw new RuntimeException("Unexpected JoinPointInfo type: " +
                joinPointInfo.getClass());
    }
+   
+   public static class CreatedInterceptorInfo
+   {
+      public JoinPointInfo info;
+      public Interceptor[] interceptors;
+      
+      public CreatedInterceptorInfo(JoinPointInfo info, Interceptor[] interceptors)
+      {
+         this.info = info;
+         this.interceptors = interceptors;
+      }
+   }
+}
+
+class IndexedDomainJoinPointManager extends IndexedJoinPointManager
+{
+   public IndexedDomainJoinPointManager(AspectManager domain)
+   {
+      super(domain);
+   }
+
+   // TODO implement this
+   protected Collection<JoinPointInfo> getMatch(Pointcut pointcut)
+   {
+      return super.getMatch(pointcut);
+   }
 }
\ No newline at end of file

Modified: 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	2008-06-08 22:34:18 UTC (rev 74296)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/JoinPointRegistry.java	2008-06-08 22:36:59 UTC (rev 74297)
@@ -21,11 +21,27 @@
  */
 package org.jboss.aop.joinpoint;
 
+import org.jboss.aop.ConByConInfo;
+import org.jboss.aop.ConByMethodInfo;
+import org.jboss.aop.ConstructionInfo;
+import org.jboss.aop.ConstructorInfo;
+import org.jboss.aop.FieldInfo;
+import org.jboss.aop.MethodByConInfo;
+import org.jboss.aop.MethodByMethodInfo;
+import org.jboss.aop.MethodInfo;
+
 /**
  * @author  <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
  *
  */
 public interface JoinPointRegistry
 {
-
+   public void register(ConstructorInfo info);
+   public void register(ConstructionInfo info);
+   public void register(FieldInfo info);
+   public void register(MethodInfo info);
+   public void register(ConByConInfo info);
+   public void register(ConByMethodInfo info);
+   public void register(MethodByConInfo info);
+   public void register(MethodByMethodInfo info);
 }
\ No newline at end of file




More information about the jboss-cvs-commits mailing list