Class NarClassLoader
- All Implemented Interfaces:
Closeable
,AutoCloseable
A ClassLoader for loading NARs (NiFi archives). NARs are designed to allow isolating bundles of code (comprising one-or-more NiFi FlowFileProcessors, FlowFileComparators and their dependencies) from other such bundles; this allows for dependencies and processors that require conflicting, incompatible versions of the same dependency to run in a single instance of NiFi.
NarClassLoader follows the delegation model described in ClassLoader.findClass(...)
; classes are first loaded from the parent ClassLoader, and only if they cannot
be found there does the NarClassLoader provide a definition. Specifically, this means that resources are
loaded from NiFi's conf and lib directories first, and if they cannot be found there, are loaded
from the NAR.
The packaging of a NAR is such that it is a ZIP file with the following directory structure:
+META-INF/ +-- bundled-dependencies/ +-- <JAR files> +-- MANIFEST.MF
The MANIFEST.MF file contains the same information as a typical JAR file but also includes two additional NiFi
properties: Nar-Id
and Nar-Dependency-Id
.
The Nar-Id
provides a unique identifier for this NAR.
The Nar-Dependency-Id
is optional. If provided, it indicates that this NAR should inherit all of the
dependencies of the NAR with the provided ID. Often times, the NAR that is depended upon is referred to as the
Parent. This is because its ClassLoader will be the parent ClassLoader of the dependent NAR.
If a NAR is built using NiFi's Maven NAR Plugin, the Nar-Id
property will be set to the artifactId of the
NAR. The Nar-Dependency-Id
will be set to the artifactId of the NAR that is depended upon. For example, if
NAR A is defined as such:
... <artifactId>nar-a</artifactId> <packaging>nar</packaging> ... <dependencies> <dependency> <groupId>group</groupId> <artifactId>nar-z</artifactId> <type>nar</type> </dependency> </dependencies>
Then the MANIFEST.MF file that is created for NAR A will have the following properties set:
Nar-Id: nar-a
Nar-Dependency-Id: nar-z
Note, above, that the type
of the dependency is set to nar
.
If the NAR has more than one dependency of type
nar
, then the Maven NAR plugin will fail to build the
NAR.
-
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected String
findLibrary
(String libname) getClasspathFromArchive
(File narPath, String narExtractionDirectory) getServiceDefinition
(String serviceName) Read a service definition as a String.getServiceImplementation
(String serviceName) toString()
Methods inherited from class java.net.URLClassLoader
addURL, close, definePackage, findClass, findResource, findResources, getPermissions, getResourceAsStream, getURLs, newInstance, newInstance
Methods inherited from class java.security.SecureClassLoader
defineClass, defineClass
Methods inherited from class java.lang.ClassLoader
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findClass, findLoadedClass, findResource, findSystemClass, getClassLoadingLock, getDefinedPackage, getDefinedPackages, getName, getPackage, getPackages, getParent, getPlatformClassLoader, getResource, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, getUnnamedModule, isRegisteredAsParallelCapable, loadClass, loadClass, registerAsParallelCapable, resolveClass, resources, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
-
Field Details
-
DEFAULT_NAR_EXTRACTION_DIR
-
-
Method Details
-
getClasspathFromArchive
public static List<File> getClasspathFromArchive(File narPath, String narExtractionDirectory) throws IOException - Throws:
IOException
-
getWorkingDirectory
-
getServiceDefinition
Read a service definition as a String.- Throws:
IOException
-
getServiceImplementation
- Throws:
IOException
-
findLibrary
- Overrides:
findLibrary
in classClassLoader
-
toString
-