Class NarClassLoader

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable

    public class NarClassLoader
    extends java.net.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.

    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected java.lang.String findLibrary​(java.lang.String libname)  
      java.lang.String getServiceDefinition​(java.lang.String serviceName)
      Read a service definition as a String.
      java.util.List<java.lang.String> getServiceImplementation​(java.lang.String serviceName)  
      java.io.File getWorkingDirectory()  
      java.lang.String 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
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • DEFAULT_NAR_EXTRACTION_DIR

        public static final java.lang.String DEFAULT_NAR_EXTRACTION_DIR
    • Method Detail

      • getWorkingDirectory

        public java.io.File getWorkingDirectory()
      • getServiceDefinition

        public java.lang.String getServiceDefinition​(java.lang.String serviceName)
                                              throws java.io.IOException
        Read a service definition as a String.
        Throws:
        java.io.IOException
      • getServiceImplementation

        public java.util.List<java.lang.String> getServiceImplementation​(java.lang.String serviceName)
                                                                  throws java.io.IOException
        Throws:
        java.io.IOException
      • findLibrary

        protected java.lang.String findLibrary​(java.lang.String libname)
        Overrides:
        findLibrary in class java.lang.ClassLoader
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object