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();
}
});
}
Aggregations