Ruby Java Bridge: Are there any?

Discussion in 'Ruby' started by Richard Cole, Apr 13, 2005.

  1. Richard Cole

    Richard Cole Guest

    Hi. Quick question. I've install a database like thingy (kowari) written
    in Java that I want to communicate with from a Ruby: send queries get
    answers. What's a good way to communicate from a ruby process to Java
    process, SOAP? RMI? Corba? A socket? Are there any wrappers that let me
    go from ruby straight to the JVM presumably via the java native call
    interface? It's all on the same machine, I need only to communicate from
    ruby to the Java Client interface that comes with my database thingy
    (kowari). The data to be passed back and forth is all strings. The
    client interface is a Java Bean. Does that open up any possibilities?

    regards,

    Richard.
    Richard Cole, Apr 13, 2005
    #1
    1. Advertising

  2. On 4/13/05, Richard Cole <> wrote:
    > Hi. Quick question. I've install a database like thingy (kowari) written
    > in Java that I want to communicate with from a Ruby: send queries get
    > answers. What's a good way to communicate from a ruby process to Java
    > process, SOAP? RMI? Corba? A socket? Are there any wrappers that let me
    > go from ruby straight to the JVM presumably via the java native call
    > interface? It's all on the same machine, I need only to communicate from
    > ruby to the Java Client interface that comes with my database thingy
    > (kowari). The data to be passed back and forth is all strings. The
    > client interface is a Java Bean. Does that open up any possibilities?
    >


    Sockets would probably be easiest with strings. However if the jruby
    and cruby marshall formats are compatable you could use that across
    shared memory.


    > regards,
    >
    > Richard.
    >
    >



    --
    Into RFID? www.rfidnewsupdate.com Simple, fast, news.
    Lyndon Samson, Apr 13, 2005
    #2
    1. Advertising

  3. >A socket? Are there any wrappers that let me
    > go from ruby straight to the JVM presumably via the java native call
    > interface?


    It is possible to compile java bytecodes to native objects via gcj, and
    wrap that using Ruby's C interface (either manually, or via SWIG)
    Avik Sengupta, Apr 13, 2005
    #3
  4. Richard Cole

    David Corbin Guest

    On Wednesday 13 April 2005 12:32 am, Richard Cole wrote:
    > Hi. Quick question. I've install a database like thingy (kowari) written
    > in Java that I want to communicate with from a Ruby: send queries get
    > answers. What's a good way to communicate from a ruby process to Java
    > process, SOAP? RMI? Corba? A socket? Are there any wrappers that let me
    > go from ruby straight to the JVM presumably via the java native call
    > interface? It's all on the same machine, I need only to communicate from
    > ruby to the Java Client interface that comes with my database thingy
    > (kowari). The data to be passed back and forth is all strings. The
    > client interface is a Java Bean. Does that open up any possibilities?
    >
    > regards,
    >
    > Richard.


    Depending on the application, you might consider JRuby. (A ruby implementation
    in Java that allows direct calls to Java objects). There are, however,
    definately applications for which it is NOT the solution at this point in
    it's life.
    David Corbin, Apr 13, 2005
    #4
  5. Richard Cole wrote:
    > Hi. Quick question. I've install a database like thingy (kowari) written
    > in Java that I want to communicate with from a Ruby: send queries get
    > answers. What's a good way to communicate from a ruby process to Java
    > process, SOAP? RMI? Corba? A socket? Are there any wrappers that let me
    > go from ruby straight to the JVM presumably via the java native call
    > interface?


    Try rjb,
    http://arton.no-ip.info/data/rjb-0.1.9.zip
    http://arton.no-ip.info/collabo/backyard/?RubyJavaBridge
    --
    Takaaki Tateishi <>
    Takaaki Tateishi, Apr 13, 2005
    #5
  6. Richard Cole

    Luke Galea Guest

    Wow,
    RJB looks really nice!

    So: Trying to get a handle on use cases for JRuby versus RJB...
    JRuby is for embedding ruby in java applications, RJB is for embedding java in
    ruby applications? Or is there overlap between the two?

    On Wednesday 13 April 2005 12:48, Takaaki Tateishi wrote:
    > Richard Cole wrote:
    > > Hi. Quick question. I've install a database like thingy (kowari) written
    > > in Java that I want to communicate with from a Ruby: send queries get
    > > answers. What's a good way to communicate from a ruby process to Java
    > > process, SOAP? RMI? Corba? A socket? Are there any wrappers that let me
    > > go from ruby straight to the JVM presumably via the java native call
    > > interface?

    >
    > Try rjb,
    > http://arton.no-ip.info/data/rjb-0.1.9.zip
    > http://arton.no-ip.info/collabo/backyard/?RubyJavaBridge
    Luke Galea, Apr 13, 2005
    #6
  7. Richard Cole

    Richard Cole Guest

    Takaaki Tateishi wrote:

    > Richard Cole wrote:
    >
    >> Hi. Quick question. I've install a database like thingy (kowari)
    >> written in Java that I want to communicate with from a Ruby: send
    >> queries get answers. What's a good way to communicate from a ruby
    >> process to Java process, SOAP? RMI? Corba? A socket? Are there any
    >> wrappers that let me go from ruby straight to the JVM presumably via
    >> the java native call interface?

    >
    >
    > Try rjb,
    > http://arton.no-ip.info/data/rjb-0.1.9.zip
    > http://arton.no-ip.info/collabo/backyard/?RubyJavaBridge


    Wow, cool library. That was just what I was looking for :). Can you
    think of any reason why I'm getting a SIGHUP? Here's my short ruby
    program, maybe there's something obvious.

    ----
    require 'rjb'
    include Rjb

    def file_contents_of(filename)
    result = nil
    File.open(filename) { |file| return file.read() }
    return result
    end

    queryString = file_contents_of('example.itql')
    load("itql-1.1.0.jar")
    iTQLInterpreterBeanClass = import('org.kowari.itql.ItqlInterpreterBean')
    iTQL = iTQLInterpreterBeanClass.new
    answer = iTQL.executeQuery(queryString)

    vars = answer.getVariables
    while answer.next do
    for i in 1..vars.length do
    puts "i=#{i} val=#{answer.getObject(i-1).toString()}"
    end
    end
    ----

    Output is:

    [snip]
    i=1 val=gr:eek:rg.apache.bcel.classfile.Signature%24MyByteArrayInputStream
    i=1 val=gr:java.io.ByteArrayInputStream
    itql.rb:19: SIGHUP (SignalException)

    Each time I run the program the SIGHUP comes either on answer.next or
    answer.getObjects... and with a different amount of output.

    regards,

    Richard.
    Richard Cole, Apr 14, 2005
    #7
  8. Richard Cole

    vruz Guest

    > Hi. Quick question. I've install a database like thingy (kowari) written
    > in Java that I want to communicate with from a Ruby: send queries get
    > answers. What's a good way to communicate from a ruby process to Java
    > process, SOAP? RMI? Corba? A socket? Are there any wrappers that let me
    > go from ruby straight to the JVM presumably via the java native call
    > interface? It's all on the same machine, I need only to communicate from
    > ruby to the Java Client interface that comes with my database thingy
    > (kowari). The data to be passed back and forth is all strings. The
    > client interface is a Java Bean. Does that open up any possibilities?


    SOAP4R comes standard with Ruby 1.8.x
    (for a brief introduction have a look at: http://www.simplesiteuk.com)

    I haven't heard of any RMI lib freely available in native Ruby

    There's also RJNI: Java binding for Ruby through JNI
    http://thekode.net/ruby/rjni/index.html
    (though unsupported at the moment, would be interesting for someone to
    pick it up)

    You may consider JRuby can be a good option for some projects:
    http://jruby.sourceforge.net/

    There are some other JNI bindings available, can't recall the names
    now, someone will probably help adding to the list in this thread.

    cheers,
    vruz
    vruz, Apr 14, 2005
    #8
  9. Richard Cole

    Richard Cole Guest

    Richard Cole wrote:

    > Takaaki Tateishi wrote:
    >
    >> Richard Cole wrote:
    >>
    >>> Hi. Quick question. I've install a database like thingy (kowari)
    >>> written in Java that I want to communicate with from a Ruby: send
    >>> queries get answers. What's a good way to communicate from a ruby
    >>> process to Java process, SOAP? RMI? Corba? A socket? Are there any
    >>> wrappers that let me go from ruby straight to the JVM presumably via
    >>> the java native call interface?

    >>
    >>
    >>
    >> Try rjb,
    >> http://arton.no-ip.info/data/rjb-0.1.9.zip
    >> http://arton.no-ip.info/collabo/backyard/?RubyJavaBridge

    >
    >
    > Wow, cool library. That was just what I was looking for :). Can you
    > think of any reason why I'm getting a SIGHUP? Here's my short ruby
    > program, maybe there's something obvious.


    Don't know where SIGHUP is coming from, but putting a signal handler in
    at the top of the ruby script allowed me to ignore SIGHUP, i.e:

    trap('SIGHUP') {
    # puts "SIGHUP Raised!"
    }

    and now the program is producing the correct output, i.e. correctly
    iterating through the result set.

    regards,

    Richard.
    Richard Cole, Apr 14, 2005
    #9
  10. Richard Cole

    David Corbin Guest

    On Wednesday 13 April 2005 09:30 am, Luke Galea wrote:
    > Wow,
    > RJB looks really nice!
    >
    > So: Trying to get a handle on use cases for JRuby versus RJB...
    > JRuby is for embedding ruby in java applications, RJB is for embedding java
    > in ruby applications? Or is there overlap between the two?
    >


    I"m not familiar with RJB, but JRuby can work "both ways". In fact, I use it
    exclusively for times when I need to call Java code from a Ruby application.

    David
    David Corbin, Apr 16, 2005
    #10
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dave Glasser
    Replies:
    5
    Views:
    2,186
    Brett Sheeran
    Aug 27, 2003
  2. Replies:
    5
    Views:
    506
    Michel Claveau
    Jun 12, 2006
  3. Dema
    Replies:
    2
    Views:
    91
    Kaspar Schiess
    Jun 20, 2005
  4. Replies:
    2
    Views:
    118
  5. Anukul Singhal
    Replies:
    0
    Views:
    156
    Anukul Singhal
    Mar 9, 2010
Loading...

Share This Page