com.ibm.ws.classloading

Interface ClassLoadingService


  1. public interface ClassLoadingService
The ClassLoadingService is used to construct and manage class loaders. These can then be used to load application, module, or other level artifacts.

Method Summary

Modifier and Type Method and Description
  1. java.lang.ClassLoader
createBundleAddOnClassLoader(java.util.List<java.io.File> classPath,java.lang.ClassLoader gwClassLoader,ClassLoaderConfiguration config)
This method creates a classloader for use from within a bundle.
  1. java.lang.ClassLoader
createChildClassLoader(java.util.List<Container> classpath,ClassLoaderConfiguration config)
This method creates a lower level class loader, such as a module class loader.
  1. ClassLoaderConfiguration
createClassLoaderConfiguration()
  1. GatewayConfiguration
createGatewayConfiguration()
  1. ClassLoaderIdentity
createIdentity(java.lang.String domain,java.lang.String id)
This creates an immutable ClassLoaderIdentity.
  1. java.lang.ClassLoader
createThreadContextClassLoader(java.lang.ClassLoader applicationClassLoader)
This will augment the application class loader with the ability to see more internal packages.
  1. java.lang.ClassLoader
createTopLevelClassLoader(java.util.List<Container> classPath,GatewayConfiguration gwConfig,ClassLoaderConfiguration config)
This method creates a top level class loader.
  1. void
destroyThreadContextClassLoader(java.lang.ClassLoader unifiedClassLoader)
This will destroy the thread context class loader.
  1. java.lang.ClassLoader
getShadowClassLoader(java.lang.ClassLoader loader)
Attempt to create a ClassLoader that can be used to introspect the classes on the class path of the provided ClassLoader without loading them directly.
  1. java.lang.ClassLoader
getSharedLibraryClassLoader(SharedLibrary lib)
Create or retrieve the shared class loader for a shared library.
  1. boolean
registerTransformer(ClassTransformer transformer,java.lang.ClassLoader loader)
Attempt to register a ClassTransformer with a ClassLoader.
  1. java.lang.ClassLoader
unify(java.lang.ClassLoader parent,java.lang.ClassLoader... classloaders)
This method builds a classloader that delegates to the provided classloaders in order.
  1. boolean
unregisterTransformer(ClassTransformer transformer,java.lang.ClassLoader loader)
Attempt to unregister a ClassTransformer from a ClassLoader.

Method Detail

createTopLevelClassLoader

  1. java.lang.ClassLoader createTopLevelClassLoader( java.util.List<Container> classPath,
  2. GatewayConfiguration gwConfig,
  3. 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.

Parameters:
classPath - A list of URLs that should be used to load classes
gwConfig - The desired configuration for the gateway.
config - The desired configuration of the ClassLoader.
Returns:
The created class loader.

createBundleAddOnClassLoader

  1. java.lang.ClassLoader createBundleAddOnClassLoader( java.util.List<java.io.File> classPath,
  2. java.lang.ClassLoader gwClassLoader,
  3. 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.

Parameters:
classPath - A list of URLs that should be used to load classes
gwClassLoader - The gateway ClassLoader.
config - The desired configuration of the ClassLoader.
Returns:
The created class loader.

createChildClassLoader

  1. java.lang.ClassLoader createChildClassLoader( java.util.List<Container> classpath,
  2. 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.

Parameters:
classpath - A list of URLs that should be used to load classes
config - The desired configuration of the ClassLoader.
Returns:
the created class loader.

createGatewayConfiguration

  1. GatewayConfiguration createGatewayConfiguration( )
Returns:
A clean gateway configuration

createClassLoaderConfiguration

  1. ClassLoaderConfiguration createClassLoaderConfiguration( )
Returns:
A clean class loader configuration.

createIdentity

  1. ClassLoaderIdentity createIdentity( java.lang.String domain,
  2. java.lang.String id)
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 loader
id - an id unique within the domain
Returns:
a new ClassLoaderIdentity composed of the domain and the id

getShadowClassLoader

  1. java.lang.ClassLoader getShadowClassLoader( java.lang.ClassLoader loader)
Attempt to create a ClassLoader that can be used to introspect the classes on the class path of the provided ClassLoader without loading them directly. The returned ClassLoader should 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 ClassLoader or null if loader was not created by this service
See Also:
javax.persistence.spi.PersistenceUnitInfo#getNewTempClassLoader()

registerTransformer

  1. boolean registerTransformer(ClassTransformer transformer,
  2. java.lang.ClassLoader loader)
Attempt to register a ClassTransformer with a ClassLoader.
Parameters:
transformer - the ClassTransformer to be registered
loader - the ClassLoader to be modified
Returns:
true if the operation succeeded, false if the ClassLoader was not created by this ClassLoadingService.

unregisterTransformer

  1. boolean unregisterTransformer(ClassTransformer transformer,
  2. java.lang.ClassLoader loader)
Attempt to unregister a ClassTransformer from a ClassLoader.
Parameters:
transformer - the ClassTransformer to be unregistered
loader - the ClassLoader to be modified
Returns:
true if loader was modified, false if it was not a classloader created by this service or if transformer was never registered with it.

unify

  1. java.lang.ClassLoader unify(java.lang.ClassLoader parent,
  2. java.lang.ClassLoader... classloaders)
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 query
classloaders - the class loaders to unify,
Returns:
a unified classloader

getSharedLibraryClassLoader

  1. java.lang.ClassLoader getSharedLibraryClassLoader( SharedLibrary lib)
Create or retrieve the shared class loader for a shared library.
Parameters:
lib - the shared library to create a class loader for
Returns:
the unique clas loader for the provided library

createThreadContextClassLoader

  1. java.lang.ClassLoader createThreadContextClassLoader( java.lang.ClassLoader applicationClassLoader)
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.
Parameters:
applicationClassLoader - The application class loader to augment
Returns:
The new class loader that can be set as the thread context class loader

destroyThreadContextClassLoader

  1. void destroyThreadContextClassLoader( java.lang.ClassLoader unifiedClassLoader)
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