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 class
ASURLClassLoader.SentinelInputStream
Wraps all InputStreams returned by this class loader to report when a finalizer is run before the stream has been closed.protected static class
ASURLClassLoader.URLEntry
URL 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 void
addDeclaredPermissions(PermissionCollection declaredPc)
Pass the declared permission collection from the module handler to the classloadervoid
addEEPermissions(PermissionCollection eePc)
Pass the EE permission to the classloadervoid
addTransformer(ClassFileTransformer transformer)
Add a new ClassFileTransformer to this class loader.void
addURL(URL url)
Appends the specified URL to the list of URLs to search for classes and resources.void
appendURL(File file)
Adds a URL to the search list, based on the specified File.void
appendURL(URL url)
Add a url to the list of urls we search for a class's bytecodes.ClassLoader
copy()
Create a new instance of a sibling classloadervoid
done()
This method should be called to free up the resources.protected Class
findClass(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.ClassData
findClassData(String name)
This method is responsible for locating the url from the class bytes have to be read and reading the bytes.URL
findResource(String name)
Enumeration<URL>
findResources(String name)
protected String
getClassLoaderName()
String
getClasspath()
Returns all the "file" protocol resources of this ASURLClassLoader, concatenated to a classpath string.protected PermissionCollection
getPermissions(CodeSource codeSource)
InputStream
getResourceAsStream(String name)
URL[]
getURLs()
Returns the urls of this class loader.boolean
isDone()
static AutoCloseable
mustLoadFrom(ClassLoader loader)
To be used when loading classes that are absolutely necessary for tha app to work, ignoring expensive negative lookups.void
preDestroy()
void
refresh()
Refreshes the memory of the class loader.String
toString()
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:
preDestroy
in 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:
addURL
in 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:
getURLs
in interfaceJasperAdapter
- Overrides:
getURLs
in 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:InstrumentableClassLoader
Add a new ClassFileTransformer to this class loader. This transformer should be called for each class loading event.- Specified by:
addTransformer
in 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:
copy
in 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:
findResource
in classURLClassLoader
-
findResources
public Enumeration<URL> findResources(String name)
- Overrides:
findResources
in classURLClassLoader
-
addEEPermissions
public void addEEPermissions(PermissionCollection eePc) throws SecurityException
Description copied from interface:DDPermissionsLoader
Pass the EE permission to the classloader- Specified by:
addEEPermissions
in 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:DDPermissionsLoader
Pass the declared permission collection from the module handler to the classloader- Specified by:
addDeclaredPermissions
in 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:
getPermissions
in 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:
findClass
in 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:
getResourceAsStream
in classURLClassLoader
-
-