Class ASURLClassLoader
- All Implemented Interfaces:
JasperAdapter,Closeable,AutoCloseable,org.glassfish.api.deployment.InstrumentableClassLoader,org.glassfish.hk2.api.PreDestroy
This class loader also keeps cache of not found classes and resources.
- Since:
- JDK 1.4
- Author:
- Nazrul Islam, Kenneth Saks, Sivakumar Thyagarajan
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static final classURL entry - keeps track of the url resources. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddTransformer(ClassFileTransformer transformer) voidAppends the specified URL to the list of URLs to search for classes and resources.voidAdds a URL to the search list, based on the specified File.voidAdd an url to the list of urls we search for a class's bytecodes.voidclose()This method should be called to free up the resources.copy()Create a new instance of a sibling classloader.protected Class<?> THREAD SAFETY: what happens when more than one thread requests the same class and thus works on the same classData?findResource(String name) findResources(String name) Returns an enumeration of java.net.URL objects representing all the resources with the given name.Returns all the "file" protocol resources of this ASURLClassLoader, concatenated to a classpath string.protected PermissionCollectiongetPermissions(CodeSource codeSource) getResources(String name) URL[]getURLs()Returns the urls of this class loader.booleanisClosed()voidvoidrefresh()Refreshes the memory of the class loader.toString()Returns a string representation of this class loaderMethods inherited from class org.glassfish.common.util.GlassfishUrlClassLoader
definePackage, getResourceAsStream, loadClassMethods inherited from class java.net.URLClassLoader
definePackage, newInstance, newInstanceMethods inherited from class java.security.SecureClassLoader
defineClass, defineClassMethods inherited from class java.lang.ClassLoader
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, findClass, findLibrary, findLoadedClass, findResource, findSystemClass, getClassLoadingLock, getDefinedPackage, getDefinedPackages, getName, getPackage, getPackages, getParent, getPlatformClassLoader, getResource, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, getUnnamedModule, isRegisteredAsParallelCapable, loadClass, registerAsParallelCapable, resolveClass, resources, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
-
Constructor Details
-
ASURLClassLoader
Constructor.- Parameters:
name-parent- parent class loader
-
-
Method Details
-
isClosed
public boolean isClosed() -
preDestroy
public void preDestroy()- Specified by:
preDestroyin interfaceorg.glassfish.hk2.api.PreDestroy
-
close
This method should be called to free up the resources. It helps garbage collection. Must be synchronized for:- visibility of variables
- race condition while checking 'doneCalled'
- only one caller should close the zip files,
- done should occur only once and set the flag when done.
- should not return 'true' when a previous thread might still be in the process of executing the method.
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classGlassfishUrlClassLoader- Throws:
IOException
-
appendURL
Adds a URL to the search list, based on the specified File.This variant of the method makes sure that the URL is valid, in particular encoding special characters (such as blanks) in the file path.
- Parameters:
file- the File to use in creating the URL- Throws:
IOException- in case of errors converting the file to a URL
-
addURL
Appends the specified URL to the list of URLs to search for classes and resources.- Overrides:
addURLin classGlassfishUrlClassLoader- Parameters:
url- the URL to be added to the search path of URLs
-
appendURL
Add an url to the list of urls we search for a class's bytecodes.- Parameters:
url- url to be added
-
getURLs
Returns the urls of this class loader.Method is
synchronizedto avoid the thread-unsafe null-check idiom, also protects the caller from simultaneous changes while iterating, by returning a URL[] (copy) rather than the original. Also protects against changes to 'urlSet' while iterating over it.- Specified by:
getURLsin interfaceJasperAdapter- Overrides:
getURLsin classURLClassLoader- Returns:
- the urls of this class loader or an empty array
-
getClasspath
Returns all the "file" protocol resources of this ASURLClassLoader, concatenated to a classpath string.Notice that this method is called by the setClassPath() method of org.apache.catalina.loader.WebappLoader, since this ASURLClassLoader does not extend off of URLClassLoader.
- Returns:
- Classpath string containing all the "file" protocol resources of this ASURLClassLoader
-
refresh
Refreshes the memory of the class loader. This involves clearing the not-found caches and recreating the hash tables for the URLEntries that record the files accessible for each.Code that creates an ASURLClassLoader and then adds files to a directory that is in the loader's classpath should invoke this method after the new file(s) have been added in order to update the class loader's data structures which optimize class and resource searches.
- Throws:
IOException- in case of errors refreshing the cache
-
addTransformer
- Specified by:
addTransformerin interfaceorg.glassfish.api.deployment.InstrumentableClassLoader
-
copy
Create a new instance of a sibling classloader.- Specified by:
copyin interfaceorg.glassfish.api.deployment.InstrumentableClassLoader- Returns:
- a new instance of a class loader that has the same visibility as this class loader
-
findResource
- Overrides:
findResourcein classGlassfishUrlClassLoader
-
findResources
Returns an enumeration of java.net.URL objects representing all the resources with the given name. This method is synchronized to avoid- race condition checking 'doneCalled',
- changes to contents or length of 'resourcesList' and/or 'notFoundResources' while iterating over them,
- thread visibility to all of the above.
- Overrides:
findResourcesin classGlassfishUrlClassLoader- Throws:
IOException
-
getPermissions
- Overrides:
getPermissionsin classURLClassLoader
-
findClass
THREAD SAFETY: what happens when more than one thread requests the same class and thus works on the same classData? Or defines the same package? Maybe the same work just gets done twice, and that's all.CAUTION: this method might be overridden, and subclasses must be cautious (also) about thread safety.
- Overrides:
findClassin classGlassfishUrlClassLoader- Throws:
ClassNotFoundException
-
toString
Returns a string representation of this class loader- Overrides:
toStringin classGlassfishUrlClassLoader
-
getResources
- Overrides:
getResourcesin classClassLoader- Throws:
IOException
-