public class NarClassLoader extends URLClassLoader
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-aNar-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.
| Modifier and Type | Field and Description |
|---|---|
private static FileFilter |
JAR_FILTER |
private static org.slf4j.Logger |
LOGGER |
private File |
narWorkingDirectory
The NAR for which this ClassLoader is responsible.
|
| Constructor and Description |
|---|
NarClassLoader(File narWorkingDirectory)
Construct a nar class loader.
|
NarClassLoader(File narWorkingDirectory,
ClassLoader parentClassLoader)
Construct a nar class loader with the specific parent.
|
| Modifier and Type | Method and Description |
|---|---|
protected String |
findLibrary(String libname) |
File |
getWorkingDirectory() |
String |
toString() |
private void |
updateClasspath(File root)
Adds URLs for the resources unpacked from this NAR:
the root: for classes, META-INF, etc.
META-INF/dependencies: for config files, .sos,
etc.
META-INF/dependencies/*.jar: for dependent
libraries
|
addURL, close, definePackage, findClass, findResource, findResources, getPermissions, getResourceAsStream, getURLs, newInstance, newInstancedefineClass, defineClassclearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findLoadedClass, findSystemClass, getClassLoadingLock, getPackage, getPackages, getParent, getResource, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, loadClass, loadClass, registerAsParallelCapable, resolveClass, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSignersprivate static final org.slf4j.Logger LOGGER
private static final FileFilter JAR_FILTER
private final File narWorkingDirectory
public NarClassLoader(File narWorkingDirectory) throws ClassNotFoundException, IOException
narWorkingDirectory - directory to explode nar contents toIllegalArgumentException - if the NAR is missing the Java Services
API file for FlowFileProcessor implementations.ClassNotFoundException - if any of the FlowFileProcessor
implementations defined by the Java Services API cannot be loaded.IOException - if an error occurs while loading the NAR.public NarClassLoader(File narWorkingDirectory, ClassLoader parentClassLoader) throws ClassNotFoundException, IOException
narWorkingDirectory - directory to explode nar contents toparentClassLoader - parent class loader of this narIllegalArgumentException - if the NAR is missing the Java Services
API file for FlowFileProcessor implementations.ClassNotFoundException - if any of the FlowFileProcessor
implementations defined by the Java Services API cannot be loaded.IOException - if an error occurs while loading the NAR.public File getWorkingDirectory()
private void updateClasspath(File root) throws IOException
root - the root directory of the unpacked NAR.IOException - if the URL list could not be updated.protected String findLibrary(String libname)
findLibrary in class ClassLoaderCopyright © 2016 Apache NiFi Project. All rights reserved.