Top Description Inners Fields Constructors Methods
com.kenai.jffi

public final Class ClosureManager

extends Object
Class Inheritance
Imports
java.lang.ref.Reference, .SoftReference, java.lang.reflect.Method, java.util.Map, .WeakHashMap

Allocates and manages the lifecycle of native closures (aka callbacks)

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
ClosureManager.SingletonHolder

Holder class to do lazy allocation of the ClosureManager instance

Field Summary

Modifier and TypeField and Description
private final Map<CallContext, Reference<ClosurePool>>
poolMap

ClosurePool instances are linked via a SoftReference in the lookup map, so when all closure instances that that were allocated from the ClosurePool have been reclaimed, and there is memory pressure, the native closure pool can be freed.

Constructor Summary

AccessConstructor and Description
private
ClosureManager()

Constructs a ClosureManager

Method Summary

Modifier and TypeMethod and Description
public final synchronized ClosurePool
public static ClosureManager

Returns:

An instance of a ClosureManager
getInstance
()

Gets the global instance of the ClosureManager

public final Closure.Handle

Returns:

A new Closure.Handle instance.
newClosure
(Closure
The java object to be called when the native closure is invoked.
closure
,
Type
The return type of the closure.
returnType
,
Type[]
The parameter types of the closure.
parameterTypes
,
CallingConvention
The calling convention of the closure.
convention
)

Wraps a java object that implements the Closure interface in a native closure.

public final Closure.Handle

Returns:

A new Closure.Handle instance.
newClosure
(Closure
The java object to be called when the native closure is invoked.
closure
,
CallContext
The call context (return type, param types, convention) of the Closure
callContext
)

Wraps a java object that implements the Closure interface in a native closure.

public ClosureMagazine
newClosureMagazine(CallContext callContext, Method method)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

poolMapback to summary
private final Map<CallContext, Reference<ClosurePool>> poolMap

ClosurePool instances are linked via a SoftReference in the lookup map, so when all closure instances that that were allocated from the ClosurePool have been reclaimed, and there is memory pressure, the native closure pool can be freed. This will allow the CallContext instance to also be collected if it is not strongly referenced elsewhere, and ejected from the CallContextCache

Constructor Detail

ClosureManagerback to summary
private ClosureManager()

Constructs a ClosureManager

Method Detail

getClosurePoolback to summary
public final synchronized ClosurePool getClosurePool(CallContext callContext)
getInstanceback to summary
public static ClosureManager getInstance()

Gets the global instance of the ClosureManager

Returns:ClosureManager

An instance of a ClosureManager

newClosureback to summary
public final Closure.Handle newClosure(Closure closure, Type returnType, Type[] parameterTypes, CallingConvention convention)

Wraps a java object that implements the Closure interface in a native closure.

Parameters
closure:Closure

The java object to be called when the native closure is invoked.

returnType:Type

The return type of the closure.

parameterTypes:Type[]

The parameter types of the closure.

convention:CallingConvention

The calling convention of the closure.

Returns:Closure.Handle

A new Closure.Handle instance.

newClosureback to summary
public final Closure.Handle newClosure(Closure closure, CallContext callContext)

Wraps a java object that implements the Closure interface in a native closure.

Parameters
closure:Closure

The java object to be called when the native closure is invoked.

callContext:CallContext

The call context (return type, param types, convention) of the Closure

Returns:Closure.Handle

A new Closure.Handle instance.

newClosureMagazineback to summary
public ClosureMagazine newClosureMagazine(CallContext callContext, Method method)
com.kenai.jffi back to summary

private final Class ClosureManager.SingletonHolder

extends Object
Class Inheritance

Holder class to do lazy allocation of the ClosureManager instance

Field Summary

Modifier and TypeField and Description
pack-priv static final ClosureManager

Constructor Summary

AccessConstructor and Description
private

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

INSTANCEback to summary
pack-priv static final ClosureManager INSTANCE

Constructor Detail

SingletonHolderback to summary
private SingletonHolder()