jnr.ffi
Class ObjectReferenceManager<T>

java.lang.Object
  extended by jnr.ffi.ObjectReferenceManager<T>
Direct Known Subclasses:
DefaultObjectReferenceManager

public abstract class ObjectReferenceManager<T>
extends Object

Provides a mapping between java objects and unique native addresses.

The native addresses generated by this class do not relate to the object's true native address (since that is not supported by most java virtual machines), but is guaranteed to be unique within an ObjectReferenceManager instance.

This would be commonly used to create a unique native pointer that can be used to retrieve an object from within a callback. e.g.

     {@code

     public interface MyLib {
         public static interface MyCallback {


Constructor Summary
ObjectReferenceManager()
           
 
Method Summary
abstract  Pointer add(T object)
          Adds a mapping from a java object to a unique native address.
 void freeReference(Pointer reference)
          Deprecated. use remove(Pointer)
abstract  T get(Pointer reference)
          Gets the java object that is mapped to the native memory address referred to by reference.
 T getObject(Pointer reference)
          Deprecated. use get(Pointer)
static
<T> ObjectReferenceManager<T>
newInstance(Runtime runtime)
           
 Pointer newReference(T object)
          Deprecated. use add(Object)
abstract  boolean remove(Pointer reference)
          Removes a mapping from java object to native pointer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ObjectReferenceManager

public ObjectReferenceManager()
Method Detail

newInstance

public static <T> ObjectReferenceManager<T> newInstance(Runtime runtime)

newReference

@Deprecated
public Pointer newReference(T object)
Deprecated. use add(Object)

Adds a mapping from a java object to a unique native address. Each call to this method is guaranteed to produce a memory address unique within the ObjectReferenceManager instance, even for the same object.

A strong reference to object is maintained internally, until remove(Pointer) is called.

Parameters:
object - The java object to generate a reference for
Returns:
A pointer representing the unique id.

freeReference

@Deprecated
public void freeReference(Pointer reference)
Deprecated. use remove(Pointer)

Removes a mapping from java object to native pointer.

Parameters:
reference - a native memory pointer.

getObject

@Deprecated
public T getObject(Pointer reference)
Deprecated. use get(Pointer)

Gets the java object that is mapped to the native memory address referred to by reference.

Parameters:
reference - a native memory pointer.
Returns:
The java object corresponding to pointer.

add

public abstract Pointer add(T object)
Adds a mapping from a java object to a unique native address. Each call to this method is guaranteed to produce a memory address unique within the ObjectReferenceManager instance, even for the same object.

A strong reference to object is maintained internally, until remove(Pointer) is called.

Parameters:
object - The java object to generate a reference for
Returns:
A pointer representing the unique id.

remove

public abstract boolean remove(Pointer reference)
Removes a mapping from java object to native pointer.

Parameters:
reference - a native memory pointer.
Returns:
true if the mapping was removed.

get

public abstract T get(Pointer reference)
Gets the java object that is mapped to the native memory address referred to by reference.

Parameters:
reference - a native memory pointer.
Returns:
The java object corresponding to pointer.


Copyright © 2013. All Rights Reserved.