Created
January 16, 2011 14:38
-
-
Save calavera/781834 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From a7b32e77cd16772bb20df95813c674ac2de3d30c Mon Sep 17 00:00:00 2001 | |
From: David Calavera <[email protected]> | |
Date: Sun, 16 Jan 2011 15:39:07 +0100 | |
Subject: [PATCH] allow to use an existent JRuby runtime | |
--- | |
.../jruby/rack/DefaultRackApplicationFactory.java | 7 +++++-- | |
src/main/java/org/jruby/rack/RackContext.java | 1 + | |
2 files changed, 6 insertions(+), 2 deletions(-) | |
diff --git a/src/main/java/org/jruby/rack/DefaultRackApplicationFactory.java b/src/main/java/org/jruby/rack/DefaultRackApplicationFactory.java | |
index 9230509..345fb9d 100644 | |
--- a/src/main/java/org/jruby/rack/DefaultRackApplicationFactory.java | |
+++ b/src/main/java/org/jruby/rack/DefaultRackApplicationFactory.java | |
@@ -77,8 +77,11 @@ public class DefaultRackApplicationFactory implements RackApplicationFactory { | |
public Ruby newRuntime() throws RackInitializationException { | |
try { | |
- setupJRubyManagement(); | |
- Ruby runtime = JavaEmbedUtils.initialize(new ArrayList(), createRuntimeConfig()); | |
+ Ruby runtime = (Ruby) rackContext.getAttribute("jruby.runtime"); | |
+ if (runtime == null) { | |
+ setupJRubyManagement(); | |
+ runtime = JavaEmbedUtils.initialize(new ArrayList(), createRuntimeConfig()); | |
+ } | |
runtime.getGlobalVariables().set("$servlet_context", | |
JavaEmbedUtils.javaToRuby(runtime, rackContext)); | |
runtime.evalScriptlet("require 'rack/handler/servlet'"); | |
diff --git a/src/main/java/org/jruby/rack/RackContext.java b/src/main/java/org/jruby/rack/RackContext.java | |
index cb0015c..377bf7e 100644 | |
--- a/src/main/java/org/jruby/rack/RackContext.java | |
+++ b/src/main/java/org/jruby/rack/RackContext.java | |
@@ -24,4 +24,5 @@ public interface RackContext extends RackLogger { | |
Set getResourcePaths(String path); | |
URL getResource(String path) throws MalformedURLException; | |
InputStream getResourceAsStream(String path); | |
+ Object getAttribute(String name); | |
} | |
-- | |
1.7.2.3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment