module AMQP::ChannelIdAllocator

Constants

MAX_CHANNELS_PER_CONNECTION

Public Instance Methods

next_channel_id() click to toggle source

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

# File lib/amqp/channel_id_allocator.rb, line 34
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
release_channel_id(i) click to toggle source

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

# File lib/amqp/channel_id_allocator.rb, line 22
def release_channel_id(i)
  channel_id_mutex.synchronize do
    int_allocator.release(i)
  end
end
reset_channel_id_allocator() click to toggle source

Resets channel allocator. This method is thread safe. @api public @see Channel.next_channel_id @see Channel.release_channel_id

# File lib/amqp/channel_id_allocator.rb, line 10
def reset_channel_id_allocator
  channel_id_mutex.synchronize do
    int_allocator.reset
  end
end

Private Instance Methods

channel_id_mutex() click to toggle source

@private @api private

# File lib/amqp/channel_id_allocator.rb, line 46
def channel_id_mutex
  @channel_id_mutex ||= Mutex.new
end
int_allocator() click to toggle source

@private

# File lib/amqp/channel_id_allocator.rb, line 51
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