velocity-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nbu...@apache.org
Subject svn commit: r680817 - in /velocity/engine/trunk/src: java/org/apache/velocity/util/introspection/ test/org/apache/velocity/test/
Date Tue, 29 Jul 2008 19:49:41 GMT
Author: nbubna
Date: Tue Jul 29 12:49:41 2008
New Revision: 680817

URL: http://svn.apache.org/viewvc?rev=680817&view=rev
Log:
remove IntrospectorCacheListener support, some deprecated introspector stuff, and use finer-grained
synchronization (VELOCITY-606)

Removed:
    velocity/engine/trunk/src/java/org/apache/velocity/util/introspection/IntrospectorCacheListener.java
Modified:
    velocity/engine/trunk/src/java/org/apache/velocity/util/introspection/Introspector.java
    velocity/engine/trunk/src/java/org/apache/velocity/util/introspection/IntrospectorBase.java
    velocity/engine/trunk/src/java/org/apache/velocity/util/introspection/IntrospectorCache.java
    velocity/engine/trunk/src/java/org/apache/velocity/util/introspection/IntrospectorCacheImpl.java
    velocity/engine/trunk/src/test/org/apache/velocity/test/ClassloaderChangeTestCase.java

Modified: velocity/engine/trunk/src/java/org/apache/velocity/util/introspection/Introspector.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/src/java/org/apache/velocity/util/introspection/Introspector.java?rev=680817&r1=680816&r2=680817&view=diff
==============================================================================
--- velocity/engine/trunk/src/java/org/apache/velocity/util/introspection/Introspector.java
(original)
+++ velocity/engine/trunk/src/java/org/apache/velocity/util/introspection/Introspector.java
Tue Jul 29 12:49:41 2008
@@ -57,14 +57,6 @@
 public class Introspector extends IntrospectorBase
 {
     /**
-     *  define a public string so that it can be looked for
-     *  if interested
-     */
-
-    public final static String CACHEDUMP_MSG =
-        "Introspector: detected classloader change. Dumping cache.";
-
-    /**
      * @param log A Log object to use for the introspector.
      */
     public Introspector(final Log log)
@@ -136,12 +128,4 @@
         return null;
     }
 
-    /**
-     * Logs that the Introspector Cache has been cleared.
-     */
-    public void triggerClear()
-    {
-        super.triggerClear();
-        log.debug(CACHEDUMP_MSG);
-    }
 }

Modified: velocity/engine/trunk/src/java/org/apache/velocity/util/introspection/IntrospectorBase.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/src/java/org/apache/velocity/util/introspection/IntrospectorBase.java?rev=680817&r1=680816&r2=680817&view=diff
==============================================================================
--- velocity/engine/trunk/src/java/org/apache/velocity/util/introspection/IntrospectorBase.java
(original)
+++ velocity/engine/trunk/src/java/org/apache/velocity/util/introspection/IntrospectorBase.java
Tue Jul 29 12:49:41 2008
@@ -52,7 +52,6 @@
  * @version $Id$
  */
 public abstract class IntrospectorBase
-	implements IntrospectorCacheListener
 {
     /** Class logger */
     protected final Log log;
@@ -65,9 +64,8 @@
      */
     protected IntrospectorBase(final Log log)
     {
-	this.log = log;
-	introspectorCache = new IntrospectorCacheImpl(log); // TODO: Load that from properties.
-	introspectorCache.addListener(this);
+        this.log = log;
+        introspectorCache = new IntrospectorCacheImpl(log); // TODO: Load that from properties.
     }
     
     /**
@@ -114,67 +112,7 @@
      */
     protected IntrospectorCache getIntrospectorCache()
     {
-	return introspectorCache;
-    }
-    
-    /**
-     * Clears the internal cache.
-     * 
-     * @deprecated Use getIntrospectorCache().clear();
-     */
-    protected void clearCache()
-    {
-        getIntrospectorCache().clear();
-    }
-
-    /**
-     * Creates a class map for specific class and registers it in the
-     * cache.  Also adds the qualified name to the name->class map
-     * for later Classloader change detection.
-     *
-     * @param c The class for which the class map gets generated.
-     * @return A ClassMap object.
-     * 
-     * @deprecated Use getIntrospectorCache().put(c);
-     */
-    protected ClassMap createClassMap(final Class c)
-    {
-        return getIntrospectorCache().put(c);
-    }
-
-    /**
-     * Lookup a given Class object in the cache. If it does not exist, 
-     * check whether this is due to a class change and purge the caches
-     * eventually.
-     *
-     * @param c The class to look up.
-     * @return A ClassMap object or null if it does not exist in the cache.
-     * 
-     * @deprecated Use getIntrospectorCache().get(c);
-     */
-    protected ClassMap lookupClassMap(final Class c)
-    {
-        return getIntrospectorCache().get(c);
-    }
-    
-    /**
-     * @see IntrospectorCacheListener#triggerClear()
-     */
-    public void triggerClear()
-    {
-    }
-    
-    /**
-     * @see IntrospectorCacheListener#triggerGet(Class, ClassMap)
-     */
-    public void triggerGet(Class c, ClassMap classMap)
-    {
+	    return introspectorCache;
     }
 
-    /**
-     * @see IntrospectorCacheListener#triggerPut(Class, ClassMap)
-     */
-    public void triggerPut(Class c, ClassMap classMap)
-    {
-    }
 }

Modified: velocity/engine/trunk/src/java/org/apache/velocity/util/introspection/IntrospectorCache.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/src/java/org/apache/velocity/util/introspection/IntrospectorCache.java?rev=680817&r1=680816&r2=680817&view=diff
==============================================================================
--- velocity/engine/trunk/src/java/org/apache/velocity/util/introspection/IntrospectorCache.java
(original)
+++ velocity/engine/trunk/src/java/org/apache/velocity/util/introspection/IntrospectorCache.java
Tue Jul 29 12:49:41 2008
@@ -52,18 +52,4 @@
      */
     ClassMap put(Class c);
 
-    /**
-     * Register a Cache listener.
-     *
-     * @param listener A Cache listener object.
-     */
-    void addListener(IntrospectorCacheListener listener);
-
-    /**
-     * Remove a Cache listener.
-     *
-     * @param listener A Cache listener object.
-     */
-    void removeListener(IntrospectorCacheListener listener);
-
 }

Modified: velocity/engine/trunk/src/java/org/apache/velocity/util/introspection/IntrospectorCacheImpl.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/src/java/org/apache/velocity/util/introspection/IntrospectorCacheImpl.java?rev=680817&r1=680816&r2=680817&view=diff
==============================================================================
--- velocity/engine/trunk/src/java/org/apache/velocity/util/introspection/IntrospectorCacheImpl.java
(original)
+++ velocity/engine/trunk/src/java/org/apache/velocity/util/introspection/IntrospectorCacheImpl.java
Tue Jul 29 12:49:41 2008
@@ -33,9 +33,14 @@
  * @author <a href="mailto:henning@apache.org">Henning P. Schmiedehausen</a>
  * @version $Id$
  */
-public final class IntrospectorCacheImpl
-        implements IntrospectorCache
+public final class IntrospectorCacheImpl implements IntrospectorCache
 {
+    /**
+     * define a public string so that it can be looked for if interested
+     */
+    public final static String CACHEDUMP_MSG =
+        "IntrospectorCache detected classloader change. Dumping cache.";
+
     /** Class logger */
     private final Log log;
     
@@ -53,11 +58,6 @@
     private final Set classNameCache = new HashSet();
 
     /**
-     * Set of IntrospectorCache Listeners.
-     */
-    private final Set listeners = new HashSet();
-
-    /**
      * C'tor
      */
     public IntrospectorCacheImpl(final Log log)
@@ -68,13 +68,13 @@
     /**
      * Clears the internal cache.
      */
-    public synchronized void clear()
+    public void clear()
     {
-        classMapCache.clear();
-        classNameCache.clear();
-        for (Iterator it = listeners.iterator(); it.hasNext(); )
+        synchronized (classMapCache)
         {
-            ((IntrospectorCacheListener) it.next()).triggerClear();
+            classMapCache.clear();
+            classNameCache.clear();
+            log.debug(CACHEDUMP_MSG);
         }
     }
 
@@ -86,35 +86,30 @@
      * @param c The class to look up.
      * @return A ClassMap object or null if it does not exist in the cache.
      */
-    public synchronized ClassMap get(final Class c)
+    public ClassMap get(final Class c)
     {
         if (c == null)
         {
             throw new IllegalArgumentException("class is null!");
         }
 
-        ClassMap classMap = (ClassMap) classMapCache.get(c);
-
-        /*
-         * If we don't have this, check to see if we have it
-         * by name.  if so, then we have an object with the same
-         * name but loaded through a different class loader.
-         * In that case, we will just dump the cache to be sure.
-         */
-        
+        ClassMap classMap = (ClassMap)classMapCache.get(c);
         if (classMap == null)
         {
-            if (classNameCache.contains(c.getName()))
+            /*
+             * check to see if we have it by name.
+             * if so, then we have an object with the same
+             * name but loaded through a different class loader.
+             * In that case, we will just dump the cache to be sure.
+             */
+            synchronized (classMapCache)
             {
-                clear();
+                if (classNameCache.contains(c.getName()))
+                {
+                    clear();
+                }
             }
         }
-
-        for (Iterator it = listeners.iterator(); it.hasNext(); )
-        {
-            ((IntrospectorCacheListener) it.next()).triggerGet(c, classMap);
-        }
-
         return classMap;
     }
 
@@ -126,37 +121,15 @@
      * @param c The class for which the class map gets generated.
      * @return A ClassMap object.
      */
-    public synchronized ClassMap put(final Class c)
+    public ClassMap put(final Class c)
     {
-        ClassMap classMap = new ClassMap(c, log);
-        classMapCache.put(c, classMap);
-        classNameCache.add(c.getName());
-        
-        for (Iterator it = listeners.iterator(); it.hasNext(); )
+        final ClassMap classMap = new ClassMap(c, log);
+        synchronized (classMapCache)
         {
-            ((IntrospectorCacheListener) it.next()).triggerPut(c, classMap);
+            classMapCache.put(c, classMap);
+            classNameCache.add(c.getName());
         }
-
         return classMap;
     }
 
-    /**
-     * Register a Cache listener.
-     *
-     * @param listener A Cache listener object.
-     */
-    public synchronized void addListener(final IntrospectorCacheListener listener)
-    {
-        listeners.add(listener);
-    }
-
-    /**
-     * Remove a Cache listener.
-     *
-     * @param listener A Cache listener object.
-     */
-    public synchronized void removeListener(final IntrospectorCacheListener listener)
-    {
-        listeners.remove(listener);
-    }
 }

Modified: velocity/engine/trunk/src/test/org/apache/velocity/test/ClassloaderChangeTestCase.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/src/test/org/apache/velocity/test/ClassloaderChangeTestCase.java?rev=680817&r1=680816&r2=680817&view=diff
==============================================================================
--- velocity/engine/trunk/src/test/org/apache/velocity/test/ClassloaderChangeTestCase.java
(original)
+++ velocity/engine/trunk/src/test/org/apache/velocity/test/ClassloaderChangeTestCase.java
Tue Jul 29 12:49:41 2008
@@ -31,7 +31,7 @@
 import org.apache.velocity.app.VelocityEngine;
 import org.apache.velocity.runtime.RuntimeServices;
 import org.apache.velocity.runtime.log.LogChute;
-import org.apache.velocity.util.introspection.Introspector;
+import org.apache.velocity.util.introspection.IntrospectorCacheImpl;
 
 /**
  * Tests if we can hand Velocity an arbitrary class for logging.
@@ -143,7 +143,7 @@
      */
     public void log(int level, String message)
     {
-        if (message.equals( Introspector.CACHEDUMP_MSG) )
+        if (message.equals( IntrospectorCacheImpl.CACHEDUMP_MSG) )
         {
             sawCacheDump = true;
         }



Mime
View raw message