Class NarClassLoader
- java.lang.Object
-
- java.lang.ClassLoader
-
- java.security.SecureClassLoader
-
- java.net.URLClassLoader
-
- org.apache.pulsar.common.nar.NarClassLoader
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable
public class NarClassLoader extends java.net.URLClassLoaderA 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-IdandNar-Dependency-Id.The
Nar-Idprovides a unique identifier for this NAR.The
Nar-Dependency-Idis 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-Idproperty will be set to the artifactId of the NAR. TheNar-Dependency-Idwill 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
typeof the dependency is set tonar.If the NAR has more than one dependency of
typenar, then the Maven NAR plugin will fail to build the NAR.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringDEFAULT_NAR_EXTRACTION_DIR
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.lang.StringfindLibrary(java.lang.String libname)java.lang.StringgetServiceDefinition(java.lang.String serviceName)Read a service definition as a String.java.util.List<java.lang.String>getServiceImplementation(java.lang.String serviceName)java.io.FilegetWorkingDirectory()java.lang.StringtoString()-
Methods inherited from class java.net.URLClassLoader
addURL, close, definePackage, findClass, findResource, findResources, getPermissions, getResourceAsStream, getURLs, newInstance, newInstance
-
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
-
-
-
-
Method Detail
-
getWorkingDirectory
public java.io.File getWorkingDirectory()
-
getServiceDefinition
public java.lang.String getServiceDefinition(java.lang.String serviceName) throws java.io.IOExceptionRead 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:
findLibraryin classjava.lang.ClassLoader
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-