User: juhalindfors
Date: 02/03/17 02:35:55
Modified: src/main/javax/management/loading MLet.java
Log:
unified classloader support
Revision Changes Path
1.8 +73 -4 jmx/src/main/javax/management/loading/MLet.java
Index: MLet.java
===================================================================
RCS file: /cvsroot/jboss/jmx/src/main/javax/management/loading/MLet.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- MLet.java 13 Mar 2002 14:44:53 -0000 1.7
+++ MLet.java 17 Mar 2002 10:35:55 -0000 1.8
@@ -32,6 +32,11 @@
import org.jboss.mx.loading.MBeanFileParser;
import org.jboss.mx.loading.MLetParser;
import org.jboss.mx.loading.MBeanElement;
+import org.jboss.mx.loading.LoaderRepository;
+import org.jboss.mx.loading.UnifiedClassLoader;
+import org.jboss.mx.loading.UnifiedLoaderRepository;
+
+import org.jboss.mx.server.ServerConstants;
/**
* URL classloader capable of parsing an MLet text file adhering to the file
@@ -40,7 +45,7 @@
* @see javax.management.loading.MLetMBean
*
* @author <a href="mailto:[EMAIL PROTECTED]">Juha Lindfors</a>.
- * @version $Revision: 1.7 $
+ * @version $Revision: 1.8 $
*
* <p><b>Revisions:</b>
*
@@ -48,14 +53,34 @@
* <ul>
* <li> Added MLet text file ARG tag support </li>
* </ul>
+ *
+ * <p><b>20020317 Juha Lindfors:</b>
+ * <ul>
+ * <li> Unified Loader Repository support </li>
+ *
+ * <li> We need to intercept addURL() call since MLet CL exposes this as a
+ * public method (unlike URL CL). This means the set of URLs in this
+ * classloaders scope may change after it has been registered to the
+ * repository. </li>
+ *
+ * <li> We override loadClass() to delegate class loading directly to the
+ * repository in case a Unified Loader Repository is installed. This means
+ * in case of ULR this classloader is never used to load classes. The ULR
+ * has a set of Unified CLs that match the URLs added to this CL. </li>
+ * </ul>
*/
public class MLet
extends URLClassLoader
implements MLetMBean, MBeanRegistration
{
- // FIXME: (RI javadoc) Note - The MLet class loader uses the
DefaultLoaderRepository to load classes that could not be found in the loaded jar
files.
+ // FIXME: (RI javadoc) Note - The MLet class loader uses the
DefaultLoaderRepository
+ // to load classes that could not be found in the loaded jar files.
+ //
+ // IOW we need to override findClass for this cl...
+ // I think we can avoid the ugly dlr field hack from RI
+
// Attributes ----------------------------------------------------
/** Reference to the MBean server this loader is registered to. */
private MBeanServer server = null;
@@ -162,6 +187,12 @@
try
{
+ // FIXME: see the note at the beginning... we use an explicit loader
+ // in the createMBean() call to force this classloader to
+ // be used first to load all MLet classes. Normally this form
+ // of createMBean() call will not delegate to DLR even though
+ // the javadoc requires it. Therefore the findClass() should
+ // be overridden to delegate to the repository.
mbeans.add(server.createMBean(
element.getCode(),
(element.getName() != null) ? new
ObjectName(element.getName()) : null,
@@ -190,14 +221,28 @@
public void addURL(URL url)
{
- super.addURL(url);
+ if
(System.getProperty(ServerConstants.LOADER_REPOSITORY_CLASS_PROPERTY).equals(
+ ServerConstants.UNIFIED_LOADER_REPOSITORY_CLASS))
+ {
+ // since we don't have the URLs til getMBeansFromURL() is called we
+ // need to add these UCLs late, after the MBean registration
+ LoaderRepository.getDefaultLoaderRepository().addClassLoader(new
UnifiedClassLoader(url));
+ }
+
+ else
+ {
+ // will probably override to add individual URL CL to repository as well
+ // in the same style as with ULR. This would allow findClass() to safely
+ // delegate to the BLR without having to deal with infinite looping.
+ super.addURL(url);
+ }
}
public void addURL(String url) throws ServiceNotFoundException
{
try
{
- super.addURL(new URL(url));
+ this.addURL(new URL(url));
}
catch (MalformedURLException e)
{
@@ -207,13 +252,37 @@
public String getLibraryDirectory()
{
+ // FIXME
throw new Error("NYI");
}
public void setLibraryDirectory(String libdir)
{
+ // FIXME
throw new Error("NYI");
}
+ // Classloader overrides -----------------------------------------
+ public Class loadClass(String name, boolean resolve) throws
ClassNotFoundException
+ {
+ if
(System.getProperty(ServerConstants.LOADER_REPOSITORY_CLASS_PROPERTY).equals(
+ ServerConstants.UNIFIED_LOADER_REPOSITORY_CLASS))
+ {
+ // if its ULR we can safely delegate the load to it because only a single
+ // definition of a given class exists in the repository. This cl has
+ // conflicting definitions and therefore we skip it altogether.
+ UnifiedLoaderRepository ulr =
(UnifiedLoaderRepository)LoaderRepository.getDefaultLoaderRepository();
+ return ulr.loadClass(name, resolve,
Thread.currentThread().getContextClassLoader());
+ }
+
+ else
+ {
+ // with BLR multiple class definitions by different classloaders can
+ // exist... therefore try loadClass with this CL first, if it fails
+ // delegate to loader repository
+ return super.loadClass(name, resolve);
+ }
+ }
+
}
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development