Sha256: 6e1aaddb77f6e1dab3d2f6b45c35a66ccd6d141ac1f73ffabd12df6fd9ba8012

Contents?: true

Size: 1.61 KB

Versions: 28

Compression:

Stored size: 1.61 KB

Contents

if !defined?(JRUBY_VERSION)
  raise "GorgonBunny::Concurrent::LinkedContinuationQueue can only be used on JRuby!"
end

require "java"

java_import java.util.concurrent.LinkedBlockingQueue
java_import java.util.concurrent.TimeUnit

module GorgonBunny
  module Concurrent
    # 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.
    # @private
    class LinkedContinuationQueue
      def initialize(*args, &block)
        @q = LinkedBlockingQueue.new
      end

      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
      alias << push

      def pop
        @q.take
      end

      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

      def clear
        @q.clear
      end

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

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
gorgon-0.11.1 lib/gorgon_bunny/lib/gorgon_bunny/concurrent/linked_continuation_queue.rb
gorgon-0.11.0 lib/gorgon_bunny/lib/gorgon_bunny/concurrent/linked_continuation_queue.rb
gorgon-0.10.5 lib/gorgon_bunny/lib/gorgon_bunny/concurrent/linked_continuation_queue.rb
gorgon-0.10.4 lib/gorgon_bunny/lib/gorgon_bunny/concurrent/linked_continuation_queue.rb
gorgon-0.10.3 lib/gorgon_bunny/lib/gorgon_bunny/concurrent/linked_continuation_queue.rb
gorgon-0.10.2 lib/gorgon_bunny/lib/gorgon_bunny/concurrent/linked_continuation_queue.rb
gorgon-0.10.1 lib/gorgon_bunny/lib/gorgon_bunny/concurrent/linked_continuation_queue.rb
gorgon-0.10.0 lib/gorgon_bunny/lib/gorgon_bunny/concurrent/linked_continuation_queue.rb
gorgon-0.9.0 lib/gorgon_bunny/lib/gorgon_bunny/concurrent/linked_continuation_queue.rb
gorgon-0.8.4 lib/gorgon_bunny/lib/gorgon_bunny/concurrent/linked_continuation_queue.rb
gorgon-0.8.3 lib/gorgon_bunny/lib/gorgon_bunny/concurrent/linked_continuation_queue.rb
gorgon-0.8.2 lib/gorgon_bunny/lib/gorgon_bunny/concurrent/linked_continuation_queue.rb
gorgon-0.8.1 lib/gorgon_bunny/lib/gorgon_bunny/concurrent/linked_continuation_queue.rb
gorgon-0.8.0 lib/gorgon_bunny/lib/gorgon_bunny/concurrent/linked_continuation_queue.rb
gorgon-0.7.1 lib/gorgon_bunny/lib/gorgon_bunny/concurrent/linked_continuation_queue.rb
gorgon-0.7.0 lib/gorgon_bunny/lib/gorgon_bunny/concurrent/linked_continuation_queue.rb
gorgon-0.7.0.rc4 lib/gorgon_bunny/lib/gorgon_bunny/concurrent/linked_continuation_queue.rb
gorgon-0.7.0.rc3 lib/gorgon_bunny/lib/gorgon_bunny/concurrent/linked_continuation_queue.rb
gorgon-0.7.0.rc2 lib/gorgon_bunny/lib/gorgon_bunny/concurrent/linked_continuation_queue.rb
gorgon-0.7.0.rc1 lib/gorgon_bunny/lib/gorgon_bunny/concurrent/linked_continuation_queue.rb