Class AbstractJPPFClassLoader

All Implemented Interfaces:
Closeable, AutoCloseable
Direct Known Subclasses:
JPPFClassLoader, JPPFLocalClassLoader

public abstract class AbstractJPPFClassLoader extends AbstractJPPFClassLoaderLifeCycle
This class is a custom class loader serving the purpose of dynamically loading the JPPF classes and the client application classes, to avoid costly redeployment system-wide.
Author:
Laurent Cohen
  • Constructor Details

    • AbstractJPPFClassLoader

      public AbstractJPPFClassLoader(ClassLoaderConnection<?> connection, ClassLoader parent, List<String> uuidPath, org.jppf.utils.hooks.HookFactory hookFactory)
      Initialize this class loader with a parent class loader.
      Parameters:
      connection - the connection to the driver.
      parent - a ClassLoader instance.
      uuidPath - unique identifier for the submitting application.
      hookFactory - a HookFactory instance.
  • Method Details

    • loadJPPFClass

      public Class<?> loadJPPFClass(String name) throws ClassNotFoundException
      Load a JPPF class from the server. This method bypasses the class loader delegation model and the URL classpath and attempts to load the class definition directly from the server.

      In principle, this method is only used to load the class that performs object serialization and deserialization, to ensure that classes available only remotely are properly downloaded from the server or client.

      Parameters:
      name - the binary name of the class
      Returns:
      the resulting Class object
      Throws:
      ClassNotFoundException - if the class could not be found
    • findClass

      protected Class<?> findClass(String name) throws ClassNotFoundException
      Find a class in this class loader's classpath.
      Overrides:
      findClass in class URLClassLoader
      Parameters:
      name - binary name of the resource to find.
      Returns:
      a defined Class instance.
      Throws:
      ClassNotFoundException - if the class could not be loaded.
      See Also:
    • findClass

      protected Class<?> findClass(String name, boolean lookupClasspath) throws ClassNotFoundException
      Find a class in this class loader's classpath.
      Parameters:
      name - binary name of the resource to find.
      lookupClasspath - specifies whether the class should be looked up in the URL classpath as well.
      Returns:
      a defined Class instance.
      Throws:
      ClassNotFoundException - if the class could not be loaded.
      See Also:
    • computeCallable

      public <V> V computeCallable(org.jppf.utils.JPPFCallable<V> callable) throws Exception
      Compute a value on the client-side, as the result of the execution of a JPPFCallable.

      Any Throwable raised in the callable's call() method will be thrown as the result of this method. If the Throwable is an instance of Exception or one of its subclasses, it is thrown as such, otherwise it is wrapped into a JPPFException.

      Type Parameters:
      V - the type of results returned by the callable.
      Parameters:
      callable - the callable to execute on the client side.
      Returns:
      the value computed on the client, or null if the value could not be computed.
      Throws:
      Exception - if the execution of the callable in the client resulted in a Throwable being raised.
    • computeRemoteData

      public byte[] computeRemoteData(byte[] callable) throws Exception
      Request the remote computation of a JPPFCallable on the client.
      Parameters:
      callable - the serialized callable to execute remotely.
      Returns:
      an array of bytes containing the result of the callable's execution.
      Throws:
      Exception - if the connection was lost and could not be reestablished.
    • findResource

      public URL findResource(String name)
      Finds the resource with the specified name. The resource lookup order is the same as the one specified by getResourceAsStream(String)
      Overrides:
      findResource in class URLClassLoader
      Parameters:
      name - the name of the resource to find.
      Returns:
      the URL of the resource.
    • getResourceAsStream

      public InputStream getResourceAsStream(String name)
      Get a stream from a resource file accessible from this class loader.
      Overrides:
      getResourceAsStream in class URLClassLoader
      Parameters:
      name - name of the resource to obtain a stream from.
      Returns:
      an InputStream instance, or null if the resource was not found.
    • findResources

      public Enumeration<URL> findResources(String name) throws IOException
      Find all resources with the specified name.
      Overrides:
      findResources in class URLClassLoader
      Parameters:
      name - name of the resources to find in the class loader's classpath.
      Returns:
      An enumeration of URLs pointing to the resources found.
      Throws:
      IOException - if an error occurs.
    • loadClass

      protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException
      Overrides:
      loadClass in class ClassLoader
      Throws:
      ClassNotFoundException
    • getDelegationModel

      public static org.jppf.classloader.DelegationModel getDelegationModel()
      Determine the class loading delegation model currently in use.
      Returns:
      an int value representing the model, either PARENT_FIRST or URL_FIRST.
    • setDelegationModel

      public static void setDelegationModel(org.jppf.classloader.DelegationModel model)
      Specify the class loading delegation model to use.
      Parameters:
      model - an int value, either PARENT_FIRST or URL_FIRST. If any other value is specified then calling this method has no effect.
    • clearNotFoundCache

      public void clearNotFoundCache()
      Clear the cache of resources not found. The main usage for this method is when libraries or folders have been dynamically added to this class loader's classpath.
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Overrides:
      close in class AbstractJPPFClassLoaderLifeCycle
    • fireEvent

      protected void fireEvent(Class<?> c, String name, boolean foundInURLClassPath)
      Notify all listeners that a class was either loaded or not found.
      Parameters:
      c - the class object if the class was successfully loaded, null otherwise.
      name - the name of the class if it was not found, this parameter is ignored if the class was found.
      foundInURLClassPath - true if the class was loaded from the class loader's URL classpath, false if it was loaded from a remote JPPF driver or client.
    • isClientClassLoader

      public boolean isClientClassLoader()
      Determine whether this class loader accesses the classpath of a remote client.
      Returns:
      true if this class loader is a client class loader, false if it is a server class loader.
    • isServerClassLoader

      public boolean isServerClassLoader()
      Determine whether this class loader accesses the classpath of a remote driver/server.
      Returns:
      true if this class loader is a server class loader, false if it is a client class loader.
    • getResource

      public URL getResource(String name)
      Overrides:
      getResource in class ClassLoader
    • getResources

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