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

RailsSelectorThread

public class RailsSelectorThread extends com.sun.enterprise.web.connector.grizzly.SelectorThread
JRuby on rails implementation of Grizzly SelectorThread
author
TAKAI Naoto
author
Jeanfrancois Arcand

Fields Summary
private static final String
NUMBER_OF_RUNTIME
protected static boolean
embeddedInGlassFish
Is Grizzly embedded in GlassFish.
private String
jrubyLib
private int
numberOfRuntime
private RubyObjectPool
pool
private String
railsRoot
Constructors Summary
Methods Summary
public java.lang.StringgetRailsRoot()


       
        return railsRoot;
    
public voidinitEndpoint()

        if (embeddedInGlassFish) {
            railsRoot = System.getProperty("com.sun.aas.instanceRoot") 
                + "/applications/rails";
        }
        setupSystemProperties();
        initializeRubyRuntime();        
        
        setBufferResponse(false);
        
        asyncExecution = true;
        DefaultAsyncHandler asyncHandler = new DefaultAsyncHandler();
        setAsyncHandler(asyncHandler);
        
        RailAsyncFilter railAsyncFilter = new RailAsyncFilter();
        railAsyncFilter.setRubyRuntimeQueue(pool.getRubyRuntimeQueue());
        asyncHandler.addAsyncFilter(railAsyncFilter);
        
        adapter = new RailsAdapter(pool,railAsyncFilter);
        
        algorithmClassName = StaticStreamAlgorithm.class.getName();
        super.initEndpoint();  
    
protected voidinitializeRubyRuntime()

        pool = new RubyObjectPool();
        pool.setNumberOfRuntime(numberOfRuntime);
        pool.setJrubyLib(jrubyLib);
        pool.setRailsRoot(railsRoot);

        try {
            pool.start();
        } catch (Throwable t) {
            logger.log(Level.WARNING, t.getMessage());
        }
    
public voidsetNumberOfRuntime(int numberOfRuntime)

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

        this.railsRoot = railsRoot;
    
protected voidsetupSystemProperties()

        String jrubyBase = System.getProperty("jruby.base");
        String jrubyHome = System.getProperty("jruby.home");
        String jrubyShell = System.getProperty("jruby.shell");
        String jrubyScript = System.getProperty("jruby.script");
        
        if (System.getProperty(NUMBER_OF_RUNTIME) != null){
            try{
                numberOfRuntime = Integer.parseInt(
                        System.getProperty(NUMBER_OF_RUNTIME));
            } catch (NumberFormatException ex){
                SelectorThread.logger().log(Level.WARNING, 
                                            "Invalid number of Runtime");
            }
        }        

        if (jrubyBase == null) {
            throw new IllegalStateException("Set system property jruby.base to JRuby directory");
        }
        if (jrubyHome == null) {
            System.setProperty("jruby.home", jrubyBase);
        }
        if (jrubyShell == null) {
            System.setProperty("jruby.shell", "");
        }
        if (jrubyScript == null) {
            System.setProperty("jruby.script", "");
        }

        jrubyLib = System.getProperty("jruby.lib");
        if (jrubyLib == null) {
            jrubyLib = jrubyBase + "/lib";
            System.setProperty("jruby.lib", jrubyLib);
        }
    
public synchronized voidstopEndpoint()

        pool.stop();

        super.stopEndpoint();