Created
August 23, 2012 14:44
-
-
Save jpignata/3437294 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "java" | |
class Item | |
include java.util.concurrent.Delayed | |
def initialize(deliver_at) | |
@deliver_at = deliver_at | |
end | |
def get_delay | |
@deliver_at | |
end | |
def compare_to(other_item) | |
get_delay <=> other_item.get_delay | |
end | |
end | |
class QueueWrapper | |
import java.util.concurrent.DelayQueue | |
def initialize | |
@queue = DelayQueue.new | |
end | |
def <<(item) | |
queue.offer(item) | |
end | |
def pop | |
queue.poll | |
end | |
def size | |
queue.size | |
end | |
def peek | |
queue.peek | |
end | |
private | |
attr_reader :queue | |
end | |
item = Item.new(Time.now) | |
queue = QueueWrapper.new | |
queue << item | |
p "Peek: " + queue.peek.inspect | |
p "Pop: " + queue.pop.inspect |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jp@oeuf:~/workspace/transporter(master*)$ ruby -v | |
jruby 1.6.7.2 (ruby-1.9.2-p312) (2012-05-01 26e08ba) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_33) [darwin-x86_64-java] | |
jp@oeuf:~/workspace/transporter(master*)$ ruby test.rb | |
"Peek: #<Item:0x6d87275d @deliver_at=2012-08-23 10:48:26 -0400>" | |
ArgumentError: wrong number of arguments (1 for 0) | |
pop at test.rb:31 | |
(root) at test.rb:51 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This turned out to be a faulty implementation of get_delay which takes a parameter of a TimeUnit. Turns out that jruby 1.6 doesn't return useful information but 1.7's stack trace properly identifies this problem. See http://docs.oracle.com/javase/6/docs/api/java/util/concurrent/Delayed.html