站内搜索: 请输入搜索关键词
当前页面: 在线文档首页 > JBoss 3.2.7 jmx API Documentation 英文版文档

UnifiedClassLoader (JBoss/JMX API) - JBoss 3.2.7 jmx API Documentation 英文版文档


org.jboss.mx.loading
Class UnifiedClassLoader

java.lang.Object
  extended byjava.lang.ClassLoader
      extended byjava.security.SecureClassLoader
          extended byjava.net.URLClassLoader
              extended byorg.jboss.mx.loading.UnifiedClassLoader
All Implemented Interfaces:
org.jboss.util.loading.Translatable, UnifiedClassLoaderMBean
Direct Known Subclasses:
UnifiedClassLoader2, UnifiedClassLoader3, UnifiedClassLoader4

public class UnifiedClassLoader
extends URLClassLoader
implements UnifiedClassLoaderMBean, org.jboss.util.loading.Translatable

A ClassLoader which loads classes from a single URL in conjunction with the LoaderRepository. Notice that this classloader does not work independently of the repository. A repository reference must be provided via the constructor or the classloader must be explicitly registered to the repository before any attempt to load a class. At this point this is little more than an abstract class maintained as the interface for class loaders as the algorithm of the UnifiedLoaderRepository fails with deadlocks, and several other class loading exceptions in multi- threaded environments.

Version:
$Revision: 1.9.4.28 $
Author:
Marc Fleury, Christoph G. Jung, Scott Stark, Juha Lindfors, Bill Burke

Field Summary
protected  URL origURL
          An optional URL from which url may have been copied.
protected  LoaderRepository repository
          Reference to the unified repository.
protected  Exception unregisterTrace
          The location where unregister is called from
protected  URL url
          One URL per ClassLoader in our case
 
Constructor Summary
UnifiedClassLoader(URL url)
          Construct a UnifiedClassLoader without registering it to the classloader repository.
UnifiedClassLoader(URL url, LoaderRepository repository)
          Construct a UnifiedClassLoader and registers it to the given repository.
UnifiedClassLoader(URL url, MBeanServer server, ObjectName repositoryName)
          UnifiedClassLoader constructor that can be used to register with a particular Loader Repository identified by ObjectName.
UnifiedClassLoader(URL url, URL origURL)
          Construct a UnifiedClassLoader without registering it to the classloader repository.
UnifiedClassLoader(URL url, URL origURL, ClassLoader parent)
          Construct a UnifiedClassLoader without registering with the classloader repository.
UnifiedClassLoader(URL url, URL origURL, LoaderRepository repository)
          Construct a UnifiedClassLoader and registers it to the given repository.
UnifiedClassLoader(URL url, URL origURL, MBeanServer server, ObjectName repositoryName)
          UnifiedClassLoader constructor that can be used to register with a particular Loader Repository identified by ObjectName.
 
Method Summary
 void addURL(URL url)
          Append the given url to the URLs used for class and resource loading
 void clearBlacklists()
           
protected  void definePackage(String className)
          Define the package for the class if not already done
 boolean equals(Object other)
          This is here to document that this must delegate to the super implementation to perform identity based equality.
protected  Class findClass(String name)
          Called by loadClassLocally to find the requested class within this class loaders class path.
 Enumeration findResources(String name)
          Find all resource URLs for the given name.
 Enumeration findResourcesLocally(String name)
          Provides the same functionality as URLClassLoader.findResources(java.lang.String).
 int getAddedOrder()
           
 URL[] getAllURLs()
          Return all library URLs associated with this UnifiedClassLoader
 URL[] getClasspath()
          This method simply invokes the super.getURLs() method to access the list of URLs that make up the UnifiedClassLoader classpath.
 LoaderRepository getLoaderRepository()
           
 ObjectName getObjectName()
          Obtain the ObjectName under which the UCL can be registered with the JMX server.
 URL getOrigURL()
          Get the original URL associated with the UCL.
 Package getPackage(String name)
           
 Package[] getPackages()
           
protected  PermissionCollection getPermissions(CodeSource cs)
          Override the permissions accessor to use the CodeSource based on the original URL if one exists.
protected  ProtectionDomain getProtectionDomain()
          Determine the protection domain.
protected  ProtectionDomain getProtectionDomain(URL codesourceUrl)
          Determine the protection domain.
 URL getResource(String name)
          Attempts to load the resource from its URL and if not found forwards to the request to LoaderRepository.
 URL getResourceLocally(String name)
          Provides the same functionality as ClassLoader.getResource(java.lang.String).
 URL getURL()
          Get the URL associated with the UCL.
 URL[] getURLs()
          Return an empty URL array to force the RMI marshalling subsystem to use the java.server.codebase property as the annotated codebase.
 int hashCode()
          This is here to document that this must delegate to the super implementation to perform identity based hashing.
protected  byte[] loadByteCode(String classname)
          Obtain the bytecode for the indicated class from this class loaders classpath.
 Class loadClass(String name, boolean resolve)
          The only caller of this method should be the VM initiated loadClassInternal() method.
 Class loadClassLocally(String name, boolean resolve)
          Called to attempt to load a class from the set of URLs associated with the UCL.
 void setAddedOrder(int addedOrder)
           
 void setRepository(LoaderRepository repository)
           
 String toString()
          Retruns a string representaion of this UCL.
 void unregister()
           
 
Methods inherited from class java.net.URLClassLoader
definePackage, findResource, newInstance, newInstance
 
Methods inherited from class java.security.SecureClassLoader
defineClass
 
Methods inherited from class java.lang.ClassLoader
clearAssertionStatus, defineClass, defineClass, defineClass, definePackage, findLibrary, findLoadedClass, findSystemClass, getParent, getResourceAsStream, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, loadClass, resolveClass, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

repository

protected LoaderRepository repository
Reference to the unified repository.


unregisterTrace

protected Exception unregisterTrace
The location where unregister is called from


url

protected URL url
One URL per ClassLoader in our case


origURL

protected URL origURL
An optional URL from which url may have been copied. It is used to allow the security permissions to be based on a static url namespace.

Constructor Detail

UnifiedClassLoader

public UnifiedClassLoader(URL url)
Construct a UnifiedClassLoader without registering it to the classloader repository.

Parameters:
url - the single URL to load classes from.

UnifiedClassLoader

public UnifiedClassLoader(URL url,
                          URL origURL)
Construct a UnifiedClassLoader without registering it to the classloader repository.

Parameters:
url - the single URL to load classes from.
origURL - the possibly null original URL from which url may be a local copy or nested jar.

UnifiedClassLoader

public UnifiedClassLoader(URL url,
                          URL origURL,
                          ClassLoader parent)
Construct a UnifiedClassLoader without registering with the classloader repository.

Parameters:
url - the single URL to load classes from.
origURL - the possibly null original URL from which url may be a local copy or nested jar.
parent - the parent class loader to use

UnifiedClassLoader

public UnifiedClassLoader(URL url,
                          LoaderRepository repository)
Construct a UnifiedClassLoader and registers it to the given repository.

Parameters:
url - The single URL to load classes from.
repository - the repository this classloader delegates to

UnifiedClassLoader

public UnifiedClassLoader(URL url,
                          URL origURL,
                          LoaderRepository repository)
Construct a UnifiedClassLoader and registers it to the given repository.

Parameters:
url - The single URL to load classes from.
origURL - the possibly null original URL from which url may be a local copy or nested jar.
repository - the repository this classloader delegates to be a local copy or nested jar.

UnifiedClassLoader

public UnifiedClassLoader(URL url,
                          MBeanServer server,
                          ObjectName repositoryName)
                   throws Exception
UnifiedClassLoader constructor that can be used to register with a particular Loader Repository identified by ObjectName.

Parameters:
url - an URL value
server - a MBeanServer value
repositoryName - an ObjectName value
Throws:
Exception - if an error occurs

UnifiedClassLoader

public UnifiedClassLoader(URL url,
                          URL origURL,
                          MBeanServer server,
                          ObjectName repositoryName)
                   throws Exception
UnifiedClassLoader constructor that can be used to register with a particular Loader Repository identified by ObjectName.

Parameters:
url - an URL value
origURL - the possibly null original URL from which url may be a local copy or nested jar.
server - a MBeanServer value
repositoryName - an ObjectName value
Throws:
Exception - if an error occurs
Method Detail

getAddedOrder

public int getAddedOrder()

setAddedOrder

public void setAddedOrder(int addedOrder)

getObjectName

public ObjectName getObjectName()
                         throws MalformedObjectNameException
Obtain the ObjectName under which the UCL can be registered with the JMX server. This creates a name of the form "jmx.loading:UCL=hashCode" since we don't currently care that UCL be easily queriable.

Throws:
MalformedObjectNameException

unregister

public void unregister()

addURL

public void addURL(URL url)
Append the given url to the URLs used for class and resource loading

Parameters:
url - the URL to load from

clearBlacklists

public void clearBlacklists()

getLoaderRepository

public LoaderRepository getLoaderRepository()

setRepository

public void setRepository(LoaderRepository repository)

loadClassLocally

public Class loadClassLocally(String name,
                              boolean resolve)
                       throws ClassNotFoundException
Called to attempt to load a class from the set of URLs associated with the UCL.

Throws:
ClassNotFoundException

getResourceLocally

public URL getResourceLocally(String name)
Provides the same functionality as ClassLoader.getResource(java.lang.String).

Specified by:
getResourceLocally in interface org.jboss.util.loading.Translatable

getURL

public URL getURL()
Get the URL associated with the UCL.


getOrigURL

public URL getOrigURL()
Get the original URL associated with the UCL. This may be null.


getClasspath

public URL[] getClasspath()
This method simply invokes the super.getURLs() method to access the list of URLs that make up the UnifiedClassLoader classpath.


loadClass

public Class loadClass(String name,
                       boolean resolve)
                throws ClassNotFoundException
The only caller of this method should be the VM initiated loadClassInternal() method. This method attempts to acquire the UnifiedLoaderRepository2 lock and then asks the repository to load the class.

Forwards request to LoaderRepository.

Throws:
ClassNotFoundException

getResource

public URL getResource(String name)
Attempts to load the resource from its URL and if not found forwards to the request to LoaderRepository.


findResources

public Enumeration findResources(String name)
                          throws IOException
Find all resource URLs for the given name. This overrides the URLClassLoader version to look for resources in the repository.

Parameters:
name - the name of the resource
Returns:
Enumeration
Throws:
IOException

findResourcesLocally

public Enumeration findResourcesLocally(String name)
                                 throws IOException
Provides the same functionality as URLClassLoader.findResources(java.lang.String).

Throws:
IOException

hashCode

public final int hashCode()
This is here to document that this must delegate to the super implementation to perform identity based hashing. Using URL based hashing caused conflicts with the Class.forName(String, boolean, ClassLoader).


equals

public final boolean equals(Object other)
This is here to document that this must delegate to the super implementation to perform identity based equality. Using URL based equality caused conflicts with the Class.forName(String, boolean, ClassLoader).


getAllURLs

public URL[] getAllURLs()
Return all library URLs associated with this UnifiedClassLoader

Do not remove this method without running the WebIntegrationTestSuite


getURLs

public URL[] getURLs()
Return an empty URL array to force the RMI marshalling subsystem to use the java.server.codebase property as the annotated codebase.

Do not remove this method without discussing it on the dev list.

Returns:
Empty URL[]

getPackage

public Package getPackage(String name)

getPackages

public Package[] getPackages()

toString

public String toString()
Retruns a string representaion of this UCL.


findClass

protected Class findClass(String name)
                   throws ClassNotFoundException
Called by loadClassLocally to find the requested class within this class loaders class path.

Parameters:
name - the name of the class
Returns:
the resulting class
Throws:
ClassNotFoundException - if the class could not be found

definePackage

protected void definePackage(String className)
Define the package for the class if not already done

Parameters:
className - the class name

getPermissions

protected PermissionCollection getPermissions(CodeSource cs)
Override the permissions accessor to use the CodeSource based on the original URL if one exists. This allows the security policy to be defined in terms of the static URL namespace rather than the local copy or nested URL. This builds a PermissionCollection from: 1. The origURL CodeSource 2. The argument CodeSource 3. The Policy.getPermission(origURL CodeSource) This is necessary because we cannot define the CodeSource the SecureClassLoader uses to register the class under.

Parameters:
cs - the location and signatures of the codebase.

getProtectionDomain

protected ProtectionDomain getProtectionDomain()
Determine the protection domain. If we are a copy of the original deployment, use the original url as the codebase.

Returns:
the protection domain

getProtectionDomain

protected ProtectionDomain getProtectionDomain(URL codesourceUrl)
Determine the protection domain. If we are a copy of the original deployment, use the original url as the codebase.

Returns:
the protection domain

loadByteCode

protected byte[] loadByteCode(String classname)
                       throws ClassNotFoundException,
                              IOException
Obtain the bytecode for the indicated class from this class loaders classpath.

Parameters:
classname -
Returns:
the bytecode array if found
Throws:
ClassNotFoundException - - if the class resource could not be found
IOException


Copyright © 2002 JBoss Group, LLC. All Rights Reserved.