NativeDepsLoader#
- public class NativeDepsLoader#
This class will load the native dependencies.
Method Summary
Extract a native library resource without loading it.
Allows other libraries to reuse the same native deps loading logic.
Load the native libraries needed for libcudf, if not loaded already.
Allows other libraries to reuse the same native deps loading logic.
Allows other libraries to reuse the same native deps loading logic.
Optionally load native dependencies.
Static Methods
- public static void loadNativeDeps()#
Load the native libraries needed for libcudf, if not loaded already.
- public static void loadNativeDeps(
- String[] loadOrder
Allows other libraries to reuse the same native deps loading logic.
Libraries will be searched for under ${os.arch}/${os.name}/ in the class path using the class loader for this class.
Because this just loads the libraries and loading the libraries themselves needs to be a singleton operation it is recommended that any library using this provide their own wrapper function similar to
This function should be called from the static initialization block of any class that uses JNI. For exampleprivate static boolean loaded = false; static synchronized void loadNativeDeps() { if (!loaded) { try { // If you also depend on the cudf liobrary being loaded, be sure it is loaded // first ai.rapids.cudf.NativeDepsLoader.loadNativeDeps(); ai.rapids.cudf.NativeDepsLoader.loadNativeDeps(new String[]{...}); loaded = true; } catch (Throwable t) { log.error("Could not load ...", t); } } }
public class UsesJNI { static { MyNativeDepsLoader.loadNativeDeps(); } }
- Parameters:
loadOrder – the base name of the libraries. For example libfoo.so would be passed in as “foo”. The libraries are loaded in the order provided.
- Throws:
IOException– on any error trying to load the libraries.
- public static void loadNativeDeps(
- String[] loadOrder,
- boolean preserveDeps
Allows other libraries to reuse the same native deps loading logic.
Libraries will be searched for under ${os.arch}/${os.name}/ in the class path using the class loader for this class.
Because this just loads the libraries and loading the libraries themselves needs to be a singleton operation it is recommended that any library using this provide their own wrapper function similar to
This function should be called from the static initialization block of any class that uses JNI. For exampleprivate static boolean loaded = false; static synchronized void loadNativeDeps() { if (!loaded) { try { // If you also depend on the cudf liobrary being loaded, be sure it is loaded // first ai.rapids.cudf.NativeDepsLoader.loadNativeDeps(); ai.rapids.cudf.NativeDepsLoader.loadNativeDeps(new String[]{...}); loaded = true; } catch (Throwable t) { log.error("Could not load ...", t); } } }
public class UsesJNI { static { MyNativeDepsLoader.loadNativeDeps(); } }
- Parameters:
loadOrder – the base name of the libraries. For example libfoo.so would be passed in as “foo”. The libraries are loaded in the order provided.
preserveDeps – if false the dependencies will be deleted immediately after loading rather than on exit.
- Throws:
IOException– on any error trying to load the libraries.
- public static boolean loadOptionalNativeDeps(String[] loadOrder)#
Optionally load native dependencies.
This method attempts to load the specified libraries but does not throw exceptions on failure. Instead, it returns true if all libraries were loaded successfully, false otherwise.
- Parameters:
loadOrder – the base name of the libraries. For example libfoo.so would be passed in as “foo”. The libraries are loaded in the order provided.
- Returns:
true if all libraries were loaded successfully, false otherwise
- public static File loadNativeDep(
- String depName,
- boolean preserveDep
Allows other libraries to reuse the same native deps loading logic.
Library will be searched for under ${os.arch}/${os.name}/ in the class path using the class loader for this class.
- Parameters:
depName – the base name of the library. For example libfoo.so would be passed in as “foo”. The libraries are loaded in the order provided.
preserveDep – if false the dependencies will be deleted immediately after loading rather than on exit.
- Throws:
IOException– on any error trying to load the libraries.- Returns:
path where the dependency was loaded
- public static File extractNativeDep( ) throws IOException#
Extract a native library resource without loading it.
The library is searched for under
${os.arch}/${os.name}/in the class path using the class loader for this class. Both conventional resources and chunked resources are supported.The destination is replaced only after the resource has been completely extracted and validated. If extraction fails, an existing destination is left unchanged.
- Parameters:
depName – the base name of the library; for example, use
"cudf"forlibcudf.sodestination – the file where the reconstructed library will be written
- Throws:
IOException– on any error locating or extracting the library- Returns:
the absolute destination file
- public static boolean libraryLoaded()#