Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package org.jruby.ext.ffi.jffi;
 import org.jruby.Ruby;
Manages Callback instances for the low level FFI backend.
public class CallbackManager extends org.jruby.ext.ffi.CallbackManager {
            = new WeakHashMap<CallbackInfoNativeCallbackFactory>();

Holder for the single instance of CallbackManager
    private static final class SingletonHolder {
        static final CallbackManager INSTANCE = new CallbackManager();

Gets the singleton instance of CallbackManager
    public static final CallbackManager getInstance() {
        return .;
Creates a Callback class for a ruby runtime

runtime The runtime to create the class for
module The module to place the class in
The newly created ruby class
    public static RubyClass createCallbackClass(Ruby runtimeRubyModule module) {
        RubyClass cbClass = module.defineClassUnder("Callback"module.getClass("Pointer"),
        return cbClass;
    public final org.jruby.ext.ffi.Pointer getCallback(Ruby runtimeCallbackInfo cbInfoObject proc) {
        return proc instanceof RubyObject
                ? getCallbackFactory(runtimecbInfo).getCallback((RubyObjectproc)
                : getCallbackFactory(runtimecbInfo).newCallback(proc);
    public final synchronized NativeCallbackFactory getCallbackFactory(Ruby runtimeCallbackInfo cbInfo) {
        NativeCallbackFactory factory = .get(cbInfo);
        if (factory == null) {
            .put(cbInfofactory = new NativeCallbackFactory(runtimecbInfo));
        return factory;

    final CallbackMemoryIO newClosure(Ruby runtimeType returnTypeType[] parameterTypes
            Object procCallingConvention convention) {
        NativeFunctionInfo info = new NativeFunctionInfo(runtimereturnTypeparameterTypesconvention);
        final NativeClosureProxy cbProxy = new NativeClosureProxy(runtimeinfoproc);
        final Closure.Handle handle = ClosureManager.getInstance().newClosure(cbProxyinfo.callContext);
        return new CallbackMemoryIO(runtimehandleproc);
New to GrepCode? Check out our FAQ X