Interface GDAClassLoaderService


public interface GDAClassLoaderService
  • Method Details

    • getClassLoader

      ClassLoader getClassLoader()
      Obtain a class loader which is capable of loading classes from all bundles/plugins in the application provided the containing package is exported from its plugin.
    • getClassLoaderForLibrary

      ClassLoader getClassLoaderForLibrary(Class<?> libraryClass)
      Obtain a class loader which is capable of loading classes from all bundles/plugins in the application provided the containing package is exported from its plugin.
      This loader allows an additional ClassLoader to be searched first (typically this would be a class from the library requiring this class loader)
      The library bundle will be used to load resources.
      Parameters:
      libraryClass - the ClassLoader of this Class object will be searched first
    • getClassLoaderForLibrary

      ClassLoader getClassLoaderForLibrary(Class<?> libraryClass, Consumer<Class<?>> onSuccess)
      Obtain a class loader which is capable of loading classes from all bundles/plugins in the application provided the containing package is exported from its plugin.
      This loader allows an additional ClassLoader to be searched first (typically this would be a class from the library requiring this class loader)
      The library bundle will be used to load resources.
      Parameters:
      libraryClass - the ClassLoader of this Class object will be searched first
      onSuccess - callback when class is successfully loaded
    • getClassLoaderForLibrary

      ClassLoader getClassLoaderForLibrary(Class<?> libraryClass, Consumer<Class<?>> onSuccess, Set<String> resourceBundleNames)
      Obtain a class loader which is capable of loading classes from all bundles/plugins in the application provided the containing package is exported from its plugin.
      This loader allows an additional ClassLoader to be searched first (typically this would be a class from the library requiring this class loader).
      Resources may be loaded from any of the bundles provided in the resourceBundleNames parameter.
      Parameters:
      libraryClass - the ClassLoader of this Class object will be searched first
      onSuccess - callback when class is successfully loaded
      resourceBundleNames - set of Bundle-SymbolicNames for bundles to search for resources
    • getClassLoaderForLibraryWithGlobalResourceLoading

      ClassLoader getClassLoaderForLibraryWithGlobalResourceLoading(Class<?> libraryClass, Set<String> excludedBundles)
      Obtain a class loader which is capable of loading classes from all bundles/plugins in the application provided the containing package is exported from its plugin.
      This loader allows an additional ClassLoader to be searched first (typically this would be a class from the library requiring this class loader).
      Resources may be loaded from any of the bundles present in the application.
      Parameters:
      libraryClass - the ClassLoader of this Class object will be searched first
      excludedBundles - set of bundle symbolic names to exclude from the resource loading
    • getClassLoaderService

      static GDAClassLoaderService getClassLoaderService()
      Get the class loader service from OSGi if it is running otherwise a null service will be returned.
      Possibly not required if there is a solution later implemented for DAQ-2239.
      Returns:
      the service instantiated by OSGi DS or a service providing null class loaders if OSGi is not running
    • temporaryClassLoader

      static TemporaryContextClassLoader temporaryClassLoader()
      Create a TemporaryContextClassLoader that uses the service provided class loader and can automatically revert to the existing class loader when closed.
       try (var tccl = temporaryClassLoader()) {
           // Code requiring new class loader
       }
       
      Returns:
      A TemporaryContextClassLoader wrapping the service's class loader
      See Also:
    • temporaryClassLoader

      static TemporaryContextClassLoader temporaryClassLoader(Function<GDAClassLoaderService,ClassLoader> configurer)
      Create a TemporaryContextClassLoader that uses the service provided class loader and can automatically revert to the existing class loader when closed.
       try (var tccl = temporaryClassLoader(s -> s.getClassLoaderForLibrary(LibraryClass.class))) {
           // Code requiring new class loader
       }
       
      Parameters:
      configurer - Function to get a class loader from the class loader service
      Returns:
      A TemporaryContextClassLoader wrapping the service's class loader
      See Also: