Package com.kenai.jffi
Class ClosureManager
- java.lang.Object
-
- com.kenai.jffi.ClosureManager
-
public final class ClosureManager extends java.lang.Object
Allocates and manages the lifecycle of native closures (aka callbacks)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
ClosureManager.SingletonHolder
Holder class to do lazy allocation of the ClosureManager instance
-
Field Summary
Fields Modifier and Type Field Description private java.util.Map<CallContext,java.lang.ref.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
Constructors Modifier Constructor Description private
ClosureManager()
Constructs a ClosureManager
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ClosurePool
getClosurePool(CallContext callContext)
static ClosureManager
getInstance()
Gets the global instance of theClosureManager
Closure.Handle
newClosure(Closure closure, CallContext callContext)
Wraps a java object that implements theClosure
interface in a native closure.Closure.Handle
newClosure(Closure closure, Type returnType, Type[] parameterTypes, CallingConvention convention)
Wraps a java object that implements theClosure
interface in a native closure.ClosureMagazine
newClosureMagazine(CallContext callContext, java.lang.reflect.Method method)
-
-
-
Field Detail
-
poolMap
private final java.util.Map<CallContext,java.lang.ref.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 theCallContextCache
-
-
Method Detail
-
getInstance
public static ClosureManager getInstance()
Gets the global instance of theClosureManager
- Returns:
- An instance of a
ClosureManager
-
newClosure
public final Closure.Handle newClosure(Closure closure, Type returnType, Type[] parameterTypes, CallingConvention convention)
Wraps a java object that implements theClosure
interface in a native closure.- Parameters:
closure
- The java object to be called when the native closure is invoked.returnType
- The return type of the closure.parameterTypes
- The parameter types of the closure.convention
- The calling convention of the closure.- Returns:
- A new
Closure.Handle
instance.
-
newClosure
public final Closure.Handle newClosure(Closure closure, CallContext callContext)
Wraps a java object that implements theClosure
interface in a native closure.- Parameters:
closure
- The java object to be called when the native closure is invoked.callContext
- The call context (return type, param types, convention) of the Closure- Returns:
- A new
Closure.Handle
instance.
-
getClosurePool
public final ClosurePool getClosurePool(CallContext callContext)
-
newClosureMagazine
public ClosureMagazine newClosureMagazine(CallContext callContext, java.lang.reflect.Method method)
-
-