Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 882645
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T12:27:34+00:00 2026-05-15T12:27:34+00:00

I have built a variety of little scripts using Ruby’s very simple Queue class,

  • 0

I have built a variety of little scripts using Ruby’s very simple Queue class, and share the Queue between Ruby and JRuby processes using DRb. It would be nice to be able to access these from Scala (and maybe Java) using JRuby.

I’ve put together something Scala and the JSR-223 interface to access jruby-complete.jar.

import javax.script._

class DRbQueue(host: String, port: Int) {
  private var engine = DRbQueue.factory.getEngineByName("jruby")
  private var invoker = engine.asInstanceOf[Invocable]
  engine.eval("require \"drb\" ")
  private var queue = engine.eval("DRbObject.new(nil, \"druby://" + host + ":" + port.toString + "\")")

  def isEmpty(): Boolean = invoker.invokeMethod(this.queue, "empty?").asInstanceOf[Boolean]
  def size(): Long = invoker.invokeMethod(this.queue, "length").asInstanceOf[Long]
  def threadsWaiting: Long = invoker.invokeMethod(this.queue, "num_waiting").asInstanceOf[Long]
  def offer(obj: Any) = invoker.invokeMethod(this.queue, "push", obj.asInstanceOf[java.lang.Object])
  def poll(): Any = invoker.invokeMethod(this.queue, "pop")
  def clear(): Unit = { invoker.invokeMethod(this.queue, "clear") }
}
object DRbQueue {
  var factory = new ScriptEngineManager()
}

(It conforms roughly to java.util.Queue interface, but I haven’t declared the interface because it doesn’t implement the element and peek methods because the Ruby class doesn’t offer them.)

The problem with this is the type conversion. JRuby is fine with Scala’s Strings – because they are Java strings. But if I give it a Scala Int or Long, or one of the other Scala types (List, Set, RichString, Array, Symbol) or some other custom type.

This seems unnecessarily hacky: surely there has got to be a better way of doing RMI/DRb interop without having to use JSR-223 API. I could either make it so that the offer method serializes the object to, say, a JSON string and takes a structural type of only objects that have a toJson method. I could then write a Ruby wrapper class (or just monkeypatch Queue) to would parse the JSON.

Is there any point in carrying on with trying to access DRb from Java/Scala? Might it just be easier to install a real message queue? (If so, any suggestions for a lightweight JVM-based MQ?)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T12:27:34+00:00Added an answer on May 15, 2026 at 12:27 pm

    Its worthwile to install a enterprise message queue because DRB and ruby is not the technology for Queuing.

    In my opinion you are creating a tech debt here.

    If you want to persist on the same path you can use the twitter queuing they abandoned starling.

    I think there are heaps of queues available in the Java world JMS.

    If you wrote a DRB server you could have sufficed even doing an array implementing the queue interface thats dead simple!
    then scale appropriately
    http://www.java-tips.org/java-se-tips/java.lang/array-based-queue-implementation-in-java.html

    In my opinion stick to proven enterprise technologies and not hacky unproven ones, I have leanrt that the hard way.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.