All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.sun.grizzly.jruby.rack.SingleThreadedRackAdapter Maven / Gradle / Ivy

package com.sun.grizzly.jruby.rack;

import com.sun.grizzly.pool.DynamicPool;
import com.sun.grizzly.pool.DynamicPoolConfig;
import com.sun.grizzly.jruby.RailsAdapter;
import org.jruby.Ruby;

/**
 * This is a single threaded Rack Adapter - basically it is used when the Ruby
 * framework is single threaded and we need multiple JRuby runtimes to process
 * concurrent requests.
 */
public class SingleThreadedRackAdapter implements RackAdapter {
    private final RackApplicationFactory myFactory;
    private final DynamicPoolConfig myConfig;
    private DynamicPool pool;
    private final int numThreads;
    public SingleThreadedRackAdapter(RackApplicationFactory f, RailsAdapter settings) {
        myConfig = new DynamicPoolConfig(settings.getRuntimes(), -1, settings.getMaxRuntimes(), settings.getMinRuntimes(), -1, -1, -1, settings.async(), false);
        // Using defaults for, in order, maximum generating, downThreshold, queueThreshold, newThreshold
        numThreads = settings.getNumThreads();
        myFactory = f;
        RackApplicationPoolAdapter adapter = new RackApplicationPoolAdapter(myFactory, settings);
        pool = new DynamicPool(adapter, myConfig);
        pool.start(numThreads);
    }
//    public void initialize() {
//        RackApplicationPoolAdapter adapter = new RackApplicationPoolAdapter(myFactory);
//        pool = new DynamicPool(adapter, myConfig);
//        pool.start(numThreads);
//
//    }

    // Shuts the adapter down
    public void shutdown() {
        myFactory.destroy();
        pool.stop();
    }// Returns an application suitable for processing a request
    public RackApplication getApp() {
        return pool.borrowObject();
    }// Indicates that the app is done processing the request
    public void returnApp(RackApplication returned) {
        pool.returnObject(returned);
    }
    public RackApplicationFactory getFactory() {
        return myFactory;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy