Package org.jocl
Class LibTracker
- java.lang.Object
-
- org.jocl.LibTracker
-
class LibTracker extends java.lang.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 java.util.Set<java.io.File>
libraryFiles
The tracked library files that will be unloaded and deleted when the application exitsprivate static java.util.logging.Logger
logger
The logger used in this classprivate static java.lang.Thread
shutdownHook
The shutdown hook thread that will attempt to unload and delete the library files
-
Constructor Summary
Constructors Modifier Constructor Description private
LibTracker()
Private constructor to prevent instantiation
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static void
deleteNativeLibraries()
Try to delete all library files that are tracked by this class.private static void
freeNativeLibraries()
Free the native libraries that have been registered in this class.private static void
freeNativeLibrary(java.lang.Object library)
Free the given library object by invoking its "finalize(Class>)" method.private static java.lang.reflect.Field
getDeclaredField(java.lang.Class<?> c, java.lang.String fieldName)
Returns the declared field with the given name in the given class, or any of its superclasses.private static java.lang.Object
getFieldValueOptional(java.lang.Object object, java.lang.String fieldName)
Returns the value of the (potentially private) field with the given name from the given object.private static void
invokeFinalizeOptional(java.lang.Object object)
Tries to invoke a "finalize(Class>)" method on the given object.private static void
shutdown()
Will be called by the shutdown hook(package private) static void
track(java.io.File libraryFile)
Add the given native library file to be tracked by this class.
-
-
-
Field Detail
-
logger
private static final java.util.logging.Logger logger
The logger used in this class
-
libraryFiles
private static final java.util.Set<java.io.File> libraryFiles
The tracked library files that will be unloaded and deleted when the application exits
-
shutdownHook
private static java.lang.Thread shutdownHook
The shutdown hook thread that will attempt to unload and delete the library files
-
-
Method Detail
-
track
static void track(java.io.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(java.lang.Object library)
Free the given library object by invoking its "finalize(Class>)" 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 java.lang.Object getFieldValueOptional(java.lang.Object object, java.lang.String fieldName)
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
private static java.lang.reflect.Field getDeclaredField(java.lang.Class<?> c, java.lang.String fieldName)
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
private static void invokeFinalizeOptional(java.lang.Object object)
Tries to invoke a "finalize(Class>)" method on the given object. Any error will be ignored.- Parameters:
object
- The object
-
-