Package com.sun.enterprise.loader
Class ASURLClassLoader
- java.lang.Object
-
- java.lang.ClassLoader
-
- java.security.SecureClassLoader
-
- java.net.URLClassLoader
-
- com.sun.enterprise.loader.CurrentBeforeParentClassLoader
-
- com.sun.enterprise.loader.ASURLClassLoader
-
- All Implemented Interfaces:
JasperAdapter,DDPermissionsLoader,Closeable,AutoCloseable,InstrumentableClassLoader,org.glassfish.hk2.api.PreDestroy
- Direct Known Subclasses:
ConnectorClassFinder,ConnectorClassLoader,EarClassLoader,EarLibClassLoader
public class ASURLClassLoader extends CurrentBeforeParentClassLoader implements JasperAdapter, InstrumentableClassLoader, org.glassfish.hk2.api.PreDestroy, DDPermissionsLoader
Class loader used by the ejbs of an application or stand alone module. 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 Classes Modifier and Type Class Description protected classASURLClassLoader.SentinelInputStreamWraps all InputStreams returned by this class loader to report when a finalizer is run before the stream has been closed.protected static classASURLClassLoader.URLEntryURL entry - keeps track of the url resources.
-
Field Summary
-
Fields inherited from class com.sun.enterprise.loader.CurrentBeforeParentClassLoader
currentBeforeParentEnabled, PARENT_CLASSLOADER_DELEGATE_PROPERTY
-
Fields inherited from interface com.sun.enterprise.security.integration.DDPermissionsLoader
SET_EE_POLICY
-
-
Constructor Summary
Constructors Constructor Description ASURLClassLoader()Constructor.ASURLClassLoader(ClassLoader parent)Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddDeclaredPermissions(PermissionCollection declaredPc)Pass the declared permission collection from the module handler to the classloadervoidaddEEPermissions(PermissionCollection eePc)Pass the EE permission to the classloadervoidaddTransformer(ClassFileTransformer transformer)Add a new ClassFileTransformer to this class loader.voidaddURL(URL url)Appends the specified URL to the list of URLs to search for classes and resources.voidappendURL(File file)Adds a URL to the search list, based on the specified File.voidappendURL(URL url)Add a url to the list of urls we search for a class's bytecodes.ClassLoadercopy()Create a new instance of a sibling classloadervoiddone()This method should be called to free up the resources.protected ClassfindClass(String name)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.protected com.sun.enterprise.loader.ASURLClassLoader.ClassDatafindClassData(String name)This method is responsible for locating the url from the class bytes have to be read and reading the bytes.URLfindResource(String name)Enumeration<URL>findResources(String name)protected StringgetClassLoaderName()StringgetClasspath()Returns all the "file" protocol resources of this ASURLClassLoader, concatenated to a classpath string.protected PermissionCollectiongetPermissions(CodeSource codeSource)InputStreamgetResourceAsStream(String name)URL[]getURLs()Returns the urls of this class loader.booleanisDone()static AutoCloseablemustLoadFrom(ClassLoader loader)To be used when loading classes that are absolutely necessary for tha app to work, ignoring expensive negative lookups.voidpreDestroy()voidrefresh()Refreshes the memory of the class loader.StringtoString()Returns a string representation of this class loader.-
Methods inherited from class com.sun.enterprise.loader.CurrentBeforeParentClassLoader
disableCurrentBeforeParent, enableCurrentBeforeParent, enableCurrentBeforeParentUnconditional, isWhiteListed, isWhitelistEnabled, loadClass
-
Methods inherited from class java.net.URLClassLoader
close, definePackage, newInstance, newInstance
-
Methods inherited from class java.security.SecureClassLoader
defineClass, defineClass
-
Methods inherited from class java.lang.ClassLoader
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findClass, findLibrary, findLoadedClass, findResource, findSystemClass, getClassLoadingLock, getDefinedPackage, getDefinedPackages, getName, getPackage, getPackages, getParent, getPlatformClassLoader, getResource, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, getUnnamedModule, isRegisteredAsParallelCapable, loadClass, registerAsParallelCapable, resolveClass, resources, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
-
-
-
-
Constructor Detail
-
ASURLClassLoader
public ASURLClassLoader()
Constructor.
-
ASURLClassLoader
public ASURLClassLoader(ClassLoader parent)
Constructor.- Parameters:
parent- parent class loader
-
-
Method Detail
-
isDone
public boolean isDone()
-
preDestroy
public void preDestroy()
- Specified by:
preDestroyin interfaceorg.glassfish.hk2.api.PreDestroy
-
done
public void done()
This method should be called to free up the resources. It helps garbage collection. Must be synchronized for: (a) visibility of variables (b) race condition while checking 'doneCalled' (c) only one caller should close the zip files, (d) done should occur only once and set the flag when done. (e) shoudl not return 'true' when a previous thread might still be in the process of executing the method.
-
appendURL
public void appendURL(File file) throws IOException
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
public void addURL(URL url)
Appends the specified URL to the list of URLs to search for classes and resources.- Overrides:
addURLin classCurrentBeforeParentClassLoader- Parameters:
url- the URL to be added to the search path of URLs
-
appendURL
public void appendURL(URL url)
Add a url to the list of urls we search for a class's bytecodes.- Parameters:
url- url to be added
-
getURLs
public URL[] getURLs()
Returns the urls of this class loader. Method is 'synchronized' to avoid the thread-unsafe null-check idiom 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
public String 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
public void refresh()
Refreshes the memory of the class loader. This involves clearing the not-found cahces 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.
-
addTransformer
public void addTransformer(ClassFileTransformer transformer)
Description copied from interface:InstrumentableClassLoaderAdd a new ClassFileTransformer to this class loader. This transformer should be called for each class loading event.- Specified by:
addTransformerin interfaceInstrumentableClassLoader- Parameters:
transformer- new class file transformer to do byte code enhancement.
-
mustLoadFrom
public static AutoCloseable mustLoadFrom(ClassLoader loader)
To be used when loading classes that are absolutely necessary for tha app to work, ignoring expensive negative lookups. Since DirWatched is being used, there is a possibility of a race condition when OS doesn't deliver file creation events fast enough. This method will disable DirWatcher for lookups.- Parameters:
loader- instance which should be- Returns:
- AutoCloseable to be used with try-with-resources so the value gets reset when stack frame is existed
-
copy
public ClassLoader copy()
Create a new instance of a sibling classloader- Specified by:
copyin interfaceInstrumentableClassLoader- Returns:
- a new instance of a class loader that has the same visibility as this class loader
-
findResource
public URL findResource(String name)
- Overrides:
findResourcein classURLClassLoader
-
findResources
public Enumeration<URL> findResources(String name)
- Overrides:
findResourcesin classURLClassLoader
-
addEEPermissions
public void addEEPermissions(PermissionCollection eePc) throws SecurityException
Description copied from interface:DDPermissionsLoaderPass the EE permission to the classloader- Specified by:
addEEPermissionsin interfaceDDPermissionsLoader- Parameters:
eePc- EE permissions throws AccessControlException if caller has no privilege- Throws:
SecurityException
-
addDeclaredPermissions
public void addDeclaredPermissions(PermissionCollection declaredPc) throws SecurityException
Description copied from interface:DDPermissionsLoaderPass the declared permission collection from the module handler to the classloader- Specified by:
addDeclaredPermissionsin interfaceDDPermissionsLoader- Parameters:
declaredPc- the declared permission collection obtained from permissions.xml file throws AccessControlException if caller has no privilege- Throws:
SecurityException
-
getPermissions
protected PermissionCollection getPermissions(CodeSource codeSource)
- Overrides:
getPermissionsin classURLClassLoader
-
findClass
protected Class findClass(String name) throws ClassNotFoundException
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 overriden, and subclasses must be cautious (also) about thread safety.- Overrides:
findClassin classURLClassLoader- Throws:
ClassNotFoundException
-
findClassData
protected com.sun.enterprise.loader.ASURLClassLoader.ClassData findClassData(String name) throws ClassNotFoundException
This method is responsible for locating the url from the class bytes have to be read and reading the bytes. It does not actually define the Class object.To preclude a race condition on checking 'doneCalled', as well as transient errors if done() is called while running, this method is 'synchronized'.
- Parameters:
name- class name in java.lang.Object format- Returns:
- class bytes as well protection domain information
- Throws:
ClassNotFoundException
-
getClassLoaderName
protected String getClassLoaderName()
-
toString
public String toString()
Returns a string representation of this class loader.
-
getResourceAsStream
public InputStream getResourceAsStream(String name)
- Overrides:
getResourceAsStreamin classURLClassLoader
-
-