Interface ClassLoadingService
-
Method Summary
Modifier and TypeMethodDescriptioncreateBundleAddOnClassLoader(List<File> classPath, ClassLoader gwClassLoader, ClassLoaderConfiguration config) This method creates a classloader for use from within a bundle.createChildClassLoader(List<com.ibm.wsspi.adaptable.module.Container> classpath, ClassLoaderConfiguration config) This method creates a lower level class loader, such as a module class loader.createIdentity(String domain, String id) This creates an immutable ClassLoaderIdentity.createThreadContextClassLoader(ClassLoader applicationClassLoader) This will augment the application class loader with the ability to see more internal packages.createTopLevelClassLoader(List<com.ibm.wsspi.adaptable.module.Container> classPath, GatewayConfiguration gwConfig, ClassLoaderConfiguration config) This method creates a top level class loader.voiddestroyThreadContextClassLoader(ClassLoader unifiedClassLoader) This will destroy the thread context class loader.getShadowClassLoader(ClassLoader loader) Attempt to create aClassLoaderthat can be used to introspect the classes on the class path of the providedClassLoaderwithout loading them directly.Create or retrieve the shared class loader for a shared library.booleanThis method returns whether or not the provided ClassLoader object is an instance of an AppClassLoader.booleanThis method returns whether or not the provided ClassLoader object is an instance of an ThreadContextClassLoader.booleanregisterTransformer(ClassTransformer transformer, ClassLoader loader) Attempt to register aClassTransformerwith aClassLoader.voidsetSharedLibraryProtectionDomains(Map<String, ProtectionDomain> protectionDomainMap) unify(ClassLoader parent, ClassLoader... classloaders) This method builds a classloader that delegates to the provided classloaders in order.booleanunregisterTransformer(ClassTransformer transformer, ClassLoader loader) Attempt to unregister aClassTransformerfrom aClassLoader.
-
Method Details
-
createTopLevelClassLoader
ClassLoader createTopLevelClassLoader(List<com.ibm.wsspi.adaptable.module.Container> classPath, GatewayConfiguration gwConfig, ClassLoaderConfiguration config) This method creates a top level class loader. The parent of a top level class loader is a gateway into the server's class space. The ClassLoaderConfiguration is not expected to have a parent set for this call.Once the configuration objects are passed in, they belong to the ClassLoadingService. They should not be modified or re-used for other invocations.
N.B. it is the caller's responsibility to ensure that this method is not called concurrently for the same or equivalent
ClassLoaderIdentityobjects. The results of concurrent invocation for the same identity are not defined.- Parameters:
classPath- A list of URLs that should be used to load classesgwConfig- The desired configuration for the gateway.config- The desired configuration of the ClassLoader.- Returns:
- The created class loader.
-
createBundleAddOnClassLoader
ClassLoader createBundleAddOnClassLoader(List<File> classPath, ClassLoader gwClassLoader, ClassLoaderConfiguration config) This method creates a classloader for use from within a bundle. If a bundle needs to invoke shared libraries specified in config, for example, it can use this method to create a loader for the shared libraries which will also provide access to the classes within the bundle.Once the configuration objects are passed in, they belong to the ClassLoadingService. They should not be modified or re-used for other invocations.
N.B. it is the caller's responsibility to ensure that this method is not called concurrently for the same or equivalent
ClassLoaderIdentityobjects. The results of concurrent invocation for the same identity are not defined.- Parameters:
classPath- A list of URLs that should be used to load classesgwClassLoader- The gateway ClassLoader.config- The desired configuration of the ClassLoader.- Returns:
- The created class loader.
-
createChildClassLoader
ClassLoader createChildClassLoader(List<com.ibm.wsspi.adaptable.module.Container> classpath, ClassLoaderConfiguration config) This method creates a lower level class loader, such as a module class loader. It has a parent which could be a class loader created by a call to createTopLevelClassLoader, or createChildClassLoader. The ClassLoaderConfiguration must have a parent set in this case.Once the configuration objects are passed in, they belong to the ClassLoadingService. They should not be modified or re-used for other invocations.
N.B. it is the caller's responsibility to ensure that this method is not called concurrently for the same or equivalent
ClassLoaderIdentityobjects. The results of concurrent invocation for the same identity are not defined.- Parameters:
classpath- A list of URLs that should be used to load classesconfig- The desired configuration of the ClassLoader.- Returns:
- the created class loader.
-
createGatewayConfiguration
GatewayConfiguration createGatewayConfiguration()- Returns:
- A clean gateway configuration
-
createClassLoaderConfiguration
ClassLoaderConfiguration createClassLoaderConfiguration()- Returns:
- A clean class loader configuration.
-
createIdentity
This creates an immutable ClassLoaderIdentity. Multiple calls to createIdentity with the same parameters may result in the same object.- Parameters:
domain- a unique name indicating the domain (i.e. the user) of the class loaderid- an id unique within the domain- Returns:
- a new ClassLoaderIdentity composed of the domain and the id
-
getShadowClassLoader
Attempt to create aClassLoaderthat can be used to introspect the classes on the class path of the providedClassLoaderwithout loading them directly. The returnedClassLoadershould be discarded as early as possible to allow it and all its classes to be garbage-collected.- Parameters:
loader- the class loader to clone- Returns:
- a new
ClassLoaderornullifloaderwas not created by this service - See Also:
-
javax.persistence.spi.PersistenceUnitInfo#getNewTempClassLoader()
-
registerTransformer
Attempt to register aClassTransformerwith aClassLoader.- Parameters:
transformer- theClassTransformerto be registeredloader- theClassLoaderto be modified- Returns:
trueif the operation succeeded,falseif theClassLoaderwas not created by thisClassLoadingService.
-
unregisterTransformer
Attempt to unregister aClassTransformerfrom aClassLoader.- Parameters:
transformer- theClassTransformerto be unregisteredloader- theClassLoaderto be modified- Returns:
trueifloaderwas modified,falseif it was not a classloader created by this service or iftransformerwas never registered with it.
-
unify
This method builds a classloader that delegates to the provided classloaders in order. It adds the parent classloader as the parent so it is consulted first and then consults the follow on ones when a class load fails.- Parameters:
parent- the first classloader to queryclassloaders- the class loaders to unify,- Returns:
- a unified classloader
-
createThreadContextClassLoader
This will augment the application class loader with the ability to see more internal packages. These packages are ones that contain classes that are loaded from the context class loader so are needed to be visible but shouldn't be available through the main application class loader. Note: It is the caller's responsibility to ensure the returned class loader isdestroyedwhen it is no longer needed., in order to avoid leaking this loader (and all classes it loaded).- Parameters:
applicationClassLoader- The application class loader to augment- Returns:
- The new class loader that can be set as the thread context class loader
-
destroyThreadContextClassLoader
This will destroy the thread context class loader. If the thread context class loader contains URLClassLoader, it may hold the jar file lock when the caching is enabled on Windows platform. So we need guarantee the resources could be released here.- Parameters:
unifiedClassLoader- The thread context class loader
-
isAppClassLoader
This method returns whether or not the provided ClassLoader object is an instance of an AppClassLoader.- Parameters:
cl- The class loader object to analyze.- Returns:
- true if an instance of AppClassLoader was provided, otherwise false.
-
isThreadContextClassLoader
This method returns whether or not the provided ClassLoader object is an instance of an ThreadContextClassLoader.- Parameters:
cl- The class loader object to analyze.- Returns:
- true if an instance of ThreadContextClassLoader was provided, otherwise false.
-