Package electrostatic4j.snaploader
Class NativeBinaryLoader
java.lang.Object
electrostatic4j.snaploader.NativeBinaryLoader
- Direct Known Subclasses:
ConcurrentNativeBinaryLoader
A cross-platform utility for extracting and loading native binaries based on
the variant properties (OS + ARCH + VM).
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected FileExtractionListenerprotected FileExtractorAn Output stream concrete provider for library extraction.protected final LibraryInfoprotected FileLocalizingListenerprotected intprotected NativeBinaryLoadingListenerprotected NativeDynamicLibraryThe native dynamic library object representing the library to extract and load.protected intprotected List<NativeDynamicLibrary>protected booleanFlag for retry loading with clean extract if UnSatisfiedLinkError is thrown.protected SystemDetectionListener -
Constructor Summary
ConstructorsConstructorDescriptionNativeBinaryLoader(LibraryInfo libraryInfo) Instantiates a native dynamic library loader to extract and load a system-specific native dynamic library.NativeBinaryLoader(List<NativeDynamicLibrary> registeredLibraries, LibraryInfo libraryInfo) Instantiates a native dynamic library loader to extract and load a system-specific native dynamic library. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidcleanExtractBinary(NativeDynamicLibrary library) Cleanly extracts and loads the native binary to the current [user.dir].Retrieves the native dynamic library object representing the library to extract and load.protected FileExtractorInitializes a filesystem extractor object if the filesystem extractor object associated with this loader isn't defined.Initializes the platform-dependent native dynamic library.booleanTests the retry with clean extraction flag, default value is false.protected voidloadBinary(NativeDynamicLibrary library, LoadingCriterion loadingCriterion) Loads a native binary into the virtual process address space from a specified native library data structure defining the directory path.loadLibrary(LoadingCriterion criterion) Extracts and loads the system and the architecture-specific library from the output jar to a specified directory according to a loading criterion (incremental-load or clean-extract).protected voidLoads a native binary from the system directories into the process virtual address space using the library basename in a platform-dependent way.protected LibraryLocatorpreInitLibraryLocator(FileExtractor extractor) registerNativeLibraries(NativeDynamicLibrary[] nativeDynamicLibraries) setLibraryExtractionListener(FileExtractionListener libraryExtractionListener) setLibraryLocalizingListener(FileLocalizingListener libraryLocalizingListener) setLoggingEnabled(boolean loggingEnabled) Enables the logging for this object, default value is false.setMaxNumberOfLoadingFailure(int maxNumberOfLoadingFailure) setNativeBinaryLoadingListener(NativeBinaryLoadingListener nativeBinaryLoadingListener) setRetryWithCleanExtraction(boolean retryWithCleanExtraction) Enables the retry with clean extraction after a load failure, default value is false.setSystemDetectionListener(SystemDetectionListener systemDetectionListener)
-
Field Details
-
libraryInfo
-
registeredLibraries
-
nativeBinaryLoadingListener
-
systemDetectionListener
-
libraryLocalizingListener
-
libraryExtractionListener
-
libraryExtractor
An Output stream concrete provider for library extraction. -
nativeDynamicLibrary
The native dynamic library object representing the library to extract and load. -
retryWithCleanExtraction
protected boolean retryWithCleanExtractionFlag for retry loading with clean extract if UnSatisfiedLinkError is thrown. -
maxNumberOfLoadingFailure
protected int maxNumberOfLoadingFailure -
numberOfLoadingFailure
protected int numberOfLoadingFailure
-
-
Constructor Details
-
NativeBinaryLoader
Instantiates a native dynamic library loader to extract and load a system-specific native dynamic library. -
NativeBinaryLoader
Instantiates a native dynamic library loader to extract and load a system-specific native dynamic library.
-
-
Method Details
-
registerNativeLibraries
-
initPlatformLibrary
Initializes the platform-dependent native dynamic library.- Returns:
- this instance for chained invocations
- Throws:
UnSupportedSystemError- if the OS is not supported by jSnapLoader
-
loadLibrary
Extracts and loads the system and the architecture-specific library from the output jar to a specified directory according to a loading criterion (incremental-load or clean-extract). The directory is determined by the selectedNativeDynamicLibraryfrom the registered platform libraries.Note: The default loading action for Android Systems is loading the libraries from the System directories (i.e., /lib/ABI inside the APK packages), while the default loading action for other desktop systems is determined by the user through this parameterized function.
Fallback loading routines can be implemented as needed via
NativeBinaryLoadingListener.onLoadingFailure(NativeBinaryLoader, CallingStackMetaData)and are left for the user applications.- Parameters:
criterion- the initial loading criterion, eitherLoadingCriterion.INCREMENTAL_LOADING,LoadingCriterion.CLEAN_EXTRACTIONorLoadingCriterion.SYSTEM_LOADfor loading native dlls from system directories.- Returns:
- this instance for chained invocations
- Throws:
IOException- if the library to extract is not present in the jar filesystemException
-
getNativeDynamicLibrary
Retrieves the native dynamic library object representing the library to extract and load.- Returns:
- an object representing the platform-dependent native dynamic library
-
setLoggingEnabled
Enables the logging for this object, default value is false.- Parameters:
loggingEnabled- true to enable logging, false otherwise
-
isRetryWithCleanExtraction
public boolean isRetryWithCleanExtraction()Tests the retry with clean extraction flag, default value is false.- Returns:
- true if enabled, false otherwise
-
setRetryWithCleanExtraction
Enables the retry with clean extraction after a load failure, default value is false.- Parameters:
retryWithCleanExtraction- true to enable the flag, false otherwise
-
getRegisteredLibraries
-
getNativeBinaryLoadingListener
-
setNativeBinaryLoadingListener
public NativeBinaryLoader setNativeBinaryLoadingListener(NativeBinaryLoadingListener nativeBinaryLoadingListener) -
getSystemDetectionListener
-
setSystemDetectionListener
public NativeBinaryLoader setSystemDetectionListener(SystemDetectionListener systemDetectionListener) -
getLibraryExtractionListener
-
setLibraryExtractionListener
public NativeBinaryLoader setLibraryExtractionListener(FileExtractionListener libraryExtractionListener) -
getLibraryLocalizingListener
-
setLibraryLocalizingListener
public NativeBinaryLoader setLibraryLocalizingListener(FileLocalizingListener libraryLocalizingListener) -
setMaxNumberOfLoadingFailure
-
loadSystemBinary
protected void loadSystemBinary()Loads a native binary from the system directories into the process virtual address space using the library basename in a platform-dependent way. -
loadBinary
protected void loadBinary(NativeDynamicLibrary library, LoadingCriterion loadingCriterion) throws Exception Loads a native binary into the virtual process address space from a specified native library data structure defining the directory path.- Parameters:
library- the platform-specific library to loadloadingCriterion- pass the loading criterion condition to the calling stack metadata structure- Throws:
IOException- in case the binary to be extracted is not found on the specified jarLoadingRetryExhaustionException- if the number of loading failure exceeds the specified number.Exception
-
cleanExtractBinary
Cleanly extracts and loads the native binary to the current [user.dir].- Parameters:
library- the platform-specific library to extract and load- Throws:
IOException- in case the binary to be extracted is not found on the specified jar, or an interrupted I/O operation has occurredException
-
initializeLibraryExtractor
Initializes a filesystem extractor object if the filesystem extractor object associated with this loader isn't defined.- Parameters:
library- the native dynamic library to load- Returns:
- a new FileExtractor object that represents an output stream provider
- Throws:
IOException- if the jar filesystem to be located is not found, or if the extraction destination is not foundException
-
preInitLibraryLocator
-