Package org.jocl

Class LibTracker

java.lang.Object
org.jocl.LibTracker

class LibTracker extends Object
Utility class for tracking a set of loaded libraries and deleting them at program exit.

Note: The current default setting in JOCL is that this class is NOT used.

This class contains some ugly reflection hacks, attempting to alleviate the problem that (temporary) native library files on Windows can not be deleted when they have been loaded.

However, the default setting in JOCL is that it assumes that the name of the native library is fixed, and it will not be necessary to create temporary files.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private static final Set<File>
    The tracked library files that will be unloaded and deleted when the application exits
    private static final Logger
    The logger used in this class
    private static Thread
    The shutdown hook thread that will attempt to unload and delete the library files
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
    Private constructor to prevent instantiation
  • Method Summary

    Modifier and Type
    Method
    Description
    private static void
    Try to delete all library files that are tracked by this class.
    private static void
    Free the native libraries that have been registered in this class.
    private static void
    Free the given library object by invoking its "finalize(Classinvalid input: '<'?>)" method.
    private static Field
    getDeclaredField(Class<?> c, String fieldName)
    Returns the declared field with the given name in the given class, or any of its superclasses.
    private static Object
    getFieldValueOptional(Object object, String fieldName)
    Returns the value of the (potentially private) field with the given name from the given object.
    private static void
    Tries to invoke a "finalize(Classinvalid input: '<'?>)" method on the given object.
    private static void
    Will be called by the shutdown hook
    (package private) static void
    track(File libraryFile)
    Add the given native library file to be tracked by this class.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • logger

      private static final Logger logger
      The logger used in this class
    • libraryFiles

      private static final Set<File> libraryFiles
      The tracked library files that will be unloaded and deleted when the application exits
    • shutdownHook

      private static Thread shutdownHook
      The shutdown hook thread that will attempt to unload and delete the library files
  • Constructor Details

    • LibTracker

      private LibTracker()
      Private constructor to prevent instantiation
  • Method Details

    • track

      static void track(File libraryFile)
      Add the given native library file to be tracked by this class. When the application exits, the native library will be unloaded and the given file will be deleted.
      Parameters:
      libraryFile - The library file
    • shutdown

      private static void shutdown()
      Will be called by the shutdown hook
    • freeNativeLibraries

      private static void freeNativeLibraries()
      Free the native libraries that have been registered in this class. Any errors will be ignored.
    • freeNativeLibrary

      private static void freeNativeLibrary(Object library)
      Free the given library object by invoking its "finalize(Classinvalid input: '<'?>)" method. Any errors will be ignored.
      Parameters:
      library - The library
    • deleteNativeLibraries

      private static void deleteNativeLibraries()
      Try to delete all library files that are tracked by this class. Any errors will be ignored.
    • getFieldValueOptional

      private static Object getFieldValueOptional(Object object, String fieldName)
      Returns the value of the (potentially private) field with the given name from the given object. If there is any error, then null will be returned.
      Parameters:
      object - The object
      fieldName - The name of the field whose value to obtain
      Returns:
      The field value, or null if the value could not be obtained
    • getDeclaredField

      private static Field getDeclaredField(Class<?> c, String fieldName)
      Returns the declared field with the given name in the given class, or any of its superclasses. Returns null if no such field could be found.
      Parameters:
      c - The class
      fieldName - The field name
      Returns:
      The field
    • invokeFinalizeOptional

      private static void invokeFinalizeOptional(Object object)
      Tries to invoke a "finalize(Classinvalid input: '<'?>)" method on the given object. Any error will be ignored.
      Parameters:
      object - The object