[jboss-cvs] JBossAS SVN: r65332 - projects/aop/trunk/aop/src/main/org/jboss/aop/advice/annotation.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Sep 12 11:06:55 EDT 2007


Author: flavia.rainone at jboss.com
Date: 2007-09-12 11:06:55 -0400 (Wed, 12 Sep 2007)
New Revision: 65332

Modified:
   projects/aop/trunk/aop/src/main/org/jboss/aop/advice/annotation/AdviceMethodFactory.java
Log:
[JBAOP-226] AdviceInfo cache was not implemented correctly, so, the cache was not working as a cache at all. Fixed.

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/advice/annotation/AdviceMethodFactory.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/advice/annotation/AdviceMethodFactory.java	2007-09-12 15:02:49 UTC (rev 65331)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/advice/annotation/AdviceMethodFactory.java	2007-09-12 15:06:55 UTC (rev 65332)
@@ -22,6 +22,7 @@
 package org.jboss.aop.advice.annotation;
 
 import java.lang.annotation.Annotation;
+import java.lang.ref.WeakReference;
 import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -31,7 +32,7 @@
 import java.util.LinkedList;
 import java.util.List;
 import java.util.ListIterator;
-import java.util.WeakHashMap;
+import java.util.Map;
 
 import org.jboss.aop.AspectManager;
 import org.jboss.aop.advice.AdviceMethodProperties;
@@ -179,8 +180,8 @@
    /** Stores advice matching failure messages. */
    private static StringBuffer adviceMatchingMessage = new StringBuffer();
    
-   private HashMap<String, WeakHashMap<ParameterAnnotationRule[],
-      Collection<AdviceInfo>>> adviceInfoCache;
+   private Map<String, Map<ParameterAnnotationRule[],
+      WeakReference<Collection<AdviceInfo>>>> adviceInfoCache;
    
    private ReturnType returnType;
    private AdviceSignatureRule adviceSignatureRule;
@@ -223,7 +224,7 @@
       this.rules = rules;
       this.returnType = returnType;
       this.adviceInfoCache = new HashMap
-         <String, WeakHashMap<ParameterAnnotationRule[], Collection<AdviceInfo>>>();
+         <String, Map<ParameterAnnotationRule[], WeakReference<Collection<AdviceInfo>>>>();
       this.compulsory = compulsory;
    }
    
@@ -320,7 +321,7 @@
    private Collection<AdviceInfo> getRankedAdvices(AdviceMethodProperties properties,
          ParameterAnnotationRule[] contextRules, int[][] mutuallyExclusive)
    {
-      WeakHashMap<ParameterAnnotationRule[], Collection<AdviceInfo>> map;
+      Map<ParameterAnnotationRule[], WeakReference<Collection<AdviceInfo>>> map;
       synchronized(adviceInfoCache)
       {
          // verify if list is on cache
@@ -329,7 +330,7 @@
          map = adviceInfoCache.get(key);
          if (map == null)
          {
-            map = new WeakHashMap<ParameterAnnotationRule[], Collection<AdviceInfo>>();
+            map = new HashMap<ParameterAnnotationRule[], WeakReference<Collection<AdviceInfo>>>();
             adviceInfoCache.put(key, map);
          }
       }
@@ -337,12 +338,16 @@
       {
          if (map.containsKey(contextRules))
          {
-            Collection<AdviceInfo> advices = map.get(contextRules);
-            for(AdviceInfo adviceInfo: advices)
+            WeakReference<Collection<AdviceInfo>> advicesReference = map.get(contextRules);
+            Collection<AdviceInfo> advices = advicesReference.get();
+            if (advices != null)
             {
-               adviceInfo.resetMatching();
+               for(AdviceInfo adviceInfo: advices)
+               {
+                  adviceInfo.resetMatching();
+               }
+               return advices;
             }
-            return advices;
          }
 
          // create the list
@@ -351,7 +356,7 @@
          ArrayList<AdviceInfo> rankedAdvices =
                new ArrayList<AdviceInfo>(methods.length);
          // add list to cache
-         map.put(contextRules, rankedAdvices);
+         map.put(contextRules, new WeakReference<Collection<AdviceInfo>>(rankedAdvices));
 
 
          if (methods.length == 0)




More information about the jboss-cvs-commits mailing list