Class: GorgonBunny::Concurrent::LinkedContinuationQueue

Inherits:
Object
  • Object
show all
Defined in:
lib/gorgon_bunny/lib/gorgon_bunny/concurrent/linked_continuation_queue.rb

Overview

Continuation queue implementation for JRuby.

On JRuby, we’d rather use reliable and heavily battle tested j.u.c. primitives with well described semantics than informally specified, clumsy and limited Ruby standard library parts.

This is an implementation of the continuation queue on top of the linked blocking queue in j.u.c.

Compared to the Ruby standard library Queue, there is one limitation: you cannot push a nil on the queue, it will fail with a null pointer exception.

Instance Method Summary collapse

Constructor Details

#initialize(*args, &block) ⇒ LinkedContinuationQueue

Returns a new instance of LinkedContinuationQueue.



25
26
27
# File 'lib/gorgon_bunny/lib/gorgon_bunny/concurrent/linked_continuation_queue.rb', line 25

def initialize(*args, &block)
  @q = LinkedBlockingQueue.new
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(selector, *args, &block) ⇒ Object



56
57
58
# File 'lib/gorgon_bunny/lib/gorgon_bunny/concurrent/linked_continuation_queue.rb', line 56

def method_missing(selector, *args, &block)
  @q.__send__(selector, *args, &block)
end

Instance Method Details

#clearObject



52
53
54
# File 'lib/gorgon_bunny/lib/gorgon_bunny/concurrent/linked_continuation_queue.rb', line 52

def clear
  @q.clear
end

#poll(timeout_in_ms = nil) ⇒ Object



42
43
44
45
46
47
48
49
50
# File 'lib/gorgon_bunny/lib/gorgon_bunny/concurrent/linked_continuation_queue.rb', line 42

def poll(timeout_in_ms = nil)
  if timeout_in_ms
    v = @q.poll(timeout_in_ms, TimeUnit::MILLISECONDS)
    raise ::Timeout::Error.new("operation did not finish in #{timeout_in_ms} ms") if v.nil?
    v
  else
    @q.poll
  end
end

#popObject



38
39
40
# File 'lib/gorgon_bunny/lib/gorgon_bunny/concurrent/linked_continuation_queue.rb', line 38

def pop
  @q.take
end

#push(el, timeout_in_ms = nil) ⇒ Object Also known as: <<



29
30
31
32
33
34
35
# File 'lib/gorgon_bunny/lib/gorgon_bunny/concurrent/linked_continuation_queue.rb', line 29

def push(el, timeout_in_ms = nil)
  if timeout_in_ms
    @q.offer(el, timeout_in_ms, TimeUnit::MILLISECONDS)
  else
    @q.offer(el)
  end
end