Interface ClassLoadingService


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 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 ClassLoaderIdentity objects. The results of concurrent invocation for the same identity are not defined.

      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

      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 ClassLoaderIdentity objects. The results of concurrent invocation for the same identity are not defined.

      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

      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 ClassLoaderIdentity objects. The results of concurrent invocation for the same identity are not defined.

      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

      GatewayConfiguration createGatewayConfiguration()
      Returns:
      A clean gateway configuration
    • createClassLoaderConfiguration

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

      ClassLoaderIdentity createIdentity(String domain, 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

      ClassLoader getShadowClassLoader(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

      boolean registerTransformer(ClassTransformer transformer, 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

      boolean unregisterTransformer(ClassTransformer transformer, 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

      ClassLoader unify(ClassLoader parent, 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

      ClassLoader getSharedLibraryClassLoader(Library 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 class loader for the provided library
    • createThreadContextClassLoader

      ClassLoader createThreadContextClassLoader(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. Note: It is the caller's responsibility to ensure the returned class loader is destroyed when 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

      void destroyThreadContextClassLoader(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
    • isAppClassLoader

      boolean isAppClassLoader(ClassLoader cl)
      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

      boolean isThreadContextClassLoader(ClassLoader cl)
      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.
    • setSharedLibraryProtectionDomains

      void setSharedLibraryProtectionDomains(Map<String,ProtectionDomain> protectionDomainMap)
      Parameters:
      protectionDomainMap -