Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 7 additions & 12 deletions src/main/java/org/jruby/rack/DefaultErrorApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ static Exception getException(RackEnvironment env) {
private class Response implements RackResponse {

private int status = 500;
@SuppressWarnings("rawtypes")
private Map headers = Collections.EMPTY_MAP;
private Map<String, ?> headers = Collections.emptyMap();
private String body;

protected final RackEnvironment env;
Expand All @@ -103,14 +102,13 @@ public void setStatus(int status) {
this.status = status;
}

@SuppressWarnings("rawtypes")
public Map getHeaders() {
public Map<String, ?> getHeaders() {
return headers;
}

@SuppressWarnings("unused")
public void setHeaders(@SuppressWarnings("rawtypes") Map headers) {
this.headers = headers == null ? Collections.EMPTY_MAP : headers;
public void setHeaders(Map<String, ?> headers) {
this.headers = headers == null ? Collections.emptyMap() : headers;
}

public String getBody() {
Expand Down Expand Up @@ -161,15 +159,12 @@ private void log(RackLogger.Level level, String message, Throwable e) {

}

@SuppressWarnings("rawtypes")
public static void defaultRespond(final RackResponse rackResponse,
final RackResponseEnvironment responseEnv) throws IOException {
responseEnv.setStatus( rackResponse.getStatus() );
@SuppressWarnings("unchecked")
final Set<Map.Entry> headers = rackResponse.getHeaders().entrySet();
for ( Iterator<Map.Entry> it = headers.iterator(); it.hasNext(); ) {
final Map.Entry entry = it.next();
final String key = entry.getKey().toString();
final Set<? extends Map.Entry<String, ?>> headers = rackResponse.getHeaders().entrySet();
for (final Map.Entry<String, ?> entry : headers) {
final String key = entry.getKey();
final Object value = entry.getValue();
responseEnv.addHeader(key, value != null ? value.toString() : null);
}
Expand Down
7 changes: 1 addition & 6 deletions src/main/java/org/jruby/rack/DefaultRackApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,8 @@ public RackResponse call(final RackEnvironment env) {
final IRubyObject app = getApplication();
final Ruby runtime = getRuntime();
final IRubyObject servlet_env = JavaEmbedUtils.javaToRuby(runtime, env);
//try { // app.call(env) :
final IRubyObject response = app.callMethod(runtime.getCurrentContext(), "call", servlet_env);
return (RackResponse) response.toJava(RackResponse.class);
//}
//catch (RuntimeException e) {
// throw ExceptionUtils.wrapException(runtime, e);
//}
return response.toJava(RackResponse.class);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.jruby.rack.util.IOHelpers;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.util.cli.OutputStrings;

import static org.jruby.rack.RackLogger.Level.*;
import static org.jruby.rack.DefaultRackConfig.isIgnoreRUBYOPT;
Expand Down Expand Up @@ -85,7 +86,7 @@ public void init(final RackContext rackContext) {
this.rackContext = (ServletRackContext) rackContext;
if ( getRackupScript() == null ) resolveRackupScript();
this.runtimeConfig = createRuntimeConfig();
rackContext.log(INFO, runtimeConfig.getVersionString());
rackContext.log(INFO, OutputStrings.getVersionString());
configureDefaults();
}

Expand Down Expand Up @@ -199,7 +200,7 @@ public IRubyObject createErrorApplicationObject(final Ruby runtime) {

public RackApplication newErrorApplication() {
Boolean error = rackContext.getConfig().getBooleanProperty("jruby.rack.error");
if ( error != null && ! error.booleanValue() ) { // jruby.rack.error = false
if ( error != null && !error) { // jruby.rack.error = false
return new DefaultErrorApplication(rackContext);
}
try {
Expand Down Expand Up @@ -557,7 +558,7 @@ private void configureDefaults() {
if (iniSize == null) iniSize = RewindableInputStream.INI_BUFFER_SIZE;
Integer maxSize = config.getMaximumMemoryBufferSize();
if (maxSize == null) maxSize = RewindableInputStream.MAX_BUFFER_SIZE;
if (iniSize.intValue() > maxSize.intValue()) iniSize = maxSize;
if (iniSize > maxSize) iniSize = maxSize;

RewindableInputStream.setDefaultInitialBufferSize(iniSize);
RewindableInputStream.setDefaultMaximumBufferSize(maxSize);
Expand Down
24 changes: 10 additions & 14 deletions src/main/java/org/jruby/rack/DefaultRackConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public boolean isSerialInitialization() {
}
}
}
return serial.booleanValue();
return serial;
}

@Override
Expand Down Expand Up @@ -156,10 +156,7 @@ protected RackLogger createLogger(final String loggerClass) {
Constructor<?> ctor = klass.getConstructor(String.class);
return (RackLogger) ctor.newInstance( getLoggerName() );
}
catch (NoSuchMethodException retry) {
return newLoggerInstance(klass, retry);
}
catch (IllegalAccessException retry) {
catch (NoSuchMethodException | IllegalAccessException retry) {
return newLoggerInstance(klass, retry);
}
catch (InstantiationException e) {
Expand Down Expand Up @@ -268,7 +265,7 @@ static boolean isIgnoreRUBYOPT(RackConfig config) {
// RUBYOPT ignored if jruby.runtime.env.rubyopt = false
Boolean rubyopt = config.getBooleanProperty("jruby.runtime.env.rubyopt");
if ( rubyopt == null ) return ! config.isIgnoreEnvironment();
return rubyopt != null && ! rubyopt.booleanValue();
return rubyopt != null && !rubyopt;
}

@Override
Expand All @@ -282,11 +279,11 @@ public boolean isThrowInitException() {

static boolean isThrowInitException(RackConfig config) {
Boolean error = config.getBooleanProperty("jruby.rack.error");
if ( error != null && error.booleanValue() ) {
if ( error != null && error) {
return false; // jruby.rack.error = true
}
error = config.getBooleanProperty(RackEnvironment.EXCEPTION);
if ( error != null && error.booleanValue() ) {
if ( error != null && error) {
return false; // jruby.rack.exception = true
}
return true;
Expand Down Expand Up @@ -335,7 +332,7 @@ private Integer getPositiveInteger(String key) {
if (value == null) return null;
try {
int i = Integer.parseInt(value);
if (i > 0) return Integer.valueOf(i);
if (i > 0) return i;
} catch (Exception e) { /* ignored */ }
return null;
}
Expand Down Expand Up @@ -367,12 +364,12 @@ public static Number toNumber(String value, Number defaultValue) {
}
if ( number == ((int) number) )
if ( number > Integer.MAX_VALUE ) {
return Long.valueOf((long) number);
return (long) number;
}
else {
return Integer.valueOf((int) number);
return (int) number;
}
return Float.valueOf(number);
return number;
}
catch (Exception e) { /* ignored */ }
return defaultValue;
Expand All @@ -386,7 +383,7 @@ private Map<String, String> toStringMap(final String env) {
GEM_HOME=/opt/local/rvm/gems/jruby-1.6.8@jruby-rack
*/
LineNumberReader reader = new LineNumberReader(new StringReader(env.trim()));
Map<String, String> map = new LinkedHashMap<String, String>(); String line;
Map<String, String> map = new LinkedHashMap<>(); String line;
try {
while ( (line = reader.readLine()) != null ) {
final String[] entries = line.split(",");
Expand Down Expand Up @@ -419,7 +416,6 @@ private static Map<String,String> getLoggerTypes() {
loggerTypes.put("clogging", "org.jruby.rack.logging.CommonsLoggingLogger");
loggerTypes.put("slf4j", "org.jruby.rack.logging.Slf4jLogger");
loggerTypes.put("jul", "org.jruby.rack.logging.JulLogger");
//loggerTypes.put("servlet_context", "org.jruby.rack.logging.ServletContextLogger");
return loggerTypes;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jruby/rack/DefaultRackDispatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ protected void afterException(
// TODO seems redundant maybe we should let the container decide ?!
context.log(ERROR, "error app failed to handle exception: " + e, re);
Integer errorCode = getErrorApplicationFailureStatusCode();
if ( errorCode != null && errorCode.intValue() > 0 ) {
if ( errorCode != null && errorCode > 0 ) {
response.sendError(errorCode);
}
else {
Expand Down
35 changes: 15 additions & 20 deletions src/main/java/org/jruby/rack/PoolingRackApplicationFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public class PoolingRackApplicationFactory extends RackApplicationFactoryDecorat
// 10 seconds seems still too much for a default, has been 30 previously :
private static final float ACQUIRE_DEFAULT = 10.0f;

protected final Queue<RackApplication> applicationPool = new LinkedList<RackApplication>();
protected final Queue<RackApplication> applicationPool = new LinkedList<>();
private Integer initialSize, maximumSize;

private final AtomicInteger initedApplications = new AtomicInteger(0);
Expand Down Expand Up @@ -111,7 +111,7 @@ public void setAcquireTimeout(Number acquireTimeout) {

@Override
protected void doInit() throws Exception {
super.doInit(); // delegate.init(rackContext);
super.doInit();
final RackConfig config = getConfig();
// TODO until config.getRuntimeTimeoutSeconds returns an integer :
Number timeout = config.getNumberProperty("jruby.runtime.acquire.timeout");
Expand Down Expand Up @@ -253,16 +253,15 @@ public void destroy() {
synchronized (applicationPool) {
for (RackApplication app : applicationPool) {
getDelegate().finishedWithApplication(app);
// DefaultRackAppFactory: app.destroy();
}
applicationPool.clear();
}
super.destroy(); // delegate.destroy();
super.destroy();
}

/**
* Fills the initial pool with initialized application instances.
*
* <p>
* Application objects are created in foreground threads to avoid
* leakage when the web application is undeployed from the server.
*/
Expand Down Expand Up @@ -294,19 +293,15 @@ protected void launchInitialization(final Queue<RackApplication> apps) {
if ( initThreads == null ) initThreads = 4; // quad-core baby

for (int i = 0; i < initThreads; i++) {
new Thread(new Runnable() {
@Override
public void run() {
while (true) {
final RackApplication app;
synchronized (apps) {
if ( apps.isEmpty() ) break;
app = apps.remove();
}
if ( ! initAndPutApplicationToPool(app) ) break;
new Thread(() -> {
while (true) {
final RackApplication app;
synchronized (apps) {
if ( apps.isEmpty() ) break;
app = apps.remove();
}
if ( ! initAndPutApplicationToPool(app) ) break;
}

}, "JRuby-Rack-App-Init-" + i).start();
}
}
Expand Down Expand Up @@ -395,14 +390,14 @@ private int getInitialPoolSizeWait() {
if ( waitNum != null ) {
int wait = waitNum.intValue();
if (maximumSize != null && wait > maximumSize) {
wait = maximumSize.intValue();
wait = maximumSize;
}
return wait;
}
// otherwise we assume it to be a boolean true/false flag :
Boolean waitFlag = getConfig().getBooleanProperty("jruby.runtime.init.wait");
if ( waitFlag == null ) waitFlag = Boolean.TRUE;
return waitFlag ? ( initialSize == null ? 1 : initialSize.intValue() ) : 0;
return waitFlag ? ( initialSize == null ? 1 : initialSize) : 0;
// NOTE: this slightly changes the behavior in 1.1.8, in previous
// versions the initialization only waited for 1 application instance
// to be available in the pool - here by default we wait till initial
Expand All @@ -411,14 +406,14 @@ private int getInitialPoolSizeWait() {

@Override
public Collection<RackApplication> getManagedApplications() {
int initSize = initialSize != null ? initialSize.intValue() : -1;
int initSize = initialSize != null ? initialSize : -1;
synchronized (applicationPool) {
if ( applicationPool.isEmpty() ) {
if ( initSize > 0 ) return null; // ~ init error
return Collections.emptySet();
}
Collection<RackApplication> snapshot =
new ArrayList<RackApplication>(applicationPool);
new ArrayList<>(applicationPool);
return Collections.unmodifiableCollection(snapshot);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jruby/rack/RackApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public interface RackApplication {
* @param env the RackEnvironment
* @return the RackResponse
*/
public RackResponse call(RackEnvironment env);
RackResponse call(RackEnvironment env);

/**
* Get a reference to the underlying runtime that holds the application
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jruby/rack/RackApplicationFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public interface RackApplicationFactory {
*
* @author kares
*/
public static interface Decorator {
interface Decorator {

/**
* @return the delegate factory this decorator wraps
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ private RackContext getContextBang() throws IllegalStateException {
public static Collection<Ruby> getManagedRuntimes(RackApplicationFactoryDecorator factory) {
final Collection<RackApplication> apps = factory.getManagedApplications();
if ( apps == null ) return null;
final Set<Ruby> runtimes = new LinkedHashSet<Ruby>(apps.size());
final Set<Ruby> runtimes = new LinkedHashSet<>(apps.size());
for ( RackApplication app : apps ) {
runtimes.add( app.getRuntime() );
}
Expand Down
7 changes: 1 addition & 6 deletions src/main/java/org/jruby/rack/RackConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,7 @@ public interface RackConfig {
* @return the maximum size of the in-memory buffer
*/
Integer getMaximumMemoryBufferSize();

/**
* @return whether we allow the initialization exception to bubble up
*/
//boolean isThrowInitException();


/**
* Create a logger to be used (based on this configuration).
* @return a logger instance
Expand Down
Loading