Package name.pachler.nio.file.impl
Class NativeLibLoader
java.lang.Object
name.pachler.nio.file.impl.NativeLibLoader
This class loads native libraries packaged in the JAR file that this class resides in.
The NativeLibLoader supports a number of preconfigured native libraries,
which it looks up by their name to find, extract and load their binary file.
For each platform there exists a PlatformArchLibSet, which defines a list of
native libraries available for that platform in LibraryImplementation instances.
When a library "foo" is requested through the loadLibrary() method,
all LibraryImplementation instances for the current platform's PlatformArchLibSet
is searched.
If a matching LibraryImplementation is found, first the library extraction and
loading is attempted with a default library name. If that fails, extraction and
loading is attempted with a unique temporary file name for the library.
the steps are the following:
So for a library "foo" stored in the JAR as "Windows/mylib.dll" with version 1.0, for PRODUCTNAME being "bar", the default library path would be "c:\Documents and Settings\myuser\temp\bar-1-0-mylib.dll"
- It is attempted to open and lock file indicated by the library path for reading. If successful, the integrity if the file is checked (if it is the same as the one stored in the JAR file. If successful the library is loaded.
- If the step above fails, it is attempted to open and lock the default library file for writing. If successful, the library file is extracted to the path and the library is loaded from there.
The Default Library Path
The default library path is something like "/tmp/bar-1-0-mylib.so". Because it remains the same on multiple invocations of the same program, one program might find a library file from a previously running program that hasn't been cleaned up yet. The library file might even be there from a program that is still running, creating the potential for race conditions, so the implementation is careful to avoid clashes in such cases (such as two JVMs trying to extract the same library to the same file at the same time). The default library path is formed as {tempdir}/{productname}-{major}-{minor}-{binaryname}, where {productname} is the product name that's configured in NativeLibLoader's PRODUCTNAME static variable, {major} and {minor} are the major and minor versions configured for the LibraryImplementation, and {binaryname} is the name of the binary as it is stored in the JAR (without the path), like mylib.so.So for a library "foo" stored in the JAR as "Windows/mylib.dll" with version 1.0, for PRODUCTNAME being "bar", the default library path would be "c:\Documents and Settings\myuser\temp\bar-1-0-mylib.dll"
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
NativeLibLoader
public NativeLibLoader()
-
-
Method Details
-
loadLibrary
-