[Eventmachine-talk] jruby support?

3 views
Skip to first unread message

Chuck Remes

unread,
Jun 17, 2008, 3:41:54 PM6/17/08
to eventmac...@rubyforge.org
I remember seeing some talk (and code) here regarding a java version
of EM. Does anyone have firsthand knowledge of its status?

If not, I'll give it a try and report back here.

cr

_______________________________________________
Eventmachine-talk mailing list
Eventmac...@rubyforge.org
http://rubyforge.org/mailman/listinfo/eventmachine-talk

Jesse Farmer

unread,
Jun 17, 2008, 4:05:44 PM6/17/08
to eventmac...@rubyforge.org
Is this what you were thinking of?

http://rubyeventmachine.com/browser/trunk/java

--
Jesse E.I. Farmer
e: je...@20bits.com
w: http://20bits.com

James Tucker

unread,
Jun 17, 2008, 6:00:33 PM6/17/08
to eventmac...@rubyforge.org
If you checkout a copy of my branch:

http://rubyeventmachine.com/svn/branches/raggi

You can run jruby -S rake install and you will get a working jruby
reactor installed as a gem.

There are a few things left to be done, including next_tick and
get_peername, but I am told it's mostly just the jeventmachine.rb
wrapper that needs completion, a few pieces I have looked at already.

Charles Oliver Nutter

unread,
Jun 17, 2008, 6:41:34 PM6/17/08
to eventmac...@rubyforge.org
James Tucker wrote:
> If you checkout a copy of my branch:
>
> http://rubyeventmachine.com/svn/branches/raggi
>
> You can run jruby -S rake install and you will get a working jruby
> reactor installed as a gem.
>
> There are a few things left to be done, including next_tick and
> get_peername, but I am told it's mostly just the jeventmachine.rb
> wrapper that needs completion, a few pieces I have looked at already.

Anything I can do to help get it out there?

- Charlie

James Tucker

unread,
Jun 17, 2008, 8:42:15 PM6/17/08
to eventmac...@rubyforge.org

On 17 Jun 2008, at 23:41, Charles Oliver Nutter wrote:

> James Tucker wrote:
>> If you checkout a copy of my branch:
>> http://rubyeventmachine.com/svn/branches/raggi
>> You can run jruby -S rake install and you will get a working jruby
>> reactor installed as a gem.
>> There are a few things left to be done, including next_tick and
>> get_peername, but I am told it's mostly just the jeventmachine.rb
>> wrapper that needs completion, a few pieces I have looked at already.
>
> Anything I can do to help get it out there?

I had a look around the internal api to getting next_tick implemented,
but got lost somewhere in the C++ and had to put it down for a while.
I'm hoping to get it done when I can, but in the meantime, if you
would like to take a stab at it, you can run jruby -S rake
test:partial after building the java reactor, and you should get the
test output showing the missing parts of the reactor. Francis has also
said he will do this as he gets time to / if I can't, so it's really a
time thing unless someone can post up patches to assist.

Some eventmachine apps will just work already, however quite a few of
the popular EM projects use get_peername and/or next_tick.

Chuck Remes

unread,
Jun 19, 2008, 5:37:05 PM6/19/08
to eventmac...@rubyforge.org

On Jun 17, 2008, at 5:00 PM, James Tucker wrote:

> If you checkout a copy of my branch:
>
> http://rubyeventmachine.com/svn/branches/raggi
>
> You can run jruby -S rake install and you will get a working jruby
> reactor installed as a gem.
>
> There are a few things left to be done, including next_tick and
> get_peername, but I am told it's mostly just the jeventmachine.rb
> wrapper that needs completion, a few pieces I have looked at already.
>
> On 17 Jun 2008, at 20:41, Chuck Remes wrote:
>
>> I remember seeing some talk (and code) here regarding a java
>> version of EM. Does anyone have firsthand knowledge of its status?
>>
>> If not, I'll give it a try and report back here.
>>

[Sorry for the late response. My upstream provider ended up on a
blacklist; it didn't get lifted until today.]

Re: jruby support?

This is a reply to both James and Jesse.

The java code in the tree is still marked as experimental. I'll give
it a try though. I will also look at James Tucker's fork.

I've been playing with the latest EM release. The pure ruby version
has a bug in it which is a show-stopper. I have a small patch to fix
it. I compared the ruby code to the C++ code so I know my fix is legit.

Also, it's internal check for jruby is wrong. It doesn't respect
the :pure_ruby directive in the case of java, so I fixed the require
blocks so that it does. I'll attach the patch that fixes both issues
to the end of this post.

I can't get the :pure_ruby version to run under jruby even with the
fix though. I suspect it is a jruby problem though, so I'll open a
ticket with them. (It complains about the number of args to
Socket.for_fd, incidentally.)

cr


--- /Library/Ruby/Gems/1.8/gems/eventmachine-0.12.0/lib/
eventmachine.rb 2008-06-17 15:03:21.000000000 -0500
+++ ./eventmachine.rb 2008-06-17 15:33:14.000000000 -0500
@@ -52,7 +52,12 @@
# This is the case that most user code will take.
# Prefer the extension if available.
begin
- require 'rubyeventmachine'
+ if RUBY_PLATFORM =~ /java/
+ require 'java'
+ require 'jeventmachine'
+ else
+ require 'rubyeventmachine'
+ end
rescue LoadError
require 'pr_eventmachine'
end
@@ -60,15 +65,10 @@
=end


-if RUBY_PLATFORM =~ /java/
- require 'java'
- require 'jeventmachine'
+if $eventmachine_library == :pure_ruby or ENV['EVENTMACHINE_LIBRARY']
== "pure_ruby"
+ require 'pr_eventmachine'
else
- if $eventmachine_library == :pure_ruby or
ENV['EVENTMACHINE_LIBRARY'] == "pure_ruby"
- require 'pr_eventmachine'
- else
- require 'rubyeventmachine'
- end
+ require 'rubyeventmachine'
end


@@ -1250,6 +1250,11 @@
def initialize(*args) #:nodoc:
end

+ # Not Yet Implemented
+ def associate_callback_target sig
+ nil
+ end
+
# EventMachine::Connection#post_init is called by the event loop
# immediately after the network connection has been established,
# and before resumption of the network loop.

hemant

unread,
Jun 19, 2008, 11:57:47 PM6/19/08
to eventmac...@rubyforge.org

Just because its pure ruby, it doesn't mean that it will run under
JRuby without modifications. Last I checked, JRuby had somewhat
different socket API.

Chuck Remes

unread,
Jun 20, 2008, 7:26:16 AM6/20/08
to eventmac...@rubyforge.org

I had the exact opposite thought. If JRuby is 1.8.6 compatible and can
act as a drop-in replacement for MRI, then it should "just work." It
sure would be hard to bill itself as a MRI replacement if it provided
incompatible APIs for major classes in stdlib.

Anyway, I'll chase this down with the jruby guys. I have a use case
for running analogger (EM-based) under jruby.

cr

Charles Oliver Nutter

unread,
Jun 20, 2008, 8:17:40 AM6/20/08
to eventmac...@rubyforge.org
hemant wrote:
> Just because its pure ruby, it doesn't mean that it will run under
> JRuby without modifications. Last I checked, JRuby had somewhat
> different socket API.

Our API should be mostly the same, where we're able to support
appropriate features. Some things like low-level socket manipulation
don't work because we haven't wired them in with native calls and the
JVM doesn't have APIs that directly support those features. But in
general, our APIs should match Ruby's APIs, and if they don't it's a bug.

- Charlie

James Tucker

unread,
Jun 20, 2008, 10:56:31 AM6/20/08
to eventmac...@rubyforge.org

On 19 Jun 2008, at 22:37, Chuck Remes wrote:
>
> Also, it's internal check for jruby is wrong. It doesn't respect
> the :pure_ruby directive in the case of java, so I fixed the require
> blocks so that it does. I'll attach the patch that fixes both issues
> to the end of this post.

Thanks for those :)

> I can't get the :pure_ruby version to run under jruby even with the
> fix though. I suspect it is a jruby problem though, so I'll open a
> ticket with them. (It complains about the number of args to
> Socket.for_fd, incidentally.)

Cool, thanks, I'll keep an eye out. Feel free to assign the ticket to
me (raggi) if that is convenient, and I will try to have a look at
this later on. Should be an easy enough fix.

Chuck Remes

unread,
Jun 20, 2008, 12:25:04 PM6/20/08
to eventmac...@rubyforge.org

On Jun 20, 2008, at 9:56 AM, James Tucker wrote:

>
> On 19 Jun 2008, at 22:37, Chuck Remes wrote:
>>
>> Also, it's internal check for jruby is wrong. It doesn't respect
>> the :pure_ruby directive in the case of java, so I fixed the
>> require blocks so that it does. I'll attach the patch that fixes
>> both issues to the end of this post.
>
> Thanks for those :)
>
>> I can't get the :pure_ruby version to run under jruby even with the
>> fix though. I suspect it is a jruby problem though, so I'll open a
>> ticket with them. (It complains about the number of args to
>> Socket.for_fd, incidentally.)
>
> Cool, thanks, I'll keep an eye out. Feel free to assign the ticket
> to me (raggi) if that is convenient, and I will try to have a look
> at this later on. Should be an easy enough fix.

Recorded as JRUBY-2687. I don't have permission to assign bugs in the
JRUBY bugtracker (unless you meant for me to add this to EM's TRAC).

BTW, rubinius fails to run the pure ruby version due to a missing
method #bind on Socket. I'll open a ticket over there too.

cr

James Tucker

unread,
Jun 20, 2008, 12:31:43 PM6/20/08
to eventmac...@rubyforge.org

On 20 Jun 2008, at 17:25, Chuck Remes wrote:

>
> On Jun 20, 2008, at 9:56 AM, James Tucker wrote:
>
>>
>> On 19 Jun 2008, at 22:37, Chuck Remes wrote:
>>>
>>> Also, it's internal check for jruby is wrong. It doesn't respect
>>> the :pure_ruby directive in the case of java, so I fixed the
>>> require blocks so that it does. I'll attach the patch that fixes
>>> both issues to the end of this post.
>>
>> Thanks for those :)
>>
>>> I can't get the :pure_ruby version to run under jruby even with
>>> the fix though. I suspect it is a jruby problem though, so I'll
>>> open a ticket with them. (It complains about the number of args to
>>> Socket.for_fd, incidentally.)
>>
>> Cool, thanks, I'll keep an eye out. Feel free to assign the ticket
>> to me (raggi) if that is convenient, and I will try to have a look
>> at this later on. Should be an easy enough fix.
>
> Recorded as JRUBY-2687. I don't have permission to assign bugs in
> the JRUBY bugtracker (unless you meant for me to add this to EM's
> TRAC).

Er, yes I meant anything for the EM trac.

> BTW, rubinius fails to run the pure ruby version due to a missing
> method #bind on Socket. I'll open a ticket over there too.

Hey, thanks, I have a copy of shotgun installed, but haven't done much
with it yet. I'll add a rakefile target if appropriate.

Chuck Remes

unread,
Jun 20, 2008, 12:48:05 PM6/20/08
to eventmac...@rubyforge.org

On Jun 20, 2008, at 11:31 AM, James Tucker wrote:

>
> On 20 Jun 2008, at 17:25, Chuck Remes wrote:
>
>>
>> Recorded as JRUBY-2687. I don't have permission to assign bugs in
>> the JRUBY bugtracker (unless you meant for me to add this to EM's
>> TRAC).
>
> Er, yes I meant anything for the EM trac.
>
>> BTW, rubinius fails to run the pure ruby version due to a missing
>> method #bind on Socket. I'll open a ticket over there too.
>
> Hey, thanks, I have a copy of shotgun installed, but haven't done
> much with it yet. I'll add a rakefile target if appropriate.

Ticket #29, assigned to raggi.

hemant

unread,
Jun 20, 2008, 2:32:41 PM6/20/08
to eventmac...@rubyforge.org
On Fri, Jun 20, 2008 at 5:47 PM, Charles Oliver Nutter
<charles...@sun.com> wrote:
> hemant wrote:
>>
>> Just because its pure ruby, it doesn't mean that it will run under
>> JRuby without modifications. Last I checked, JRuby had somewhat
>> different socket API.
>
> Our API should be mostly the same, where we're able to support appropriate
> features. Some things like low-level socket manipulation don't work because
> we haven't wired them in with native calls and the JVM doesn't have APIs
> that directly support those features. But in general, our APIs should match
> Ruby's APIs, and if they don't it's a bug.
>

My bad, thanks for clearing this up. May be its time for me to rev up,
Packet for JRuby.

Chuck Remes

unread,
Jun 25, 2008, 12:31:38 PM6/25/08
to eventmac...@rubyforge.org

On Jun 17, 2008, at 5:00 PM, James Tucker wrote:

> http://rubyeventmachine.com/svn/branches/raggi

Any chance you could kick the machine? I keep timing out when trying
to access this branch.

Chuck Remes

unread,
Jun 30, 2008, 5:57:18 PM6/30/08
to eventmac...@rubyforge.org

On Jun 25, 2008, at 11:31 AM, Chuck Remes wrote:

>
> On Jun 17, 2008, at 5:00 PM, James Tucker wrote:
>
>> http://rubyeventmachine.com/svn/branches/raggi
>
> Any chance you could kick the machine? I keep timing out when trying
> to access this branch.
>

I was able to checkout this branch today and it's looking good! In an
earlier reply in this thread, James said I could get a gem with the
jar included if I ran:

jruby -S rake install

I did that from within the branch, but it did not build and install
the jar. So I tried 'jruby -S rake java:build' and tried the install
again. Still no dice.

So I manually copied the jar into the correct directory. My
application worked fine though it was a limited test.

Also, I did get a fatal error as it was exiting. The stacktrace shows
the error was from within the "main" gem which I use for quickly
building command-line scripts that wrap around EM. Here's a link to
the stacktrace along with the error.

http://pastie.org/225091

Here is the method in Main that is raising that exception:

def setup_io_restoration
[STDIN, STDOUT, STDERR].each do |io|
dup = io.dup and @finalizers.push lambda{ io.reopen dup }
end
end

James Tucker

unread,
Jul 1, 2008, 9:42:45 AM7/1/08
to eventmac...@rubyforge.org

On 30 Jun 2008, at 22:57, Chuck Remes wrote:
> James said I could get a gem with the jar included if I ran:
>
> jruby -S rake install

Sorry for the confusion. The rake and gem builds on my branch actually
generate a 'common' gem, which contains no precompiled parts, but on
jruby it will build the .jar using rake during the gem installation.
By default it will build the C++ (i.e. on unknown interpreters), and
if you set $EVENTMACHINE_LIBRARY you can force it other ways, such as
pure ruby.

jruby -S rake java:build should construct a jar.

jruby -S rake install will build the gem (if required) and then
install using your current interpreter and rubygems. The gem
installation itself is responsible for compiling any extension at
install time, as above.

> So I manually copied the jar into the correct directory. My
> application worked fine though it was a limited test.

This is good news! :)

> Also, I did get a fatal error as it was exiting. The stacktrace
> shows the error was from within the "main" gem which I use for
> quickly building command-line scripts that wrap around EM. Here's a
> link to the stacktrace along with the error.
>
> http://pastie.org/225091

I'm not sure this is directly related, however let me know what turns
up on the JRuby side with Main.

Reply all
Reply to author
Forward
0 new messages