public class StandardExtensionDiscoveringManager extends Object implements ExtensionDiscoveringManager
| Modifier and Type | Class and Description |
|---|---|
private static class |
StandardExtensionDiscoveringManager.BaseClassLoaderKey |
| Modifier and Type | Field and Description |
|---|---|
private Map<BundleCoordinate,Bundle> |
bundleCoordinateBundleLookup |
private Map<BundleCoordinate,Set<ExtensionDefinition>> |
bundleCoordinateClassesLookup |
private Map<ClassLoader,Bundle> |
classLoaderBundleLookup |
private Map<String,List<Bundle>> |
classNameBundleLookup |
private Map<Class,Set<ExtensionDefinition>> |
definitionMap |
private Map<String,InstanceClassLoader> |
instanceClassloaderLookup |
private static org.slf4j.Logger |
logger |
private ConcurrentMap<StandardExtensionDiscoveringManager.BaseClassLoaderKey,SharedInstanceClassLoader> |
sharedBaseClassloaders |
private Map<String,ConfigurableComponent> |
tempComponentLookup |
| Constructor and Description |
|---|
StandardExtensionDiscoveringManager() |
StandardExtensionDiscoveringManager(Collection<Class<? extends ConfigurableComponent>> additionalExtensionTypes) |
| Modifier and Type | Method and Description |
|---|---|
private void |
buildClassLoaderDetails(Bundle bundle,
StringBuilder sb,
int indentLevel) |
void |
closeURLClassLoader(String instanceIdentifier,
ClassLoader classLoader)
Closes the given ClassLoader if it is an instance of URLClassLoader.
|
InstanceClassLoader |
createInstanceClassLoader(String classType,
String instanceIdentifier,
Bundle bundle,
Set<URL> additionalUrls,
boolean register,
String classloaderIsolationKey)
Creates the ClassLoader for the instance of the given type.
|
void |
discoverExtensions(Bundle systemBundle,
Set<Bundle> narBundles)
Discovers all extensions available in the provided bundles.
|
void |
discoverExtensions(Set<Bundle> narBundles,
boolean logDetails)
Discovers extensions in the provided bundles.
|
protected Set<BundleCoordinate> |
findReachableApiBundles(ConfigurableComponent component)
Find the bundle coordinates for any service APIs that are referenced by this component and not part of the same bundle.
|
Set<Bundle> |
getAllBundles()
Retrieves all bundles known to this ExtensionManager.
|
Bundle |
getBundle(BundleCoordinate bundleCoordinate)
Retrieves the bundle with the given coordinate.
|
Bundle |
getBundle(ClassLoader classLoader)
Retrieves the bundle for the given class loader.
|
List<Bundle> |
getBundles(String classType)
Retrieves the bundles that have a class with the given name.
|
Class<?> |
getClass(ExtensionDefinition extensionDefinition)
Returns the Class that is described by the given definition
|
private static String |
getClassBundleKey(String classType,
BundleCoordinate bundleCoordinate) |
Set<ExtensionDefinition> |
getExtensions(Class<?> definition)
Retrieves the set of classes that have been loaded for the definition.
|
InstanceClassLoader |
getInstanceClassLoader(String instanceIdentifier)
Retrieves the InstanceClassLoader for the component with the given identifier.
|
private Set<String> |
getServiceFileImplementationClassNames(URL serviceFileUrl) |
private Set<URL> |
getServiceFileURLs(Bundle bundle,
Class<?> extensionType)
Returns a Set of URL's for all Service Files (i.e., META-INF/services/<interface name> files)
that define the extensions that exist for the given bundle.
|
ConfigurableComponent |
getTempComponent(String classType,
BundleCoordinate bundleCoordinate)
Gets the temp component with the given type from the given bundle.
|
Set<ExtensionDefinition> |
getTypes(BundleCoordinate bundleCoordinate)
Retrieves the extension classes that were loaded from the bundle with the given coordinate.
|
protected void |
initializeTempComponent(ConfigurableComponent configurableComponent) |
protected boolean |
isInstanceClassLoaderRequired(String classType,
Bundle bundle) |
protected void |
loadExtension(String extensionClassName,
Class<?> extensionType,
Bundle bundle) |
private void |
loadExtensions(Bundle bundle)
Loads extensions from the specified bundle.
|
void |
logClassLoaderDetails()
Logs details about the files loaded by the class loaders
|
void |
logClassLoaderMapping()
Logs the available class loaders.
|
private static boolean |
multipleVersionsAllowed(Class<?> type) |
protected void |
registerExtensionClass(Class<?> extensionType,
String implementationClassName,
Bundle bundle) |
void |
registerInstanceClassLoader(String instanceIdentifier,
InstanceClassLoader instanceClassLoader)
Registers the given instance class loader so that it can be later retrieved via
ExtensionManager.getInstanceClassLoader(String) |
private void |
registerServiceClass(String className,
Class<?> extensionType,
Map<String,List<Bundle>> classNameBundleMap,
Map<BundleCoordinate,Set<ExtensionDefinition>> bundleCoordinateClassesMap,
Bundle bundle,
Set<ExtensionDefinition> classes)
Registers extension for the specified type from the specified Bundle.
|
InstanceClassLoader |
removeInstanceClassLoader(String instanceIdentifier)
Removes the InstanceClassLoader for a given component.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitdiscoverExtensionscreateInstanceClassLoaderprivate static final org.slf4j.Logger logger
private final Map<Class,Set<ExtensionDefinition>> definitionMap
private final Map<BundleCoordinate,Set<ExtensionDefinition>> bundleCoordinateClassesLookup
private final Map<BundleCoordinate,Bundle> bundleCoordinateBundleLookup
private final Map<ClassLoader,Bundle> classLoaderBundleLookup
private final Map<String,ConfigurableComponent> tempComponentLookup
private final Map<String,InstanceClassLoader> instanceClassloaderLookup
private final ConcurrentMap<StandardExtensionDiscoveringManager.BaseClassLoaderKey,SharedInstanceClassLoader> sharedBaseClassloaders
public StandardExtensionDiscoveringManager()
public StandardExtensionDiscoveringManager(Collection<Class<? extends ConfigurableComponent>> additionalExtensionTypes)
public Set<Bundle> getAllBundles()
ExtensionManagergetAllBundles in interface ExtensionManagerpublic void discoverExtensions(Bundle systemBundle, Set<Bundle> narBundles)
ExtensionDiscoveringManagerdiscoverExtensions in interface ExtensionDiscoveringManagersystemBundle - the system bundlenarBundles - the bundles to use for discovering extensionspublic void discoverExtensions(Set<Bundle> narBundles, boolean logDetails)
ExtensionDiscoveringManagerdiscoverExtensions in interface ExtensionDiscoveringManagernarBundles - the bundles to use for discovering extensionslogDetails - whether or not to log the details about what is loadedprivate void loadExtensions(Bundle bundle)
bundle - from which to load extensionsprivate Set<String> getServiceFileImplementationClassNames(URL serviceFileUrl) throws IOException
IOExceptionprivate Set<URL> getServiceFileURLs(Bundle bundle, Class<?> extensionType) throws IOException
bundle - the bundle whose extensions are of interestextensionType - the type of extension (I.e., Processor, ControllerService, ParameterProvider, ReportingTask, etc.)IOException - if unable to read the services file from the given bundle's classloader.protected void loadExtension(String extensionClassName, Class<?> extensionType, Bundle bundle)
protected void registerExtensionClass(Class<?> extensionType, String implementationClassName, Bundle bundle)
protected void initializeTempComponent(ConfigurableComponent configurableComponent)
private void registerServiceClass(String className, Class<?> extensionType, Map<String,List<Bundle>> classNameBundleMap, Map<BundleCoordinate,Set<ExtensionDefinition>> bundleCoordinateClassesMap, Bundle bundle, Set<ExtensionDefinition> classes)
className - the fully qualified class name of the extension implementationclassNameBundleMap - mapping of classname to Bundlebundle - the Bundle being mapped toclasses - to map to this classloader but which come from its ancestorspublic Class<?> getClass(ExtensionDefinition extensionDefinition)
ExtensionManagergetClass in interface ExtensionManagerextensionDefinition - the extension definitionprivate static boolean multipleVersionsAllowed(Class<?> type)
type - a Class that we found from a service loaderprotected boolean isInstanceClassLoaderRequired(String classType, Bundle bundle)
public InstanceClassLoader createInstanceClassLoader(String classType, String instanceIdentifier, Bundle bundle, Set<URL> additionalUrls, boolean register, String classloaderIsolationKey)
ExtensionManagercreateInstanceClassLoader in interface ExtensionManagerclassType - the type of class to create the ClassLoader forinstanceIdentifier - the identifier of the specific instance of the classType to look up the ClassLoader forbundle - the bundle where the classType existsadditionalUrls - additional URLs to add to the instance class loaderregister - whether or not to register the class loader as the new classloader for the component with the given IDclassloaderIsolationKey - a classloader key that can be used in order to specify which shared class loader can be used as the instance class loader's parent, or null if the
parent class loader should be shared or if cloning ancestors is not necessaryprotected Set<BundleCoordinate> findReachableApiBundles(ConfigurableComponent component)
component - the component being instantiatedpublic InstanceClassLoader getInstanceClassLoader(String instanceIdentifier)
ExtensionManagergetInstanceClassLoader in interface ExtensionManagerinstanceIdentifier - the identifier of a componentpublic InstanceClassLoader removeInstanceClassLoader(String instanceIdentifier)
ExtensionManagerremoveInstanceClassLoader in interface ExtensionManagerinstanceIdentifier - the of a componentpublic void registerInstanceClassLoader(String instanceIdentifier, InstanceClassLoader instanceClassLoader)
ExtensionManagerExtensionManager.getInstanceClassLoader(String)registerInstanceClassLoader in interface ExtensionManagerinstanceIdentifier - the instance identifierinstanceClassLoader - the class loaderpublic void closeURLClassLoader(String instanceIdentifier, ClassLoader classLoader)
ExtensionManagercloseURLClassLoader in interface ExtensionManagerinstanceIdentifier - the instance id the class loader corresponds toclassLoader - the class loader to closepublic List<Bundle> getBundles(String classType)
ExtensionManagergetBundles in interface ExtensionManagerclassType - the class name of an extensionpublic Bundle getBundle(BundleCoordinate bundleCoordinate)
ExtensionManagergetBundle in interface ExtensionManagerbundleCoordinate - a coordinate to look uppublic Set<ExtensionDefinition> getTypes(BundleCoordinate bundleCoordinate)
ExtensionManagergetTypes in interface ExtensionManagerbundleCoordinate - the coordinatepublic Bundle getBundle(ClassLoader classLoader)
ExtensionManagergetBundle in interface ExtensionManagerclassLoader - the class loader to look up the bundle forpublic Set<ExtensionDefinition> getExtensions(Class<?> definition)
ExtensionManagergetExtensions in interface ExtensionManagerdefinition - the extension definition, such as Processor.classpublic ConfigurableComponent getTempComponent(String classType, BundleCoordinate bundleCoordinate)
ExtensionManagergetTempComponent in interface ExtensionManagerclassType - the class namebundleCoordinate - the coordinateprivate static String getClassBundleKey(String classType, BundleCoordinate bundleCoordinate)
public void logClassLoaderMapping()
ExtensionManagerlogClassLoaderMapping in interface ExtensionManagerpublic void logClassLoaderDetails()
ExtensionManagerlogClassLoaderDetails in interface ExtensionManagerprivate void buildClassLoaderDetails(Bundle bundle, StringBuilder sb, int indentLevel)
Copyright © 2023 Apache NiFi Project. All rights reserved.