FileDocCategorySizeDatePackage
RubyObjectPool.javaAPI DocGlassfish v2 API5286Thu Jun 21 14:52:16 BST 2007com.sun.grizzly.rails

RubyObjectPool

public class RubyObjectPool extends Object
An object pool for ruby runtime.
author
TAKAI Naoto

Fields Summary
private static long
DEFAULT_TIMEOUT
How long to wait before given up.
private String
jrubyLib
JRUBY_LIB directory
private int
numberOfRuntime
The number of runtime.
private BlockingQueue
queue
Runtime queue
private String
railsRoot
RAILS_ROOT directory
Constructors Summary
Methods Summary
public org.jruby.RubybollowRuntime()
Retrives ruby runtime from the object pool.

return
JRuby runtime.


                    
       
        return queue.poll();
    
public java.lang.StringgetJrubyLib()
Gets JRUBY_LIB directory.

return
JRUBY_LIB directory.

        return jrubyLib;
    
public intgetNumberOfRuntime()
Gets the number of directory.

return
the number of directory;

        return numberOfRuntime;
    
public java.lang.StringgetRailsRoot()
Gets RAILS_ROOT directory.

return
RAILS_ROOT directory.

        return railsRoot;
    
protected java.util.concurrent.BlockingQueuegetRubyRuntimeQueue()

        return queue;
    
protected org.jruby.RubyinitializeRubyRuntime()

        return JavaEmbedUtils.initialize(new ArrayList<String>());
    
protected voidloadRubyLibraries(org.jruby.Ruby runtime)

        LoadService loadService = runtime.getLoadService();

        // load rails
        loadService.require(railsRoot + "/config/environment.rb");
    
public voidreturnRuntime(org.jruby.Ruby runtime)
Returns runtime to the object pool.

param
runtime

        queue.offer(runtime);
    
public voidsetJrubyLib(java.lang.String jrubyLib)
Sets JRUBY_LIB directory.

param
jrubyLib JRUBY_LIB directory.

        this.jrubyLib = jrubyLib;
    
public voidsetNumberOfRuntime(int numberOfRuntime)
Sets the number of pooling runtime.

param
numberOfRuntime the number of runtime.

        this.numberOfRuntime = numberOfRuntime;
    
public voidsetRailsRoot(java.lang.String railsRoot)
Sets RAILS_ROOT directory.

param
railsRoot RAILS_ROOT directory.

        this.railsRoot = railsRoot;
    
public voidstart()
Starts the object pool.

        if (jrubyLib == null || railsRoot == null) {
            throw new IllegalStateException("jrubyLib or railsRoot can not be null.");
        }
        for (int i = 0; i < numberOfRuntime; i++) {
            Ruby runtime = initializeRubyRuntime();
            loadRubyLibraries(runtime);

            queue.offer(runtime);
        }
    
public voidstop()
Shutdowns the object pool.

        for (Ruby ruby : queue) {
            ruby.tearDown();
        }
        queue.clear();