Package org.jppf.classloader
Class AbstractJPPFClassLoader
java.lang.Object
java.lang.ClassLoader
java.security.SecureClassLoader
java.net.URLClassLoader
org.jppf.classloader.AbstractJPPFClassLoaderLifeCycle
org.jppf.classloader.AbstractJPPFClassLoader
- All Implemented Interfaces:
Closeable,AutoCloseable
- Direct Known Subclasses:
JPPFClassLoader,JPPFLocalClassLoader
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
-
Field Summary
Fields inherited from class org.jppf.classloader.AbstractJPPFClassLoaderLifeCycle
connection, dynamic, hookFactory, instanceNumber, notFoundCache, offline, remoteClassLoadingDisabled, resourceCache, uuidPath -
Constructor Summary
ConstructorsConstructorDescriptionAbstractJPPFClassLoader(ClassLoaderConnection<?> connection, ClassLoader parent, List<String> uuidPath, org.jppf.utils.hooks.HookFactory hookFactory) Initialize this class loader with a parent class loader. -
Method Summary
Modifier and TypeMethodDescriptionvoidClear the cache of resources not found.voidclose()<V> VcomputeCallable(org.jppf.utils.JPPFCallable<V> callable) Compute a value on the client-side, as the result of the execution of aJPPFCallable.byte[]computeRemoteData(byte[] callable) Request the remote computation of aJPPFCallableon the client.protected Class<?>Find a class in this class loader's classpath.protected Class<?>Find a class in this class loader's classpath.findResource(String name) Finds the resource with the specified name.findResources(String name) Find all resources with the specified name.protected voidNotify all listeners that a class was either loaded or not found.static org.jppf.classloader.DelegationModelDetermine the class loading delegation model currently in use.getResource(String name) getResourceAsStream(String name) Get a stream from a resource file accessible from this class loader.getResources(String name) booleanDetermine whether this class loader accesses the classpath of a remote client.booleanDetermine whether this class loader accesses the classpath of a remote driver/server.protected Class<?>Class<?>loadJPPFClass(String name) Load a JPPF class from the server.static voidsetDelegationModel(org.jppf.classloader.DelegationModel model) Specify the class loading delegation model to use.Methods inherited from class org.jppf.classloader.AbstractJPPFClassLoaderLifeCycle
addURL, findMultipleResources, getClientUuid, getConnection, getHookFactory, getMultipleResources, getResourceCache, init, isOffline, isRemoteClassLoadingDisabled, loadResource, reset, resetResourceCache, setRemoteClassLoadingDisabled, toStringMethods inherited from class java.net.URLClassLoader
definePackage, getPermissions, getURLs, newInstance, newInstanceMethods inherited from class java.security.SecureClassLoader
defineClass, defineClassMethods 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, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, getUnnamedModule, isRegisteredAsParallelCapable, loadClass, registerAsParallelCapable, resolveClass, resources, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
-
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- aHookFactoryinstance.
-
-
Method Details
-
loadJPPFClass
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
Find a class in this class loader's classpath.- Overrides:
findClassin classURLClassLoader- Parameters:
name- binary name of the resource to find.- Returns:
- a defined
Classinstance. - Throws:
ClassNotFoundException- if the class could not be loaded.- See Also:
-
findClass
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
Classinstance. - Throws:
ClassNotFoundException- if the class could not be loaded.- See Also:
-
computeCallable
Compute a value on the client-side, as the result of the execution of aJPPFCallable.Any
Throwableraised in the callable'scall()method will be thrown as the result of this method. If the Throwable is an instance ofExceptionor one of its subclasses, it is thrown as such, otherwise it is wrapped into aJPPFException.- 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 aThrowablebeing raised.
-
computeRemoteData
Request the remote computation of aJPPFCallableon 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
Finds the resource with the specified name. The resource lookup order is the same as the one specified bygetResourceAsStream(String)- Overrides:
findResourcein classURLClassLoader- Parameters:
name- the name of the resource to find.- Returns:
- the URL of the resource.
-
getResourceAsStream
Get a stream from a resource file accessible from this class loader.- Overrides:
getResourceAsStreamin classURLClassLoader- Parameters:
name- name of the resource to obtain a stream from.- Returns:
- an
InputStreaminstance, or null if the resource was not found.
-
findResources
Find all resources with the specified name.- Overrides:
findResourcesin classURLClassLoader- 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
- Overrides:
loadClassin classClassLoader- 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_FIRSTorURL_FIRST.
-
setDelegationModel
public static void setDelegationModel(org.jppf.classloader.DelegationModel model) Specify the class loading delegation model to use.- Parameters:
model- an int value, eitherPARENT_FIRSTorURL_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:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classAbstractJPPFClassLoaderLifeCycle
-
fireEvent
Notify all listeners that a class was either loaded or not found.- Parameters:
c- the class object if the class was successfully loaded,nullotherwise.name- the name of the class if it was not found, this parameter is ignored if the class was found.foundInURLClassPath-trueif the class was loaded from the class loader's URL classpath,falseif 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:
trueif this class loader is a client class loader,falseif it is a server class loader.
-
isServerClassLoader
public boolean isServerClassLoader()Determine whether this class loader accesses the classpath of a remote driver/server.- Returns:
trueif this class loader is a server class loader,falseif it is a client class loader.
-
getResource
- Overrides:
getResourcein classClassLoader
-
getResources
- Overrides:
getResourcesin classClassLoader- Throws:
IOException
-