Using the a runtime from multiple servlets

If I’ve got a the jruby rack filter running and I want to another
servlet to grab access to the shared runtime and run some things, what’s
the best way to go about that?

Currently I’m doing:

RackApplicationFactory raf = (RackApplicationFactory)
servletContext.getAttribute(RackServletContextListener.FACTORY_KEY);
RackApplication app = raf.getApplication();
RubyRuntimeAdapter evaler = JavaEmbedUtils.newRuntimeAdapter();
evaler.eval(app.getRuntime(), code);

Which works fine, but it doesn’t line up at all with the Redbridge way
of doing things - I’m guessing that this is just because jruby-rack was
written before Redbridge was finalized? Or am I better off using these
low level methods without having a ScriptingContainer wrapping
everything?

If jruby-rack was written from scratch today, would it still use
JavaEmbedUtils directly to get a runtime object, or would the newRuntime
method in the application factory actually be a newScriptingContext
method? (and that a singleton localcontext would be appropriate?)

I’m asking because I’m playing around with mirah and dubious for an
appengine project and looking at having some parts written in ruby, but
I don’t need to be loading rack or a rack framework - so my end goal
will be dumping jruby-rack and only loading a ruby runtime if/when
needed (and then, only requiring the bare minimum of libraries).

On Wed, Jan 12, 2011 at 9:15 PM, Daniel S. [email protected]
wrote:

RackApplication app = raf.getApplication();
methods without having a ScriptingContainer wrapping everything?

If jruby-rack was written from scratch today, would it still use
JavaEmbedUtils directly to get a runtime object, or would the newRuntime
method in the application factory actually be a newScriptingContext method?
(and that a singleton localcontext would be appropriate?)

You’ve got it right – it was started before RedBridge. I haven’t
bothered to go back and re-write it using RedBridge, though it would
probably be a good idea. There are a few parts of JRuby-Rack that use
internal classes, and I’m not sure how those would change yet.

Im asking because Im playing around with mirah and dubious for an
appengine project and looking at having some parts written in ruby, but I
dont need to be loading rack or a rack framework so my end goal will be
dumping jruby-rack and only loading a ruby runtime if/when needed (and then,
only requiring the bare minimum of libraries).

I would definitely suggest using only RedBridge for your project, if
you don’t need Rack. It shouldn’t be too hard to make a new
ServletFilter that manages a runtime for you with RedBridge.

/Nick