org.jruby.rack.Bootstrap Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jruby-rack Show documentation
Show all versions of jruby-rack Show documentation
A servlet bridge for (Ruby-based) Rack applications that allow them
to run in Java Application servers using JRuby.
/*
* 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