Module: AMQP::ChannelIdAllocator

Included in:
Session
Defined in:
lib/amqp/channel_id_allocator.rb

Constant Summary collapse

MAX_CHANNELS_PER_CONNECTION =
(2**16) - 1

Instance Method Summary collapse

Instance Method Details

#initialize(*args, &block) ⇒ Object


6
7
8
9
10
# File 'lib/amqp/channel_id_allocator.rb', line 6

def initialize(*args, &block)
  super
  
  @channel_id_mutex = Mutex.new
end

#next_channel_idFixnum

Returns next available channel id. This method is thread safe.

Returns:

  • (Fixnum)

See Also:

  • Channel.release_channel_id
  • Channel.reset_channel_id_allocator

40
41
42
43
44
45
46
# File 'lib/amqp/channel_id_allocator.rb', line 40

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) ⇒ Object

Releases previously allocated channel id. This method is thread safe.

Parameters:

  • Channel (Fixnum)

    id to release

See Also:

  • Channel.next_channel_id
  • Channel.reset_channel_id_allocator

28
29
30
31
32
# File 'lib/amqp/channel_id_allocator.rb', line 28

def release_channel_id(i)
  @channel_id_mutex.synchronize do
    int_allocator.release(i)
  end
end

#reset_channel_id_allocatorObject

Resets channel allocator. This method is thread safe.

See Also:

  • Channel.next_channel_id
  • Channel.release_channel_id

16
17
18
19
20
# File 'lib/amqp/channel_id_allocator.rb', line 16

def reset_channel_id_allocator
  @channel_id_mutex.synchronize do
    int_allocator.reset
  end
end