Package org.jocl
Class LibTracker
java.lang.Object
org.jocl.LibTracker
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.
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 -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate 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
freeNativeLibrary
(Object library) 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
invokeFinalizeOptional
(Object object) Tries to invoke a "finalize(Classinvalid input: '<'?>)" method on the given object.private static void
shutdown()
Will be called by the shutdown hook(package private) static void
Add the given native library file to be tracked by this class.
-
Field Details
-
logger
The logger used in this class -
libraryFiles
The tracked library files that will be unloaded and deleted when the application exits -
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
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
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
Returns the value of the (potentially private) field with the given name from the given object. If there is any error, thennull
will be returned.- Parameters:
object
- The objectfieldName
- The name of the field whose value to obtain- Returns:
- The field value, or
null
if the value could not be obtained
-
getDeclaredField
Returns the declared field with the given name in the given class, or any of its superclasses. Returnsnull
if no such field could be found.- Parameters:
c
- The classfieldName
- The field name- Returns:
- The field
-
invokeFinalizeOptional
Tries to invoke a "finalize(Classinvalid input: '<'?>)" method on the given object. Any error will be ignored.- Parameters:
object
- The object
-