[jboss-cvs] JBossAS SVN: r64446 - projects/aop/trunk/aop/src/main/org/jboss/aop/instrument.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Aug 3 06:03:17 EDT 2007


Author: kabir.khan at jboss.com
Date: 2007-08-03 06:03:17 -0400 (Fri, 03 Aug 2007)
New Revision: 64446

Modified:
   projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/CallerTransformer.java
   projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/ConstructionTransformer.java
   projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/ConstructorExecutionTransformer.java
   projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/JoinpointSimpleClassifier.java
Log:
[JBAOP-430] Synchronize access to pointcuts map

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/CallerTransformer.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/CallerTransformer.java	2007-08-03 06:37:48 UTC (rev 64445)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/CallerTransformer.java	2007-08-03 10:03:17 UTC (rev 64446)
@@ -24,6 +24,8 @@
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
+
 import org.jboss.aop.AspectManager;
 import org.jboss.aop.ClassAdvisor;
 import org.jboss.aop.pointcut.Pointcut;
@@ -339,19 +341,23 @@
             DeclareChecker.checkDeclares(manager, call, advisor);
             
             // todo shouldn't iterate every time.  must be a better way
-            Iterator it = manager.getPointcuts().values().iterator();
-            while (it.hasNext())
+            Map pointcuts = manager.getPointcuts();
+            synchronized (pointcuts)
             {
-               Pointcut p = (Pointcut) it.next();
-               if (p.matchesCall(advisor, call))
+               Iterator it = pointcuts.values().iterator();
+               while (it.hasNext())
                {
-                  hasPointcut = true;
-                  break;
+                  Pointcut p = (Pointcut) it.next();
+                  if (p.matchesCall(advisor, call))
+                  {
+                     hasPointcut = true;
+                     break;
+                  }
+                  else
+                  {
+                     if (AspectManager.verbose && logger.isDebugEnabled()) logger.debug("MethodCall does not match: " + p.getExpr());
+                  }
                }
-               else
-               {
-                  if (AspectManager.verbose && logger.isDebugEnabled()) logger.debug("MethodCall does not match: " + p.getExpr());
-               }
             }
             if (hasPointcut)
             {
@@ -438,14 +444,18 @@
             boolean hasPointcut = false;
 
             // todo shouldn't iterate every time.  must be a better way
-            Iterator it = manager.getPointcuts().values().iterator();
-            while (it.hasNext())
+            Map pointcuts = manager.getPointcuts();
+            synchronized (pointcuts)
             {
-               Pointcut p = (Pointcut) it.next();
-               if (p.matchesCall(advisor, call))
+               Iterator it = pointcuts.values().iterator();
+               while (it.hasNext())
                {
-                  hasPointcut = true;
-                  break;
+                  Pointcut p = (Pointcut) it.next();
+                  if (p.matchesCall(advisor, call))
+                  {
+                     hasPointcut = true;
+                     break;
+                  }
                }
             }
             if (hasPointcut)

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/ConstructionTransformer.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/ConstructionTransformer.java	2007-08-03 06:37:48 UTC (rev 64445)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/ConstructionTransformer.java	2007-08-03 10:03:17 UTC (rev 64446)
@@ -23,6 +23,8 @@
 
 import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
+
 import org.jboss.aop.ClassAdvisor;
 import org.jboss.aop.pointcut.Pointcut;
 
@@ -147,13 +149,18 @@
    // currently used by CallerTransformer
    public static boolean isAdvisableConstructor(CtConstructor con, ClassAdvisor advisor) throws NotFoundException
    {
-      Iterator pointcuts = advisor.getManager().getPointcuts().values().iterator();
-      while (pointcuts.hasNext())
+      
+      Map pointcuts = advisor.getManager().getPointcuts();
+      synchronized (pointcuts)
       {
-         Pointcut pointcut = (Pointcut) pointcuts.next();
-         if (pointcut.matchesConstruction(advisor, con))
+         Iterator it = pointcuts.values().iterator();
+         while (it.hasNext())
          {
-            return true;
+            Pointcut pointcut = (Pointcut) it.next();
+            if (pointcut.matchesConstruction(advisor, con))
+            {
+               return true;
+            }
          }
       }
       return false;

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/ConstructorExecutionTransformer.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/ConstructorExecutionTransformer.java	2007-08-03 06:37:48 UTC (rev 64445)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/ConstructorExecutionTransformer.java	2007-08-03 10:03:17 UTC (rev 64446)
@@ -24,6 +24,7 @@
 import java.util.Collection;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
 
 import javassist.CannotCompileException;
 import javassist.CtClass;
@@ -465,13 +466,17 @@
    // currently used by CallerTransformer
    public static boolean isAdvisableConstructor(CtConstructor con, ClassAdvisor advisor) throws NotFoundException
    {
-      Iterator pointcuts = advisor.getManager().getPointcuts().values().iterator();
-      while (pointcuts.hasNext())
+      Map pointcuts = advisor.getManager().getPointcuts();
+      synchronized (pointcuts)
       {
-         Pointcut pointcut = (Pointcut) pointcuts.next();
-         if (pointcut.matchesExecution(advisor, con))
+         Iterator it = pointcuts.values().iterator();
+         while (it.hasNext())
          {
-            return true;
+            Pointcut pointcut = (Pointcut) it.next();
+            if (pointcut.matchesExecution(advisor, con))
+            {
+               return true;
+            }
          }
       }
       return false;

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/JoinpointSimpleClassifier.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/JoinpointSimpleClassifier.java	2007-08-03 06:37:48 UTC (rev 64445)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/JoinpointSimpleClassifier.java	2007-08-03 10:03:17 UTC (rev 64446)
@@ -60,17 +60,20 @@
    protected JoinpointClassification classifyJoinpoint(CtMember member, Advisor advisor, Matcher joinpointMatcher) throws NotFoundException
    {
       Collection pointcuts = advisor.getManager().getPointcuts().values();
-      for (Iterator it = pointcuts.iterator(); it.hasNext(); )
+      synchronized (pointcuts)
       {
-         Pointcut pointcut = (Pointcut) it.next();
-
-         if (joinpointMatcher.matches(pointcut, advisor, member))
+         for (Iterator it = pointcuts.iterator(); it.hasNext(); )
          {
-            if (AspectManager.verbose && logger.isDebugEnabled())
+            Pointcut pointcut = (Pointcut) it.next();
+   
+            if (joinpointMatcher.matches(pointcut, advisor, member))
             {
-               logger.debug(member + " matches pointcut: " + pointcut.getExpr());
+               if (AspectManager.verbose && logger.isDebugEnabled())
+               {
+                  logger.debug(member + " matches pointcut: " + pointcut.getExpr());
+               }
+               return JoinpointClassification.WRAPPED;
             }
-            return JoinpointClassification.WRAPPED;
          }
       }
       if (AspectManager.verbose && logger.isDebugEnabled())




More information about the jboss-cvs-commits mailing list