Class ASURLClassLoader

All Implemented Interfaces:
JasperAdapter, DDPermissionsLoader, Closeable, AutoCloseable, org.glassfish.api.deployment.InstrumentableClassLoader, org.glassfish.hk2.api.PreDestroy

public class ASURLClassLoader extends GlassfishUrlClassLoader implements JasperAdapter, org.glassfish.api.deployment.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
  • Constructor Details

    • ASURLClassLoader

      public ASURLClassLoader()
      Constructor.
    • ASURLClassLoader

      public ASURLClassLoader(ClassLoader parent)
      Constructor.
      Parameters:
      parent - parent class loader
  • Method Details

    • isClosed

      public boolean isClosed()
    • preDestroy

      public void preDestroy()
      Specified by:
      preDestroy in interface org.glassfish.hk2.api.PreDestroy
    • close

      public void close() throws IOException
      This method should be called to free up the resources. It helps garbage collection. Must be synchronized for:
      1. visibility of variables
      2. race condition while checking 'doneCalled'
      3. only one caller should close the zip files,
      4. done should occur only once and set the flag when done.
      5. should not return 'true' when a previous thread might still be in the process of executing the method.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Overrides:
      close in class GlassfishUrlClassLoader
      Throws:
      IOException
    • 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 class URLClassLoader
      Parameters:
      url - the URL to be added to the search path of URLs
    • appendURL

      public void appendURL(URL url)
      Add an 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, 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 interface JasperAdapter
      Overrides:
      getURLs in class URLClassLoader
      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() throws IOException
      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

      public void addTransformer(ClassFileTransformer transformer)
      Specified by:
      addTransformer in interface org.glassfish.api.deployment.InstrumentableClassLoader
    • copy

      public ClassLoader copy()
      Create a new instance of a sibling classloader.
      Specified by:
      copy in interface org.glassfish.api.deployment.InstrumentableClassLoader
      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 class GlassfishUrlClassLoader
    • findResources

      public Enumeration<URL> findResources(String name) throws IOException
      Returns an enumeration of java.net.URL objects representing all the resources with the given name. This method is synchronized to avoid
      1. race condition checking 'doneCalled',
      2. changes to contents or length of 'resourcesList' and/or 'notFoundResources' while iterating over them,
      3. thread visibility to all of the above.
      Overrides:
      findResources in class GlassfishUrlClassLoader
      Throws:
      IOException
    • addEEPermissions

      public void addEEPermissions(PermissionCollection eePc) throws SecurityException
      Description copied from interface: DDPermissionsLoader
      Pass the EE permission to the classloader
      Specified by:
      addEEPermissions in interface DDPermissionsLoader
      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 interface DDPermissionsLoader
      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 class URLClassLoader
    • 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 overridden, and subclasses must be cautious (also) about thread safety.

      Overrides:
      findClass in class GlassfishUrlClassLoader
      Throws:
      ClassNotFoundException
    • getClassLoaderName

      protected String getClassLoaderName()
    • toString

      public String toString()
      Returns a string representation of this class loader
      Overrides:
      toString in class GlassfishUrlClassLoader
    • getResources

      public Enumeration<URL> getResources(String name) throws IOException
      Overrides:
      getResources in class ClassLoader
      Throws:
      IOException