Forum: JRuby Java and JRuby tight integration

63b8801f91dec6eb7ff8c3d2e969e03c?d=identicon&s=25 Chris Burrell (Guest)
on 2012-05-18 00:10
(Received via mailing list)
Hi

I have a requirement for integrating one of our existing applications
written in Ruby with another Java application. They need to appear
seamless
and thereby share the same information (e.g. session).  At this stage,
most
of the information is available through a UI powered by Ruby.

My migration idea is to migrate Ruby to JRuby and then integrate this
with
the Java app.

Is migrating a Ruby application to JRuby a fairly trivial task?
How easy is it for Java to be able to access the JRuby session
information
and vice-versa? I assume Ruby/JRuby doesn't encode the session
information
in a way that a Java app can't read it straightforwardly? (e.g. doesn't
do
what .NET does with the viewstate field)

Are there any gotchas/pitfalls that you would look out for?

Would it be possible to have an approach of dual running both in the
same
Java container, and then gradually rewriting one of the applications:
e.g. eliminating the Java code or the Ruby code in favour of the other.
Does one way cause more issues than the other?

I'm more of a Java guy myself, so any information JRuby would be
welcome.

Chris
1273e5c266e0c4cc4065fff3a6fe7056?d=identicon&s=25 Anthony Juckel (Guest)
on 2012-05-18 03:31
(Received via mailing list)
On Thu, May 17, 2012 at 5:08 PM, Chris Burrell <chris@burrell.me.uk>
wrote:
> Is migrating a Ruby application to JRuby a fairly trivial task?

For the most part, yes, aside from a few gotchas (more below).

You could look at this project as an example of blending Java and
Rails. https://github.com/nicksieger/refactoring-to-rails, and the
associated talk at
http://www.confreaks.com/videos/572-scotlandruby20....

> How easy is it for Java to be able to access the JRuby session information
> and vice-versa? I assume Ruby/JRuby doesn't encode the session information
> in a way that a Java app can't read it straightforwardly? (e.g. doesn't do
> what .NET does with the viewstate field)

There's no viewstate in Rails, and (though I haven't tried it myself)
I believe that jruby-rack (which you would be the glue between your
servlet environment and the Rails environment) I believe it includes a
backing store so that rails data is stored in the normal servlet
session.  Now, accessing that data from Java may be slightly
cumbersome, since you'll have to cast them to the appropriate
IRubyObject.  But, accessing Java objects stored in the session from
Ruby would be considerably more convenient.

> Are there any gotchas/pitfalls that you would look out for?

There are a few gotchas, but you could give jrlint
(https://github.com/jruby/jruby-lint) a pass at your current
application.  It should warn you of some common cases.

> Would it be possible to have an approach of dual running both in the same
> Java container, and then gradually rewriting one of the applications:
> e.g. eliminating the Java code or the Ruby code in favour of the other. Does
> one way cause more issues than the other?

The refactoring-to-rails app shows exactly this.  Taking an existing
Java app (the Pet Clinic sample spring app) and gradually migrating it
to Ruby/Rails.

Good luck!
666badca71c452ae51c999971419b506?d=identicon&s=25 Joe Kutner (Guest)
on 2012-05-18 05:23
(Received via mailing list)
On May 17, 2012, at 5:08 PM, Chris Burrell wrote:

> Is migrating a Ruby application to JRuby a fairly trivial task?


I did a short screencast showing how to do this for an existing Rails
app:
http://youtu.be/C2gCi5DS_I8

I use Trinidad in that example, but you'll probably want to use
Warbler+Tomcat/Jetty/etc if you're already running with an existing Java
servlet container (although, you can deploy a WAR to Trinidad).
D4c223beb610f1e5baa56a0b764e24a9?d=identicon&s=25 Marko Asplund (Guest)
on 2012-05-18 07:35
(Received via mailing list)
On Fri, May 18, 2012 at 1:08 AM, Chris Burrell <chris@burrell.me.uk>
wrote:

> and vice-versa? I assume Ruby/JRuby doesn't encode the session information
> in a way that a Java app can't read it straightforwardly? (e.g. doesn't do
> what .NET does with the viewstate field)
>
> Are there any gotchas/pitfalls that you would look out for?
>

I've been experimenting with embedding JRuby in a Java application a bit
lately and one gotcha I ran into is that in some cases you may need to
implement your own data conversion code. First I tried passing data from
Java code to Ruby code that's invoked using JavaEmbedUtils.invokeMethod.
Initially I was using JavaEmbedUtils.javaToRuby for converting the
arguments but as things didn't work properly this way, I had to
implement a
custom "deep convert" method. I'd guess the same could happen also in
some
cases when calling Java code from Ruby.

marko
C31517bb2497ca20710a294d3f8d1144?d=identicon&s=25 Jonathan Coveney (Guest)
on 2012-05-21 23:33
(Received via mailing list)
I cannot speak to moving from Ruby to JRuby... I think the issue can be
gem
support, but it's getting better. I can talk about interop between
Java/JRuby, however. I embedded JRuby in Apache PIg so that users could
define UDF's (think of this like a user defined COUNT or SUM in the
database world) using JRuby. I found the tools to be more than adequate,
though the documentation is thin, and there are definitely some gotchas
(and you will undoubtedly have to make your own conversion functions).
Still, I think that the power of Ruby is worth it... a little pain on
the
internals is worth the expressivity of Ruby :)

2012/5/17 Marko Asplund <marko.asplund@ixonos.com>
63b8801f91dec6eb7ff8c3d2e969e03c?d=identicon&s=25 Chris Burrell (Guest)
on 2012-05-21 23:38
(Received via mailing list)
Thank you everyone for all your responses! And so complete. Much
appreciated. It gives me a very good starting point :)

Cheers
Chris
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.