JBossMX Parent POM 6.0.0.GA

org.jboss.mx.loading
Class RepositoryClassLoader

java.lang.Object
  extended by java.lang.ClassLoader
      extended by java.security.SecureClassLoader
          extended by java.net.URLClassLoader
              extended by org.jboss.mx.loading.RepositoryClassLoader
All Implemented Interfaces:
org.jboss.classloading.spi.RealClassLoader, org.jboss.util.loading.Translatable
Direct Known Subclasses:
UnifiedClassLoader

public abstract class RepositoryClassLoader
extends URLClassLoader
implements org.jboss.classloading.spi.RealClassLoader

A RepositoryClassLoader.

Version:
$Revision: 86129 $
Author:
Adrian Brock

Field Summary
protected  int loadClassDepth
          A debugging variable used to track the recursive depth of loadClass()
protected  ReentrantLock loadLock
          Lock
protected  ClassLoader parent
          The parent classloader
protected  LoaderRepository repository
          Reference to the repository.
protected  Exception unregisterTrace
          The location where unregister is called from
 
Constructor Summary
protected RepositoryClassLoader(URL[] urls, ClassLoader parent)
          Create a new LoaderRepositoryClassLoader
 
Method Summary
protected  void acquire()
          Acquire the class loading lock.
 void addToClassBlackList(String name)
          Black list a class
 void addToResourceBlackList(String name)
          Black list a resource
 void addURL(URL url)
          Append the given url to the URLs used for class and resource loading
protected  boolean attempt(long waitMS)
          Attempt to acquire the class loading lock.
 void clearBlackList(String name)
           
 void clearBlacklists()
          Clear all blacklists
 void clearClassBlackList()
          Clear any class black list.
 void clearResourceBlackList()
          Clear any resource blacklist.
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.
protected  Class<?> findClassLocally(String name)
          Find the class
 Enumeration<URL> findResources(String name)
          Find all resource URLs for the given name.
 Enumeration<URL> findResourcesLocally(String name)
          Provides the same functionality as URLClassLoader.findResources(java.lang.String).
 int getAddedOrder()
          Get the order this classloader was added to the repository
 URL[] getAllURLs()
          Return all library URLs associated with this RepositoryClassLoader
 Class<?> getCachedClass(String name)
           
 URL getCachedResource(String name)
           
 URL[] getClasspath()
          This method simply invokes the super.getURLs() method to access the list of URLs that make up the RepositoryClassLoader classpath.
 LoaderRepository getLoaderRepository()
          Get the loader repository for this classloader
abstract  ObjectName getObjectName()
          Get the ObjectName
 Package getPackage(String name)
           
 Package[] getPackages()
           
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)
           
 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.
 boolean isClassBlackListed(String name)
          Is the class black listed?
 boolean isResourceBlackListed(String name)
          Is the resource black listed?
 boolean isValid()
           
protected  byte[] loadByteCode(String classname)
          Obtain the bytecode for the indicated class from this class loaders classpath.
protected  byte[] loadByteCode(URL classURL)
          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<?> loadClassBefore(String name)
          The only caller of this method should be the VM initiated loadClassInternal() method.
abstract  Class<?> loadClassImpl(String name, boolean resolve, int stopAt)
           
 Class<?> loadClassLocally(String name, boolean resolve)
           
protected  void release()
          Release the class loading lock previous acquired through the acquire method.
 void removeFromClassBlackList(String name)
          Remove class from black list
 void removeFromResourceBlackList(String name)
          Remove resource from black list
 void setAddedOrder(int addedOrder)
          Set the order this classloader was added to the repository
 void setRepository(LoaderRepository repository)
          Set the loader repository
 String toString()
          Returns a string representation.
 void unregister()
           
 
Methods inherited from class java.net.URLClassLoader
definePackage, findResource, getPermissions, newInstance, newInstance
 
Methods inherited from class java.security.SecureClassLoader
defineClass, defineClass
 
Methods inherited from class java.lang.ClassLoader
clearAssertionStatus, defineClass, 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 repository.


unregisterTrace

protected Exception unregisterTrace
The location where unregister is called from


parent

protected ClassLoader parent
The parent classloader


loadLock

protected ReentrantLock loadLock
Lock


loadClassDepth

protected int loadClassDepth
A debugging variable used to track the recursive depth of loadClass()

Constructor Detail

RepositoryClassLoader

protected RepositoryClassLoader(URL[] urls,
                                ClassLoader parent)
Create a new LoaderRepositoryClassLoader

Parameters:
urls - the urls
parent - the parent classloader
Method Detail

getObjectName

public abstract ObjectName getObjectName()
Get the ObjectName

Specified by:
getObjectName in interface org.jboss.classloading.spi.RealClassLoader
Returns:
the object name

isValid

public boolean isValid()
Specified by:
isValid in interface org.jboss.classloading.spi.RealClassLoader

getLoaderRepository

public LoaderRepository getLoaderRepository()
Get the loader repository for this classloader

Returns:
the loader repository

setRepository

public void setRepository(LoaderRepository repository)
Set the loader repository

Parameters:
repository - the repository

getCachedClass

public Class<?> getCachedClass(String name)
Specified by:
getCachedClass in interface org.jboss.classloading.spi.RealClassLoader

getCachedResource

public URL getCachedResource(String name)
Specified by:
getCachedResource in interface org.jboss.classloading.spi.RealClassLoader

clearBlackList

public void clearBlackList(String name)
Specified by:
clearBlackList in interface org.jboss.classloading.spi.RealClassLoader

getAddedOrder

public int getAddedOrder()
Get the order this classloader was added to the repository

Returns:
the order

setAddedOrder

public void setAddedOrder(int addedOrder)
Set the order this classloader was added to the repository

Parameters:
addedOrder - the added order

loadClassLocally

public Class<?> loadClassLocally(String name,
                                 boolean resolve)
                          throws ClassNotFoundException
Throws:
ClassNotFoundException

getResourceLocally

public URL getResourceLocally(String name)
Specified by:
getResourceLocally in interface org.jboss.util.loading.Translatable

getURL

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

Returns:
the url

unregister

public void unregister()

getClasspath

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

Returns:
the urls that make up the classpath

getAllURLs

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

Do not remove this method without running the WebIntegrationTestSuite

Returns:
the urls

addToClassBlackList

public void addToClassBlackList(String name)
Black list a class

Parameters:
name - the name of the class

removeFromClassBlackList

public void removeFromClassBlackList(String name)
Remove class from black list

Parameters:
name - the name of the class

isClassBlackListed

public boolean isClassBlackListed(String name)
Is the class black listed?

Parameters:
name - the name of the class
Returns:
true when the class is black listed, false otherwise

clearClassBlackList

public void clearClassBlackList()
Clear any class black list.


addToResourceBlackList

public void addToResourceBlackList(String name)
Black list a resource

Parameters:
name - the name of the resource

removeFromResourceBlackList

public void removeFromResourceBlackList(String name)
Remove resource from black list

Parameters:
name - the name of the resource

isResourceBlackListed

public boolean isResourceBlackListed(String name)
Is the resource black listed?

Parameters:
name - the name of the resource
Returns:
true when the resource is black listed, false otherwise

clearResourceBlackList

public void clearResourceBlackList()
Clear any resource blacklist.


clearBlacklists

public void clearBlacklists()
Clear all blacklists


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.

Overrides:
loadClass in class ClassLoader
Throws:
ClassNotFoundException

loadClassBefore

public Class<?> loadClassBefore(String name)
                         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.

Parameters:
name - the class name
Returns:
the class
Throws:
ClassNotFoundException - when the class is not found

loadClassImpl

public abstract Class<?> loadClassImpl(String name,
                                       boolean resolve,
                                       int stopAt)
                                throws ClassNotFoundException
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.

Overrides:
getResource in class ClassLoader

findResources

public Enumeration<URL> 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.

Overrides:
findResources in class URLClassLoader
Parameters:
name - the name of the resource
Returns:
Enumeration
Throws:
IOException

findResourcesLocally

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

Parameters:
name - the resource name
Returns:
the found resources
Throws:
IOException - for an error accessing the resources

findClass

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

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

findClassLocally

protected Class<?> findClassLocally(String name)
                             throws ClassNotFoundException
Find the class

Parameters:
name - the name of the class
Returns:
the class
Throws:
ClassNotFoundException - when the class is not found

definePackage

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

Parameters:
className - the class name

addURL

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

Overrides:
addURL in class URLClassLoader
Parameters:
url - the URL to load from

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.

Overrides:
getURLs in class URLClassLoader
Returns:
Empty URL[]

getPackage

public Package getPackage(String name)
Overrides:
getPackage in class ClassLoader

getPackages

public Package[] getPackages()
Overrides:
getPackages in class 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).

Overrides:
equals in class Object

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).

Overrides:
hashCode in class Object

toString

public String toString()
Returns a string representation.

Overrides:
toString in class Object

attempt

protected boolean attempt(long waitMS)
Attempt to acquire the class loading lock. This lock must be acquired before a thread enters the class loading task loop in loadClass. This method maintains any interrupted state of the calling thread.

Parameters:
waitMS - the length of time to wait in milliseconds
Returns:
true when the lock was obtained
See Also:
loadClass(String, boolean)

acquire

protected void acquire()
Acquire the class loading lock. This lock must be acquired before a thread enters the class loading task loop in loadClass.

See Also:
loadClass(String, boolean)

release

protected void release()
Release the class loading lock previous acquired through the acquire method.


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 - when there is an error loading the class bytes

loadByteCode

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

Parameters:
classURL -
Returns:
the bytecode array if found
Throws:
ClassNotFoundException - - if the class resource could not be found
IOException - when there is an error loading the class bytes

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.

Parameters:
codesourceUrl - the codesource url
Returns:
the protection domain

JBossMX Parent POM 6.0.0.GA

Copyright © 2012 JBoss, a division of Red Hat, Inc.. All Rights Reserved.