This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

FYI: Patch: java.rmi.server.RMIClassLoader


Hi list,


I commited the attached patch to trunk to merge RMIClassLoader with 
classpath. This patch adds caching functionalitiy to RMIClassLoader.


Michael
Index: ChangeLog
===================================================================
RCS file: /cvs/gcc/gcc/libjava/ChangeLog,v
retrieving revision 1.2241
diff -u -b -B -r1.2241 ChangeLog
--- ChangeLog	11 Oct 2003 18:19:44 -0000	1.2241
+++ ChangeLog	11 Oct 2003 18:28:12 -0000
@@ -1,3 +1,8 @@
+2003-10-11  Ingo Proetel  <proetel@aicas.com>
+
+	* java/rmi/server/RMIClassLoader.java: Identify cached classloaders by 
+	codebase and context classloader.
+
 2003-10-11  Michael Koch  <konqueror@gmx.de>
 
 	* java/beans/beancontext/BeanContext.java,
Index: java/rmi/server/RMIClassLoader.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/rmi/server/RMIClassLoader.java,v
retrieving revision 1.8
diff -u -b -B -r1.8 RMIClassLoader.java
--- java/rmi/server/RMIClassLoader.java	9 Oct 2003 15:20:25 -0000	1.8
+++ java/rmi/server/RMIClassLoader.java	11 Oct 2003 18:28:12 -0000
@@ -91,6 +91,63 @@
     }
 
     private final String annotation;
+  }
+  
+  /** 
+   * This class is used to identify a cached classloader by its codebase and 
+   * the context classloader that is its parent.
+   */  
+  private static class CacheKey
+  {
+     private String mCodeBase;
+     private ClassLoader mContextClassLoader;
+  	
+     public CacheKey (String theCodebase, ClassLoader theContextClassLoader)
+     {
+       mCodeBase = theCodebase;
+       mContextClassLoader = theContextClassLoader;
+     }
+  	
+    /**
+     * @return true if the codebase and the context classloader are equal
+     */
+    public boolean equals (Object theOther)
+    {
+      if (theOther != null
+          && theOther instanceof CacheKey)
+      {
+      	CacheKey key = (CacheKey) theOther;
+	
+      	return (equals (this.mCodeBase,key.mCodeBase)
+                && equals (this.mContextClassLoader, key.mContextClassLoader));
+        }
+      return false;
+    }
+    
+    /**
+     * Test if the two objects are equal or both null.
+     * @param theOne
+     * @param theOther
+     * @return
+     */
+    private boolean equals (Object theOne, Object theOther)
+    {
+      return theOne != null ? theOne.equals (theOther) : theOther == null;
+    }
+
+    /**
+     * @return hashCode  
+     */
+    public int hashCode()
+    {
+      return ((mCodeBase != null           ? mCodeBase.hashCode()           :  0) 
+              ^(mContextClassLoader != null ? mContextClassLoader.hashCode() : -1));
+    }
+
+    public String toString()
+    {
+      return "[" + mCodeBase + "," + mContextClassLoader + "]"; 
+    }
 
   }
 
@@ -129,7 +186,9 @@
       {
         defaultLoader = new MyClassLoader (new URL[] { defaultCodebase }, null,
                                            defaultAnnotation);
-        cacheLoaders.put(defaultAnnotation, defaultLoader);
+        cacheLoaders.put (new CacheKey (defaultAnnotation,
+                                        Thread.currentThread().getContextClassLoader()),
+                                        defaultLoader);
       }
     }
 
@@ -189,7 +248,10 @@
   private static ClassLoader getClassLoader (String codebases) 
     throws MalformedURLException
   {
-    ClassLoader loader = (ClassLoader) cacheLoaders.get (codebases);
+    ClassLoader loader;
+    CacheKey loaderKey = new CacheKey
+      (codebases, Thread.currentThread().getContextClassLoader());
+    loader = (ClassLoader) cacheLoaders.get (loaderKey);
 	
     if (loader == null)
       {
@@ -202,8 +264,9 @@
           urls.add (new URL (tok.nextToken()));
       
         loader = new MyClassLoader ((URL[]) urls.toArray (new URL [urls.size()]),
-    				    null, codebases);
-        cacheLoaders.put (codebases, loader);
+                                    Thread.currentThread().getContextClassLoader(),
+                                    codebases);
+        cacheLoaders.put (loaderKey, loader);
       }
            
     return loader;

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]