Package uk.ac.diamond.daq.classloading
Interface GDAClassLoaderService
public interface GDAClassLoaderService
-
Method Summary
Modifier and TypeMethodDescriptionObtain 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(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.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.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.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.static GDAClassLoaderServiceGet the class loader service from OSGi if it is running otherwise a null service will be returned.static TemporaryContextClassLoaderCreate aTemporaryContextClassLoaderthat uses the service provided class loader and can automatically revert to the existing class loader whenclosed.static TemporaryContextClassLoadertemporaryClassLoader(Function<GDAClassLoaderService, ClassLoader> configurer) Create aTemporaryContextClassLoaderthat uses the service provided class loader and can automatically revert to the existing class loader whenclosed.
-
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
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
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 firstonSuccess- 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 theresourceBundleNamesparameter.- Parameters:
libraryClass- the ClassLoader of this Class object will be searched firstonSuccess- callback when class is successfully loadedresourceBundleNames- 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 firstexcludedBundles- set of bundle symbolic names to exclude from the resource loading
-
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
Create aTemporaryContextClassLoaderthat uses the service provided class loader and can automatically revert to the existing class loader whenclosed.try (var tccl = temporaryClassLoader()) { // Code requiring new class loader }- Returns:
- A
TemporaryContextClassLoaderwrapping the service's class loader - See Also:
-
temporaryClassLoader
static TemporaryContextClassLoader temporaryClassLoader(Function<GDAClassLoaderService, ClassLoader> configurer) Create aTemporaryContextClassLoaderthat uses the service provided class loader and can automatically revert to the existing class loader whenclosed.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
TemporaryContextClassLoaderwrapping the service's class loader - See Also:
-