[jboss-cvs] JBossAS SVN: r59462 - branches/JBoss_4_0_2_JBAS-3912/server/src/main/org/jboss/invocation/pooled/interfaces.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Jan 9 21:56:14 EST 2007


Author: tom.elrod at jboss.com
Date: 2007-01-09 21:56:12 -0500 (Tue, 09 Jan 2007)
New Revision: 59462

Modified:
   branches/JBoss_4_0_2_JBAS-3912/server/src/main/org/jboss/invocation/pooled/interfaces/OptimizedObjectInputStream.java
Log:
JBAS-3912 - fix for pooled invoker scoped classloading bug

Modified: branches/JBoss_4_0_2_JBAS-3912/server/src/main/org/jboss/invocation/pooled/interfaces/OptimizedObjectInputStream.java
===================================================================
--- branches/JBoss_4_0_2_JBAS-3912/server/src/main/org/jboss/invocation/pooled/interfaces/OptimizedObjectInputStream.java	2007-01-10 00:54:51 UTC (rev 59461)
+++ branches/JBoss_4_0_2_JBAS-3912/server/src/main/org/jboss/invocation/pooled/interfaces/OptimizedObjectInputStream.java	2007-01-10 02:56:12 UTC (rev 59462)
@@ -7,20 +7,22 @@
 
 package org.jboss.invocation.pooled.interfaces;
 
+import EDU.oswego.cs.dl.util.concurrent.ConcurrentHashMap;
+import EDU.oswego.cs.dl.util.concurrent.ConcurrentReaderHashMap;
+import org.jboss.logging.Logger;
+
+import java.io.IOException;
 import java.io.InputStream;
-import java.io.IOException;
 import java.io.ObjectInputStream;
 import java.io.ObjectStreamClass;
+import java.lang.ref.WeakReference;
+import java.lang.reflect.Method;
 import java.lang.reflect.Proxy;
-import java.lang.reflect.Method;
-import java.lang.ref.WeakReference;
+import java.util.Collections;
+import java.util.Map;
+import java.util.WeakHashMap;
 
-import org.jboss.util.collection.WeakValueHashMap;
 
-import org.jboss.logging.Logger;
-import org.jboss.invocation.MarshalledValueInputStream;
-import EDU.oswego.cs.dl.util.concurrent.ConcurrentReaderHashMap;
-
 /**
  * An ObjectInputStream subclass used by the MarshalledValue class to
  * ensure the classes and proxies are loaded using the thread context
@@ -30,11 +32,13 @@
  * @version $Revision$
  */
 public class OptimizedObjectInputStream
-        extends ObjectInputStream
+      extends ObjectInputStream
 {
    private static Logger log = Logger.getLogger(OptimizedObjectInputStream.class);
-   /** A class wide cache of proxy classes populated by resolveProxyClass */
-   private static ConcurrentReaderHashMap classCache;
+   /**
+    * A class wide cache of proxy classes populated by resolveProxyClass
+    */
+   private static Map classCache;
    private static ConcurrentReaderHashMap objectStreamClassCache;
    private static Method lookupStreamClass = null;
 
@@ -52,7 +56,8 @@
       }
    }
 
-   /** Enable local caching of resolved proxy classes. This can only be used
+   /**
+    * Enable local caching of resolved proxy classes. This can only be used
     * if there is a single ULR and no redeployment of the proxy classes.
     *
     * @param flag true to enable caching, false to disable it
@@ -61,7 +66,7 @@
    {
       if (flag == true)
       {
-         classCache = new ConcurrentReaderHashMap();
+         classCache = Collections.synchronizedMap(new WeakHashMap());
          objectStreamClassCache = new ConcurrentReaderHashMap();
       }
       else
@@ -71,8 +76,8 @@
       }
    }
 
-   /** Clear the current proxy cache.
-    *
+   /**
+    * Clear the current proxy cache.
     */
    public static void flushClassCache()
    {
@@ -83,13 +88,28 @@
    private static Class forName(String className) throws ClassNotFoundException
    {
       Class clazz = null;
+
       if (classCache != null)
       {
-         WeakReference ref = (WeakReference) classCache.get(className);
-         if (ref != null) clazz = (Class) ref.get();
+
+         ConcurrentHashMap subCache = (ConcurrentHashMap) classCache.get(Thread.currentThread().getContextClassLoader());
+         if (subCache == null)
+         {
+            classCache.put(Thread.currentThread().getContextClassLoader(), new ConcurrentHashMap());
+            subCache = (ConcurrentHashMap) classCache.get(Thread.currentThread().getContextClassLoader());
+         }
+
+         WeakReference ref = (WeakReference) subCache.get(className);
+         if (ref != null)
+         {
+            clazz = (Class) ref.get();
+         }
          if (clazz == null)
          {
-            if (ref != null) classCache.remove(className);
+            if (ref != null)
+            {
+               subCache.remove(className);
+            }
             ClassLoader loader = Thread.currentThread().getContextClassLoader();
             try
             {
@@ -103,7 +123,7 @@
                */
                clazz = Class.forName(className, false, loader);
             }
-            classCache.put(className, new WeakReference(clazz));
+            subCache.put(className, new WeakReference(clazz));
          }
       }
       else
@@ -136,7 +156,7 @@
    }
 
    protected ObjectStreamClass readClassDescriptor()
-           throws IOException, ClassNotFoundException
+         throws IOException, ClassNotFoundException
    {
       String className = readUTF();
       ObjectStreamClass osc = null;
@@ -148,9 +168,18 @@
       {
          Class clazz = forName(className);
          osc = ObjectStreamClass.lookup(clazz);
-         if (osc == null) osc = lookup(clazz);
-         if (osc == null) throw new IOException("Unable to readClassDescriptor for class " + className);
-         if (objectStreamClassCache != null) objectStreamClassCache.put(className, osc);
+         if (osc == null)
+         {
+            osc = lookup(clazz);
+         }
+         if (osc == null)
+         {
+            throw new IOException("Unable to readClassDescriptor for class " + className);
+         }
+         if (objectStreamClassCache != null)
+         {
+            objectStreamClassCache.put(className, osc);
+         }
       }
       return osc;
    }
@@ -158,17 +187,17 @@
    /**
     * Use the thread context class loader to resolve the class
     *
-    * @throws IOException   Any exception thrown by the underlying OutputStream.
+    * @throws IOException Any exception thrown by the underlying OutputStream.
     */
    protected Class resolveClass(ObjectStreamClass v)
-           throws IOException, ClassNotFoundException
+         throws IOException, ClassNotFoundException
    {
       String className = v.getName();
       return forName(className);
    }
 
    protected Class resolveProxyClass(String[] interfaces)
-           throws IOException, ClassNotFoundException
+         throws IOException, ClassNotFoundException
    {
       // Load the interfaces from the cache or thread context class loader
       ClassLoader loader = Thread.currentThread().getContextClassLoader();




More information about the jboss-cvs-commits mailing list