Top Description Inners Fields Constructors Methods
com.kenai.jffi

public final Class Library

extends Object
Class Inheritance
Imports
java.lang.ref.WeakReference, java.util.Map, java.util.concurrent.ConcurrentHashMap, java.util.concurrent.atomic.AtomicIntegerFieldUpdater

Represents a native library

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
Library.DefaultLibrary

A handle to the current process

Field Summary

Modifier and TypeField and Description
private static final Map<String, WeakReference<Library>>
cache

A cache of opened libraries

private volatile int
disposed

Indicates whether this library has been disposed of.

private final Foreign
foreign

A handle to the foreign interface to keep it alive as long as this object is alive

public static final int
GLOBAL

All symbols in the library are made available to other libraries

private final long
handle

The native dl/LoadLibrary handle

private static final ThreadLocal<String>
lastError

Stores the last error returned by a dlopen or dlsym call

public static final int
LAZY

Perform lazy binding.

public static final int
LOCAL

Symbols in this library are not made available to other libraries

private static final Object
lock

A lock used to serialize all dlopen/dlsym calls

private final String
name

The name of this Library

public static final int
NOW

Resolve all symbols when loading the library

private static final AtomicIntegerFieldUpdater<Library>

Constructor Summary

AccessConstructor and Description
private
Library(Foreign foreign, String name, long address)

Method Summary

Modifier and TypeMethod and Description
private static long

Returns:

The native handle for the opened library, or 0 if it failed to open.
dlopen
(Foreign foreign, String
The name of the library to open
name
,
int
The flags to pass to dlopen
flags
)

Internal wrapper around dlopen.

protected void
finalize()

Overrides java.lang.Object.finalize.

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.
public static final Library

Returns:

A Library instance representing the named library, or null if the library could not be opened.
getCachedInstance
(String
The name or path of the library to open.
name
,
int
The library flags (e.g. LAZY, NOW, LOCAL, GLOBAL)
flags
)

Gets a handle for the named library.

public static final Library

Returns:

A Library instance representing the default library.
getDefault
()

Gets a handle to the default library.

public static final String

Returns:

A String describing the last error.
getLastError
()

Gets the current error string from dlopen/LoadLibrary.

public final long

Returns:

The address of the symbol within the current address space.
getSymbolAddress
(String
The name of the symbol to locate.
name
)

Gets the address of a symbol within the Library.

public static final Library

Returns:

A Library instance representing the named library, or null if the library cannot be opened.
openLibrary
(String
The name or path of the library to open.
name
,
int
The library flags (e.g. LAZY, NOW, LOCAL, GLOBAL)
flags
)

Gets a handle for the named library

Note

This will not cache the instance, nor will it return a cached instance.

Inherited from java.lang.Object:
cloneequalsgetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

cacheback to summary
private static final Map<String, WeakReference<Library>> cache

A cache of opened libraries

disposedback to summary
private volatile int disposed

Indicates whether this library has been disposed of.

foreignback to summary
private final Foreign foreign

A handle to the foreign interface to keep it alive as long as this object is alive

GLOBALback to summary
public static final int GLOBAL

All symbols in the library are made available to other libraries

handleback to summary
private final long handle

The native dl/LoadLibrary handle

lastErrorback to summary
private static final ThreadLocal<String> lastError

Stores the last error returned by a dlopen or dlsym call

LAZYback to summary
public static final int LAZY

Perform lazy binding. Only resolve symbols as needed

LOCALback to summary
public static final int LOCAL

Symbols in this library are not made available to other libraries

lockback to summary
private static final Object lock

A lock used to serialize all dlopen/dlsym calls

nameback to summary
private final String name

The name of this Library

NOWback to summary
public static final int NOW

Resolve all symbols when loading the library

UPDATERback to summary
private static final AtomicIntegerFieldUpdater<Library> UPDATER

Constructor Detail

Libraryback to summary
private Library(Foreign foreign, String name, long address)

Method Detail

dlopenback to summary
private static long dlopen(Foreign foreign, String name, int flags)

Internal wrapper around dlopen. If the library open fails, then this stores the native error in a thread local variable for later retrieval.

Parameters
name:String

The name of the library to open

flags:int

The flags to pass to dlopen

Returns:long

The native handle for the opened library, or 0 if it failed to open.

finalizeback to summary
protected void finalize() throws Throwable

Overrides java.lang.Object.finalize.

Doc from java.lang.Object.finalize.

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. A subclass overrides the finalize method to dispose of system resources or to perform other cleanup.

When running in a Java virtual machine in which finalization has been disabled or removed, the garbage collector will never call finalize(). In a Java virtual machine in which finalization is enabled, the garbage collector might call finalize only after an indefinite delay.

The general contract of finalize is that it is invoked if and when the Java virtual machine has determined that there is no longer any means by which this object can be accessed by any thread that has not yet died, except as a result of an action taken by the finalization of some other object or class which is ready to be finalized. The finalize method may take any action, including making this object available again to other threads; the usual purpose of finalize, however, is to perform cleanup actions before the object is irrevocably discarded. For example, the finalize method for an object that represents an input/output connection might perform explicit I/O transactions to break the connection before the object is permanently discarded.

The finalize method of class Object performs no special action; it simply returns normally. Subclasses of Object may override this definition.

The Java programming language does not guarantee which thread will invoke the finalize method for any given object. It is guaranteed, however, that the thread that invokes finalize will not be holding any user-visible synchronization locks when finalize is invoked. If an uncaught exception is thrown by the finalize method, the exception is ignored and finalization of that object terminates.

After the finalize method has been invoked for an object, no further action is taken until the Java virtual machine has again determined that there is no longer any means by which this object can be accessed by any thread that has not yet died, including possible actions by other objects or classes which are ready to be finalized, at which point the object may be discarded.

The finalize method is never invoked more than once by a Java virtual machine for any given object.

Any exception thrown by the finalize method causes the finalization of this object to be halted, but is otherwise ignored.

Annotations
@Override
Exceptions
Throwable:
the Exception raised by this method
getCachedInstanceback to summary
public static final Library getCachedInstance(String name, int flags)

Gets a handle for the named library.

Parameters
name:String

The name or path of the library to open.

flags:int

The library flags (e.g. LAZY, NOW, LOCAL, GLOBAL)

Returns:Library

A Library instance representing the named library, or null if the library could not be opened.

getDefaultback to summary
public static final Library getDefault()

Gets a handle to the default library.

Returns:Library

A Library instance representing the default library.

getLastErrorback to summary
public static final String getLastError()

Gets the current error string from dlopen/LoadLibrary.

Returns:String

A String describing the last error.

getSymbolAddressback to summary
public final long getSymbolAddress(String name)

Gets the address of a symbol within the Library.

Parameters
name:String

The name of the symbol to locate.

Returns:long

The address of the symbol within the current address space.

openLibraryback to summary
public static final Library openLibrary(String name, int flags)

Gets a handle for the named library

Note

This will not cache the instance, nor will it return a cached instance. Only use when you really need a new handle for the library.

Parameters
name:String

The name or path of the library to open.

flags:int

The library flags (e.g. LAZY, NOW, LOCAL, GLOBAL)

Returns:Library

A Library instance representing the named library, or null if the library cannot be opened.

com.kenai.jffi back to summary

private final Class Library.DefaultLibrary

extends Object
Class Inheritance

A handle to the current process

Field Summary

Modifier and TypeField and Description
private static final Library

Constructor Summary

AccessConstructor and Description
private

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

INSTANCEback to summary
private static final Library INSTANCE

Constructor Detail

DefaultLibraryback to summary
private DefaultLibrary()