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
- #initialize(*args, &block) ⇒ Object
-
#next_channel_id ⇒ Fixnum
Returns next available channel id.
-
#release_channel_id(i) ⇒ Object
Releases previously allocated channel id.
-
#reset_channel_id_allocator ⇒ Object
Resets channel allocator.
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_id ⇒ Fixnum
Returns next available channel id. This method is thread safe.
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.
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_allocator ⇒ Object
Resets channel allocator. This method is thread safe.
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 |