Sha256: d1075058092aa84e730e17831b61dc61f588ef663b7adba22a57ffd80662474e

Contents?: true

Size: 1.52 KB

Versions: 13

Compression:

Stored size: 1.52 KB

Contents

module AMQP
  module ChannelIdAllocator

    MAX_CHANNELS_PER_CONNECTION = (2**16) - 1

    # Resets channel allocator. This method is thread safe.
    # @api public
    # @see Channel.next_channel_id
    # @see Channel.release_channel_id
    def reset_channel_id_allocator
      channel_id_mutex.synchronize do
        int_allocator.reset
      end
    end

    # Releases previously allocated channel id. This method is thread safe.
    #
    # @param [Fixnum] Channel id to release
    # @api public
    # @see Channel.next_channel_id
    # @see Channel.reset_channel_id_allocator
    def release_channel_id(i)
      channel_id_mutex.synchronize do
        int_allocator.release(i)
      end
    end

    # Returns next available channel id. This method is thread safe.
    #
    # @return [Fixnum]
    # @api public
    # @see Channel.release_channel_id
    # @see Channel.reset_channel_id_allocator
    def next_channel_id
      channel_id_mutex.synchronize do
        result = int_allocator.allocate
        raise "No further channels available. Please open a new connection." if result < 0
        result
      end
    end

    private

    # @private
    # @api private
    def channel_id_mutex
      @channel_id_mutex ||= Mutex.new
    end

    # @private
    def int_allocator
      # TODO: ideally, this should be in agreement with agreed max number of channels of the connection,
      #       but it is possible that value either not yet available. MK.
      @int_allocator ||= IntAllocator.new(1, MAX_CHANNELS_PER_CONNECTION)
    end

  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
amqp-1.8.0 lib/amqp/channel_id_allocator.rb
amqp-1.7.0 lib/amqp/channel_id_allocator.rb
amqp-1.6.0 lib/amqp/channel_id_allocator.rb
amqp-1.5.3 lib/amqp/channel_id_allocator.rb
amqp-1.5.2 lib/amqp/channel_id_allocator.rb
amqp-1.5.1 lib/amqp/channel_id_allocator.rb
amqp-1.5.0 lib/amqp/channel_id_allocator.rb
amqp-1.4.2 lib/amqp/channel_id_allocator.rb
amqp-1.4.1 lib/amqp/channel_id_allocator.rb
amqp-1.4.0 lib/amqp/channel_id_allocator.rb
amqp-1.3.0 lib/amqp/channel_id_allocator.rb
amqp-1.2.1 lib/amqp/channel_id_allocator.rb
amqp-1.2.0 lib/amqp/channel_id_allocator.rb