Search in sources :

Example 1 with Finalizable

use of org.jruby.Finalizable in project jo by headius.

the class JoLibrary method load.

public void load(Ruby runtime, boolean wrap) throws IOException {
    RubyModule jo = runtime.defineModule("Jo");
    final ExecutorService executor = Executors.newCachedThreadPool(new ThreadFactory() {

        public Thread newThread(Runnable r) {
            Thread t = new Thread(r);
            t.setDaemon(true);
            return t;
        }
    });
    jo.setInternalVariable("executor", executor);
    RubyClass joFuture = jo.defineClassUnder("Future", runtime.getObject(), ObjectAllocator.NOT_ALLOCATABLE_ALLOCATOR);
    RubyClass joChannel = jo.defineClassUnder("Channel", runtime.getObject(), ObjectAllocator.NOT_ALLOCATABLE_ALLOCATOR);
    jo.defineAnnotatedMethods(JoMethods.class);
    joFuture.defineAnnotatedMethods(JoFuture.class);
    joChannel.defineAnnotatedMethods(JoChannel.class);
    runtime.addFinalizer(new Finalizable() {

        public void finalize() {
            executor.shutdown();
        }
    });
}
Also used : ThreadFactory(java.util.concurrent.ThreadFactory) RubyModule(org.jruby.RubyModule) Finalizable(org.jruby.Finalizable) ExecutorService(java.util.concurrent.ExecutorService) RubyClass(org.jruby.RubyClass)

Aggregations

ExecutorService (java.util.concurrent.ExecutorService)1 ThreadFactory (java.util.concurrent.ThreadFactory)1 Finalizable (org.jruby.Finalizable)1 RubyClass (org.jruby.RubyClass)1 RubyModule (org.jruby.RubyModule)1