Package org.jboss.modules
Class ConcurrentClassLoader
- java.lang.Object
-
- java.lang.ClassLoader
-
- org.jboss.modules.ConcurrentClassLoader
-
- Direct Known Subclasses:
ModuleClassLoader
public abstract class ConcurrentClassLoader extends java.lang.ClassLoaderA 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.
-
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.ClassLoaderdefiningLoaderprotected static java.util.Enumeration<java.net.URL>EMPTY_ENUMERATIONAn empty enumeration, for subclasses to use if desired.private static java.lang.ThreadLocal<java.lang.Boolean>GET_PACKAGE_SUPPRESSORprivate UnlockedReadHashMap<java.lang.String,java.lang.Package>packages
-
Constructor Summary
Constructors Modifier Constructor Description protectedConcurrentClassLoader()Construct a new instance, using our class loader as the parent.protectedConcurrentClassLoader(ConcurrentClassLoader parent)Construct a new instance with the given parent class loader, which must be a concurrent class loader, ornullto create a root concurrent class loader.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.lang.Class<?>defineOrLoadClass(java.lang.String className, byte[] bytes, int off, int len)Atomically define or load the named class.protected java.lang.Class<?>defineOrLoadClass(java.lang.String className, byte[] bytes, int off, int len, java.security.ProtectionDomain protectionDomain)Atomically define or load the named class.protected java.lang.PackagedefinePackage(java.lang.String name, java.lang.String specTitle, java.lang.String specVersion, java.lang.String specVendor, java.lang.String implTitle, java.lang.String implVersion, java.lang.String implVendor, java.net.URL sealBase)Defines a package by name in this ConcurrentClassLoader.protected java.lang.Class<?>findClass(java.lang.String className)Implementation ofClassLoader.findClass(String).protected java.lang.Class<?>findClass(java.lang.String className, boolean exportsOnly, boolean resolve)Find a class, possibly delegating to other loader(s).protected java.lang.PackagefindLoadedPackage(java.lang.String name)Load a package from this class loader only.protected java.net.URLfindResource(java.lang.String name)Never used.protected java.net.URLfindResource(java.lang.String name, boolean exportsOnly)Find the resource with the given name and exported status.protected java.io.InputStreamfindResourceAsStream(java.lang.String name, boolean exportsOnly)Finds the resource with the given name and exported status, returning the resource content as a stream.protected java.util.Enumeration<java.net.URL>findResources(java.lang.String name)Never used.protected java.util.Enumeration<java.net.URL>findResources(java.lang.String name, boolean exportsOnly)Finds the resources with the given name and exported status.protected java.lang.PackagegetPackage(java.lang.String name)Load a package which is visible to this class loader.protected java.lang.PackagegetPackageByName(java.lang.String name)Perform the actual work to load a package which is visible to this class loader.protected java.lang.Package[]getPackages()Get all defined packages which are visible to this class loader.java.net.URLgetResource(java.lang.String name)Finds the resource with the given name.java.io.InputStreamgetResourceAsStream(java.lang.String name)Returns an input stream for reading the specified resource.java.util.Enumeration<java.net.URL>getResources(java.lang.String name)Finds all available resources with the given name.java.lang.Class<?>loadClass(java.lang.String className)Loads the class with the specified binary name.java.lang.Class<?>loadClass(java.lang.String className, boolean resolve)Loads the class with the specified binary name.java.lang.Class<?>loadExportedClass(java.lang.String className)Same asloadClass(String), except only exported classes will be considered.java.lang.Class<?>loadExportedClass(java.lang.String className, boolean resolve)Same asloadClass(String,boolean), except only exported classes will be considered.private java.lang.Class<?>performLoadClass(java.lang.String className, boolean exportsOnly, boolean resolve)Perform a class load operation.private java.lang.Class<?>performLoadClassUnchecked(java.lang.String className, boolean exportsOnly, boolean resolve)-
Methods inherited from class java.lang.ClassLoader
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, findClass, findLibrary, findLoadedClass, findResource, findSystemClass, getClassLoadingLock, getDefinedPackage, getDefinedPackages, getName, getParent, getPlatformClassLoader, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, getUnnamedModule, isRegisteredAsParallelCapable, registerAsParallelCapable, resolveClass, resources, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
-
-
-
-
Field Detail
-
definingLoader
private static final java.lang.ClassLoader definingLoader
-
GET_PACKAGE_SUPPRESSOR
private static final java.lang.ThreadLocal<java.lang.Boolean> GET_PACKAGE_SUPPRESSOR
-
EMPTY_ENUMERATION
protected static final java.util.Enumeration<java.net.URL> EMPTY_ENUMERATION
An empty enumeration, for subclasses to use if desired.
-
packages
private final UnlockedReadHashMap<java.lang.String,java.lang.Package> packages
-
-
Constructor Detail
-
ConcurrentClassLoader
protected ConcurrentClassLoader(ConcurrentClassLoader parent)
Construct a new instance with the given parent class loader, which must be a concurrent class loader, ornullto create a root concurrent class loader.- Parameters:
parent- the parent class loader
-
ConcurrentClassLoader
protected ConcurrentClassLoader()
Construct a new instance, using our class loader as the parent.
-
-
Method Detail
-
loadClass
public final java.lang.Class<?> loadClass(java.lang.String className) throws java.lang.ClassNotFoundExceptionLoads the class with the specified binary name. Equivalent to callingloadClass(className, false).- Overrides:
loadClassin classjava.lang.ClassLoader- Parameters:
className- The binary name of the class- Returns:
- the resulting
Classinstance - Throws:
java.lang.ClassNotFoundException- if the class was not found
-
loadClass
public final java.lang.Class<?> loadClass(java.lang.String className, boolean resolve) throws java.lang.ClassNotFoundExceptionLoads the class with the specified binary name.- Overrides:
loadClassin classjava.lang.ClassLoader- Parameters:
className- The binary name of the classresolve-trueif the class should be linked after loading- Returns:
- the resulting
Classinstance - Throws:
java.lang.ClassNotFoundException
-
loadExportedClass
public final java.lang.Class<?> loadExportedClass(java.lang.String className) throws java.lang.ClassNotFoundExceptionSame asloadClass(String), except only exported classes will be considered.- Parameters:
className- the class name- Returns:
- the class
- Throws:
java.lang.ClassNotFoundException- if the class isn't found
-
loadExportedClass
public final java.lang.Class<?> loadExportedClass(java.lang.String className, boolean resolve) throws java.lang.ClassNotFoundExceptionSame asloadClass(String,boolean), except only exported classes will be considered.- Parameters:
className- the class nameresolve-trueif the class should be linked after loading- Returns:
- the class
- Throws:
java.lang.ClassNotFoundException- if the class isn't found
-
findClass
protected java.lang.Class<?> findClass(java.lang.String className, boolean exportsOnly, boolean resolve) throws java.lang.ClassNotFoundExceptionFind 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 throwsClassNotFoundException.If a class is to be defined by this method, it should be done via one of the atomic
defineOrLoadClassmethods rather thandefineClass()in order to avoid spurious exceptions.- Parameters:
className- the class nameexportsOnly-trueif only exported classes should be consideredresolve-trueif the class should be linked after loading- Returns:
- the class
- Throws:
java.lang.ClassNotFoundException- if the class is not found
-
defineOrLoadClass
protected final java.lang.Class<?> defineOrLoadClass(java.lang.String className, byte[] bytes, int off, int len)Atomically define or load the named class. If the class is already defined, the existing class is returned.- Parameters:
className- the class name to define or loadbytes- the bytes to use to define the classoff- the offset into the byte array at which the class bytes beginlen- the number of bytes in the class- Returns:
- the class
-
defineOrLoadClass
protected final java.lang.Class<?> defineOrLoadClass(java.lang.String className, byte[] bytes, int off, int len, java.security.ProtectionDomain protectionDomain)Atomically define or load the named class. If the class is already defined, the existing class is returned.- Parameters:
className- the class name to define or loadbytes- the bytes to use to define the classoff- the offset into the byte array at which the class bytes beginlen- the number of bytes in the classprotectionDomain- the protection domain for the defined class- Returns:
- the class
-
findClass
protected final java.lang.Class<?> findClass(java.lang.String className) throws java.lang.ClassNotFoundExceptionImplementation ofClassLoader.findClass(String).- Overrides:
findClassin classjava.lang.ClassLoader- Parameters:
className- the class name- Returns:
- the result of
findClass(className, false, false) - Throws:
java.lang.ClassNotFoundException
-
getResource
public final java.net.URL getResource(java.lang.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 tofindResource(String, boolean).- Overrides:
getResourcein classjava.lang.ClassLoader- Parameters:
name- the name of the resource- Returns:
- the resource URL, or
nullif no such resource exists or the invoker does not have adequate permission to access it
-
getResources
public final java.util.Enumeration<java.net.URL> getResources(java.lang.String name) throws java.io.IOExceptionFinds all available resources with the given name.- Overrides:
getResourcesin classjava.lang.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:
java.io.IOException- if an I/O error occurs- See Also:
getResource(String)
-
findResource
protected java.net.URL findResource(java.lang.String name, boolean exportsOnly)Find the resource with the given name and exported status.- Parameters:
name- the resource nameexportsOnly-trueto consider only exported resources orfalseto consider all resources- Returns:
- the resource URL
- See Also:
getResource(String)
-
findResource
protected final java.net.URL findResource(java.lang.String name)
Never used.ClassLoader.getResource(String)and related methods can cause a loop condition when this method is implemented; usefindResource(String, boolean)instead.- Overrides:
findResourcein classjava.lang.ClassLoader- Parameters:
name- ignored- Returns:
nullalways
-
findResources
protected java.util.Enumeration<java.net.URL> findResources(java.lang.String name, boolean exportsOnly) throws java.io.IOExceptionFinds the resources with the given name and exported status.- Parameters:
name- the resource nameexportsOnly-trueto consider only exported resources orfalseto consider all resources- Returns:
- the resource enumeration
- Throws:
java.io.IOException- if an I/O error occurs- See Also:
getResources(String)
-
findResources
protected final java.util.Enumeration<java.net.URL> findResources(java.lang.String name)
Never used.ClassLoader.getResources(String)and related methods can cause a loop condition when this method is implemented; usefindResources(String, boolean)instead. By default, returns an empty enumeration.- Overrides:
findResourcesin classjava.lang.ClassLoader- Parameters:
name- ignored- Returns:
- an empty enumeration
-
findResourceAsStream
protected java.io.InputStream findResourceAsStream(java.lang.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 nameexportsOnly-trueto consider only exported resources orfalseto consider all resources- Returns:
- the resource stream, or
nullif the resource is not found
-
getResourceAsStream
public final java.io.InputStream getResourceAsStream(java.lang.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 tofindResourceAsStream(String, boolean).- Overrides:
getResourceAsStreamin classjava.lang.ClassLoader- Parameters:
name- the resource name- Returns:
- the resource stream, or
nullif the resource is not found
-
performLoadClass
private java.lang.Class<?> performLoadClass(java.lang.String className, boolean exportsOnly, boolean resolve) throws java.lang.ClassNotFoundExceptionPerform a class load operation. If the class is in the package or a subpackage of a package in the system packages list, the parent class loader is used to load the class. Otherwise, this method checks to see if the class loader object is locked; if so, it unlocks it and submits the request to the class loader thread. Otherwise, it will load the class itself by delegating tofindClass(String, boolean, boolean).- Parameters:
className- the class nameexportsOnly-trueto consider only exported resources orfalseto consider all resourcesresolve-trueto resolve the loaded class- Returns:
- the class returned by
findClass(String, boolean, boolean) - Throws:
java.lang.ClassNotFoundException- iffindClass(String, boolean, boolean)throws this exception
-
performLoadClassUnchecked
private java.lang.Class<?> performLoadClassUnchecked(java.lang.String className, boolean exportsOnly, boolean resolve) throws java.lang.ClassNotFoundException- Throws:
java.lang.ClassNotFoundException
-
getPackage
protected final java.lang.Package getPackage(java.lang.String name)
Load a package which is visible to this class loader.- Overrides:
getPackagein classjava.lang.ClassLoader- Parameters:
name- the package name- Returns:
- the package, or
nullif no such package is visible to this class loader
-
getPackageByName
protected java.lang.Package getPackageByName(java.lang.String name)
Perform the actual work to load a package which is visible to this class loader. By default, uses a simple parent-first delegation strategy.- Parameters:
name- the package name- Returns:
- the package, or
nullif no such package is visible to this class loader
-
getPackages
protected java.lang.Package[] getPackages()
Get all defined packages which are visible to this class loader.- Overrides:
getPackagesin classjava.lang.ClassLoader- Returns:
- the packages
-
findLoadedPackage
protected final java.lang.Package findLoadedPackage(java.lang.String name)
Load a package from this class loader only.- Parameters:
name- the package name- Returns:
- the package or
nullif no such package is defined by this class loader
-
definePackage
protected java.lang.Package definePackage(java.lang.String name, java.lang.String specTitle, java.lang.String specVersion, java.lang.String specVendor, java.lang.String implTitle, java.lang.String implVersion, java.lang.String implVendor, java.net.URL sealBase) throws java.lang.IllegalArgumentExceptionDefines a package by name in this ConcurrentClassLoader. If the package was already defined, the existing package is returned instead.- Overrides:
definePackagein classjava.lang.ClassLoader- Parameters:
name- the package namespecTitle- the specification titlespecVersion- the specification versionspecVendor- the specification vendorimplTitle- the implementation titleimplVersion- the implementation versionimplVendor- the implementation vendorsealBase- if notnull, then this package is sealed with respect to the given code source URL- Returns:
- the newly defined package, or the existing one if one was already defined
- Throws:
java.lang.IllegalArgumentException
-
-