Borrowing a Jruby runtime in a Rails application from Java

We have an application that is partly written in Java and partly in
Rails. On the Java side we’re using the Quartz Scheduler.

When a job runs, is there a way to borrow an instantiated Ruby runtime
from the RackApplicationFactory? From a Rails controller I can do
something like this:

factory =
request.env[‘java.servlet_context’].get_attribute(‘rack.factory’)
app = factory.wait_for_next_available(10000)

where factory is a DefaultRackApplicationFactory and app appears to be a
DefaultRackApplication instance. But there doesn’t seem to be any way
to get at the contained Ruby instance to execute a Ruby script. We’d
like to be able use ActiveRecord on the Rails side to do some work.

Any suggestions?

This email communication and any files transmitted with it may contain
confidential and or proprietary information and is provided for the use
of the intended recipient only. Any review, retransmission or
dissemination of this information by anyone other than the intended
recipient is prohibited. If you receive this email in error, please
contact the sender and delete this communication and any copies
immediately. Thank you.


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Hi,

I had the same problem. I ‘fixed’ this by patching the Rack source like
this.

Index: src/main/java/org/jruby/rack/DefaultRackApplication.java

— src/main/java/org/jruby/rack/DefaultRackApplication.java
(revision 183)
+++ src/main/java/org/jruby/rack/DefaultRackApplication.java (working
copy)
@@ -54,6 +54,10 @@
public void setApplication(IRubyObject application) {
this.application = application;
}
+

  • public Ruby getRuntime() {

  •    return application.getRuntime();
    
  • }

    /** Only used for testing. */
    public IRubyObject __call(final IRubyObject env) {

Than you can call app.getRuntime and call evalScriptlet(command) on the
runtime to execute a command.

Hope this helps, maybe this patche can be used in the real Rack
application to allow RailsQuartz (with a bit of patching) to work again?

Regards

Hi Darcy,

Seems like this is an enhancement that needs to be made to the
RackApplication interface, to allow the runtime object to be exposed
for uses other than calling through the application request cycle.

A possible workaround would be to set up some special-use controllers
in your application and call into those from the RackApplication when
you need to trigger some background work.

Cheers,
/Nick

On Wed, Aug 13, 2008 at 2:56 PM, Schultz, Darcy L.
[email protected] wrote:


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

On Thu, Aug 14, 2008 at 2:29 AM, Andres K. [email protected]
wrote:

copy)
public IRubyObject __call(final IRubyObject env) {

Than you can call app.getRuntime and call evalScriptlet(command) on the
runtime to execute a command.

Hope this helps, maybe this patche can be used in the real Rack application
to allow RailsQuartz (with a bit of patching) to work again?

Sounds good, I’ve added this method in trunk.

Cheers,
/Nick


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email