[jboss-remoting-commits] JBoss Remoting SVN: r4440 - in remoting2/branches/2.x/src/main/org/jboss/remoting: loading and 1 other directories.

jboss-remoting-commits at lists.jboss.org jboss-remoting-commits at lists.jboss.org
Wed Jul 30 20:33:27 EDT 2008


Author: scott.stark at jboss.org
Date: 2008-07-30 20:33:26 -0400 (Wed, 30 Jul 2008)
New Revision: 4440

Modified:
   remoting2/branches/2.x/src/main/org/jboss/remoting/AbstractInvoker.java
   remoting2/branches/2.x/src/main/org/jboss/remoting/MicroRemoteClientInvoker.java
   remoting2/branches/2.x/src/main/org/jboss/remoting/Remoting.java
   remoting2/branches/2.x/src/main/org/jboss/remoting/loading/RemotingClassLoader.java
   remoting2/branches/2.x/src/main/org/jboss/remoting/util/SecurityUtility.java
Log:
JBREM-1019, add a Remoting.CLASSLOADING_PARENT_FIRST_DELEGATION = "classloadingParentFirstDelegation" invoker configuration option and 
Remoting.CLASSLOADING_PARENT_FIRST_DELEGATION_PROP = "org.jboss.remoting.classloadingParentFirstDelegation" system property for controlling the order the RemotingClassLoader uses for delegation to the parent and user class loaders. When true (the default, the parent class loader is delegated to before the user class loader.

Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/AbstractInvoker.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/AbstractInvoker.java	2008-07-30 15:30:52 UTC (rev 4439)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/AbstractInvoker.java	2008-07-31 00:33:26 UTC (rev 4440)
@@ -387,7 +387,11 @@
       return wrapSocketFactory(factory, configuration);
    }
    
-   
+   protected Map getConfiguration()
+   {
+      return configuration;
+   }
+
    static public SocketFactory wrapSocketFactory(SocketFactory socketFactory, Map config)
    {
       if (config == null)

Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/MicroRemoteClientInvoker.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/MicroRemoteClientInvoker.java	2008-07-30 15:30:52 UTC (rev 4439)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/MicroRemoteClientInvoker.java	2008-07-31 00:33:26 UTC (rev 4440)
@@ -117,6 +117,19 @@
          // classes.  If possible, will simply reset context classloader on existing
          // RemotingClassLoader.
          final ClassLoader contextClassLoader = SecurityUtility.getContextClassLoader(Thread.currentThread());
+         // Get the parent delegation order flag, default is parent first
+         Object flag = super.getConfiguration().get(Remoting.CLASSLOADING_PARENT_FIRST_DELEGATION);
+         if(flag == null)
+         {
+            // Fallback to the system property
+            flag = SecurityUtility.getSystemProperty(Remoting.CLASSLOADING_PARENT_FIRST_DELEGATION_PROP);
+         }
+         boolean parentFirst = true;
+         if (flag != null)
+         {
+            String sflag = flag.toString();
+            parentFirst = Boolean.valueOf(sflag);
+         }
          if (unmarshaller instanceof UpdateableClassloaderUnMarshaller)
          {
             UpdateableClassloaderUnMarshaller uclum = (UpdateableClassloaderUnMarshaller) unmarshaller;
@@ -128,13 +141,13 @@
             }
             else
             {
-               rcl = SecurityUtility.createRemotingClassLoader(getClassLoader(), contextClassLoader);
+               rcl = SecurityUtility.createRemotingClassLoader(getClassLoader(), contextClassLoader, parentFirst);
                unmarshaller.setClassLoader(rcl);
             }
          }
          else
          {
-            rcl = SecurityUtility.createRemotingClassLoader(getClassLoader(), contextClassLoader);
+            rcl = SecurityUtility.createRemotingClassLoader(getClassLoader(), contextClassLoader, parentFirst);
             unmarshaller.setClassLoader(rcl);  
          }
       }

Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/Remoting.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/Remoting.java	2008-07-30 15:30:52 UTC (rev 4439)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/Remoting.java	2008-07-31 00:33:26 UTC (rev 4440)
@@ -75,4 +75,11 @@
     * java.security.AccessController.doPrivileged() calls.
     */
    public static final String SKIP_ACCESS_CONTROL = "skipAccessControl";
+
+   /**
+    * A flag indicating whether the RemotingClassLoader uses parent first (=true)
+    * or user class loader first delegation.
+    */
+   public static final String CLASSLOADING_PARENT_FIRST_DELEGATION = "classloadingParentFirstDelegation";
+   public static final String CLASSLOADING_PARENT_FIRST_DELEGATION_PROP = "org.jboss.remoting.classloadingParentFirstDelegation";
 }

Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/loading/RemotingClassLoader.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/loading/RemotingClassLoader.java	2008-07-30 15:30:52 UTC (rev 4439)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/loading/RemotingClassLoader.java	2008-07-31 00:33:26 UTC (rev 4440)
@@ -27,22 +27,30 @@
 
 /**
  * @author <a href="mailto:tom.elrod at jboss.com">Tom Elrod</a>
+ * @version $Revision$
  */
 public class RemotingClassLoader extends ClassLoader
 {
    private ClassLoader userClassLoader = null;
    private int referenceCounter;
+   private boolean parentFirstDelegation;
 
    protected static final Logger log = Logger.getLogger(RemotingClassLoader.class);
    protected static final boolean isTrace = log.isTraceEnabled();
 
    public RemotingClassLoader(ClassLoader remotingClassLoader, ClassLoader userClassLoader)
    {
+      this(remotingClassLoader, userClassLoader, true);
+   }
+   public RemotingClassLoader(ClassLoader remotingClassLoader, ClassLoader userClassLoader,
+         boolean parentFirstDelegation)
+   {
       super(remotingClassLoader);
       this.userClassLoader = userClassLoader;
+      this.parentFirstDelegation = parentFirstDelegation;
       referenceCounter = 1;
    }
-   
+
    public synchronized void setUserClassLoader(ClassLoader userClassLoader)
    throws Exception
    {
@@ -67,9 +75,35 @@
    {
       Class loadedClass = null;
 
+      ClassLoader parent = getParent();
+      if (this.parentFirstDelegation || userClassLoader == null)
+         loadedClass = loadClassDelegate(name, parent, userClassLoader);
+      else
+         loadedClass = loadClassDelegate(name, userClassLoader, parent);
+         
+      if(loadedClass == null)
+      {
+         loadedClass = ClassLoaderUtility.loadClass(name, getClass());
+      }
+
+      return loadedClass;
+   }
+
+   /**
+    * Try to load the named class using the primary and secondary class loaders.
+    * @param name - the class name to load
+    * @param primary - the initial class loader to delegate to
+    * @param secondary - the backup class loader to delegate to
+    * @return the loaded class
+    * @throws ClassNotFoundException
+    */
+   private Class loadClassDelegate(String name, ClassLoader primary, ClassLoader secondary)
+      throws ClassNotFoundException
+   {
+      Class loadedClass = null;
       try
       {
-         loadedClass = Class.forName(name, false, getParent());
+         loadedClass = Class.forName(name, false, primary);
       }
       catch(ClassNotFoundException e)
       {
@@ -77,11 +111,11 @@
          {
             log.trace("Could not load class (" + name + ") using parent remoting class loader (" + getParent() + ")");
          }
-         if(userClassLoader != null)
+         if(secondary != null)
          {
             try
             {
-               loadedClass = Class.forName(name, false, userClassLoader);
+               loadedClass = Class.forName(name, false, secondary);
             }
             catch (ClassNotFoundException e1)
             {
@@ -92,13 +126,6 @@
             }
          }
       }
-
-      if(loadedClass == null)
-      {
-         loadedClass = ClassLoaderUtility.loadClass(name, getClass());
-      }
-
       return loadedClass;
    }
-
 }
\ No newline at end of file

Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/util/SecurityUtility.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/util/SecurityUtility.java	2008-07-30 15:30:52 UTC (rev 4439)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/util/SecurityUtility.java	2008-07-31 00:33:26 UTC (rev 4440)
@@ -640,18 +640,24 @@
    // RuntimePermission methods
    ///////////////////////////////////////////////////////////////////////////////////////
    
-   static public RemotingClassLoader createRemotingClassLoader(final ClassLoader remotingClassLoader, final ClassLoader userClassLoader)
+   static public RemotingClassLoader createRemotingClassLoader(final ClassLoader remotingClassLoader,
+         final ClassLoader userClassLoader)
    {
+      return createRemotingClassLoader(remotingClassLoader, userClassLoader, true);
+   }
+   static public RemotingClassLoader createRemotingClassLoader(final ClassLoader remotingClassLoader,
+         final ClassLoader userClassLoader, final boolean parentFirstDelegation)
+   {
       if (skipAccessControl)
       {
-         return new RemotingClassLoader(remotingClassLoader, userClassLoader);
+         return new RemotingClassLoader(remotingClassLoader, userClassLoader, parentFirstDelegation);
       }
 
       return (RemotingClassLoader)AccessController.doPrivileged( new PrivilegedAction()
       {
          public Object run()
          {
-            return new RemotingClassLoader(remotingClassLoader, userClassLoader);
+            return new RemotingClassLoader(remotingClassLoader, userClassLoader, parentFirstDelegation);
          }
       });
    }




More information about the jboss-remoting-commits mailing list