Class ASURLClassLoader

    • 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 interface org.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 class CurrentBeforeParentClassLoader
        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 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()
        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.

      • 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 interface InstrumentableClassLoader
        Returns:
        a new instance of a class loader that has the same visibility as this class loader
      • 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 class URLClassLoader
        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.
        Overrides:
        toString in class Object
        Returns:
        a string representation of this class loader