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

org.jruby.rack.Bootstrap Maven / Gradle / Ivy

Go to download

A servlet bridge for (Ruby-based) Rack applications that allow them to run in Java Application servers using JRuby.

There is a newer version: 1.2.2
Show newest version
/*
 * Copyright (c) 2015-2016 Karol Bucek LTD.
 * This source code is available under the MIT license.
 * See the file LICENSE.txt for details.
 */
package org.jruby.rack;

import java.util.Iterator;
import java.util.ServiceLoader;

/**
 * Bootstrap mechanism for JRuby-Rack (service-loader based).
 *
 * @author kares
 */
public abstract class Bootstrap {

    public static Bootstrap load(final ClassLoader loader) {
        ServiceLoader service = ServiceLoader.load(Bootstrap.class, loader);
        Iterator it = service.iterator();
        if ( it.hasNext() ) {
            return it.next(); // first one wins
        }


        return null; // TODO
    }

    public abstract RackContext newRackContext() ;

    public RackApplicationFactory newApplicationFactory(RackConfig config) {
        final RackApplicationFactory factory = realApplicationFactoryInstance();
        final Integer maxRuntimes = config.getMaximumRuntimes();
        // when runtime mix/max values not specified we assume a shared (threadsafe) runtime :
        if ( maxRuntimes == null || maxRuntimes.intValue() == 1 ) {
            return new SharedRackApplicationFactory(factory);
        }
        else {
            return config.isSerialInitialization() ?
                    new SerialPoolingRackApplicationFactory(factory) :
                    new PoolingRackApplicationFactory(factory) ;
        }
    }

    protected RackApplicationFactory realApplicationFactoryInstance() {
        return new DefaultRackApplicationFactory();
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy