org.jboss.modules
Class ConcurrentClassLoader

java.lang.Object
  extended by java.lang.ClassLoader
      extended by java.security.SecureClassLoader
          extended by org.jboss.modules.ConcurrentClassLoader
Direct Known Subclasses:
ModuleClassLoader

public abstract class ConcurrentClassLoader
extends SecureClassLoader

A classloader which can delegate to multiple other classloaders without risk of deadlock. A concurrent class loader should only ever be delegated to by another concurrent class loader; however a concurrent class loader may delegate to a standard hierarchical class loader. In other words, holding a lock on another class loader while invoking a method on this class loader may cause an unexpected deadlock.

Author:
David M. Lloyd

Field Summary
protected static Enumeration<URL> EMPTY_ENUMERATION
          An empty enumeration, for subclasses to use if desired.
 
Constructor Summary
protected ConcurrentClassLoader()
          Construct a new instance.
protected ConcurrentClassLoader(ConcurrentClassLoader parent)
          Construct a new instance with the given parent class loader, which must be a concurrent class loader.
 
Method Summary
protected  Class<?> findClass(String className)
          Implementation of ClassLoader.findClass(String).
protected  Class<?> findClass(String className, boolean exportsOnly, boolean resolve)
          Find a class, possibly delegating to other loader(s).
protected  URL findResource(String name)
          Never used.
protected  URL findResource(String name, boolean exportsOnly)
          Find the resource with the given name and exported status.
protected  InputStream findResourceAsStream(String name, boolean exportsOnly)
          Finds the resource with the given name and exported status, returning the resource content as a stream.
protected  Enumeration<URL> findResources(String name)
          Never used.
protected  Enumeration<URL> findResources(String name, boolean exportsOnly)
          Finds the resources with the given name and exported status.
 URL getResource(String name)
          Finds the resource with the given name.
 InputStream getResourceAsStream(String name)
          Returns an input stream for reading the specified resource.
 Enumeration<URL> getResources(String name)
          Finds all available resources with the given name.
 Class<?> loadClass(String className)
          Loads the class with the specified binary name.
 Class<?> loadClass(String className, boolean resolve)
          Loads the class with the specified binary name.
 Class<?> loadExportedClass(String className)
          Same as loadClass(String), except only exported classes will be considered.
 Class<?> loadExportedClass(String className, boolean resolve)
          Same as loadClass(String,boolean), except only exported classes will be considered.
 
Methods inherited from class java.security.SecureClassLoader
defineClass, defineClass, getPermissions
 
Methods inherited from class java.lang.ClassLoader
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findLibrary, findLoadedClass, findSystemClass, getPackage, getPackages, getParent, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, resolveClass, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EMPTY_ENUMERATION

protected static final Enumeration<URL> EMPTY_ENUMERATION
An empty enumeration, for subclasses to use if desired.

Constructor Detail

ConcurrentClassLoader

protected ConcurrentClassLoader(ConcurrentClassLoader parent)
Construct a new instance with the given parent class loader, which must be a concurrent class loader.

Parameters:
parent - the parent class loader

ConcurrentClassLoader

protected ConcurrentClassLoader()
Construct a new instance.

Method Detail

loadClass

public final Class<?> loadClass(String className)
                         throws ClassNotFoundException
Loads the class with the specified binary name. Equivalent to calling loadClass(className, false).

Overrides:
loadClass in class ClassLoader
Parameters:
className - The binary name of the class
Returns:
the resulting Class instance
Throws:
ClassNotFoundException - if the class was not found

loadClass

public final Class<?> loadClass(String className,
                                boolean resolve)
                         throws ClassNotFoundException
Loads the class with the specified binary name.

Overrides:
loadClass in class ClassLoader
Parameters:
className - The binary name of the class
resolve - true if the class should be linked after loading
Returns:
the resulting Class instance
Throws:
ClassNotFoundException

loadExportedClass

public final Class<?> loadExportedClass(String className)
                                 throws ClassNotFoundException
Same as loadClass(String), except only exported classes will be considered.

Parameters:
className - the class name
Returns:
the class
Throws:
ClassNotFoundException - if the class isn't found

loadExportedClass

public final Class<?> loadExportedClass(String className,
                                        boolean resolve)
                                 throws ClassNotFoundException
Same as loadClass(String,boolean), except only exported classes will be considered.

Parameters:
className - the class name
resolve - true if the class should be linked after loading
Returns:
the class
Throws:
ClassNotFoundException - if the class isn't found

findClass

protected Class<?> findClass(String className,
                             boolean exportsOnly,
                             boolean resolve)
                      throws ClassNotFoundException
Find a class, possibly delegating to other loader(s). This method should never synchronize across a delegation method call of any sort. The default implementation always throws ClassNotFoundException.

Parameters:
className - the class name
exportsOnly - true if only exported classes should be considered
resolve - true if the class should be linked after loading
Returns:
the class
Throws:
ClassNotFoundException - if the class is not found

findClass

protected final Class<?> findClass(String className)
                            throws ClassNotFoundException
Implementation of ClassLoader.findClass(String).

Overrides:
findClass in class ClassLoader
Parameters:
className - the class name
Returns:
the result of findClass(className, false, false)
Throws:
ClassNotFoundException

getResource

public final URL getResource(String name)
Finds the resource with the given name. The name of a resource is a '/'-separated path name that identifies the resource. If the resource name starts with "java/" then the parent class loader is used. Otherwise, this method delegates to findResource(String, boolean).

Overrides:
getResource in class ClassLoader
Parameters:
name - the name of the resource
Returns:
the resource URL, or null if no such resource exists or the invoker does not have adequate permission to access it

getResources

public final Enumeration<URL> getResources(String name)
                                    throws IOException
Finds all available resources with the given name.

Overrides:
getResources in class ClassLoader
Parameters:
name - the resource name
Returns:
an enumeration over all the resource URLs; if no resources could be found, the enumeration will be empty
Throws:
IOException - if an I/O error occurs
See Also:
getResource(String)

findResource

protected URL findResource(String name,
                           boolean exportsOnly)
Find the resource with the given name and exported status.

Parameters:
name - the resource name
exportsOnly - true to consider only exported resources or false to consider all resources
Returns:
the resource URL
See Also:
getResource(String)

findResource

protected final URL findResource(String name)
Never used. ClassLoader.getResource(String) and related methods can cause a loop condition when this method is implemented; use findResource(String, boolean) instead.

Overrides:
findResource in class ClassLoader
Parameters:
name - ignored
Returns:
null always

findResources

protected Enumeration<URL> findResources(String name,
                                         boolean exportsOnly)
                                  throws IOException
Finds the resources with the given name and exported status.

Parameters:
name - the resource name
exportsOnly - true to consider only exported resources or false to consider all resources
Returns:
the resource enumeration
Throws:
IOException - if an I/O error occurs
See Also:
getResources(String)

findResources

protected final Enumeration<URL> findResources(String name)
Never used. ClassLoader.getResources(String) and related methods can cause a loop condition when this method is implemented; use findResources(String, boolean) instead. By default, returns an empty enumeration.

Overrides:
findResources in class ClassLoader
Parameters:
name - ignored
Returns:
an empty enumeration

findResourceAsStream

protected InputStream findResourceAsStream(String name,
                                           boolean exportsOnly)
Finds the resource with the given name and exported status, returning the resource content as a stream.

Parameters:
name - the resource name
exportsOnly - true to consider only exported resources or false to consider all resources
Returns:
the resource stream, or null if the resource is not found

getResourceAsStream

public final InputStream getResourceAsStream(String name)
Returns an input stream for reading the specified resource. If the resource starts with "java/", then this method delegates to the parent class loader. Otherwise, this method delegates to findResourceAsStream(String, boolean).

Overrides:
getResourceAsStream in class ClassLoader
Parameters:
name - the resource name
Returns:
the resource stream, or null if the resource is not found


Copyright © 2011. All Rights Reserved.