Class AbstractNativeLibHandlingClassLoader

java.lang.Object
java.lang.ClassLoader
java.security.SecureClassLoader
java.net.URLClassLoader
org.apache.nifi.nar.AbstractNativeLibHandlingClassLoader
All Implemented Interfaces:
Closeable, AutoCloseable, OSUtil
Direct Known Subclasses:
NarClassLoader

public abstract class AbstractNativeLibHandlingClassLoader extends URLClassLoader implements OSUtil
An extension of URLClassLoader that can load native libraries from a predefined list of directories as well as from those that are defined by the java.library.path system property. Once a library is found an OS-handled temporary copy is created and cached to maintain consistency and classloader isolation. This classloader handles the native library loading when the library is being loaded by its logical name (System.loadLibrary(String) / Runtime.loadLibrary(String) calls). For loading a native library by its absolute path, see LoadNativeLibAspect.
  • Field Details

    • logger

      private final org.slf4j.Logger logger
    • nativeLibDirList

      protected final List<File> nativeLibDirList
      Directories in which to look for native libraries
    • nativeLibNameToPath

      protected final Map<String,Path> nativeLibNameToPath
      Used to cache (the paths of) temporary copies of loaded libraries
    • tmpLibFilePrefix

      private final String tmpLibFilePrefix
      Used as prefix when creating the temporary copies of libraries
  • Constructor Details

    • AbstractNativeLibHandlingClassLoader

      public AbstractNativeLibHandlingClassLoader(URL[] urls, List<File> initialNativeLibDirList, String tmpLibFilePrefix)
    • AbstractNativeLibHandlingClassLoader

      public AbstractNativeLibHandlingClassLoader(URL[] urls, ClassLoader parent, List<File> initialNativeLibDirList, String tmpLibFilePrefix)
  • Method Details

    • toDir

      public static File toDir(File fileOrDir)
    • findLibrary

      public String findLibrary(String libname)
      Overrides:
      findLibrary in class ClassLoader
    • getUsrLibDirs

      protected Set<File> getUsrLibDirs()
    • getJavaLibraryPath

      protected String getJavaLibraryPath()
    • createTempCopy

      protected Path createTempCopy(String libname, String libraryOriginalPathString)
    • findLibrary

      protected String findLibrary(String libname, File nativeLibDir)
    • buildNativeLibDirList

      private List<File> buildNativeLibDirList(List<File> initialNativeLibDirList)