Class NarClassLoader

All Implemented Interfaces:
Closeable, AutoCloseable

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-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.