Class: OMQ::Routing::Channel
- Inherits:
-
Object
- Object
- OMQ::Routing::Channel
- Defined in:
- lib/omq/routing/channel.rb
Overview
CHANNEL socket routing: exclusive 1-to-1 bidirectional.
Instance Attribute Summary collapse
- #recv_queue ⇒ Async::LimitedQueue readonly
Instance Method Summary collapse
- #connection_added(connection) ⇒ Object
- #connection_removed(connection) ⇒ Object
-
#dequeue_recv ⇒ Array<String>?
Dequeues the next received message.
- #enqueue(parts) ⇒ Object
-
#initialize(engine) ⇒ Channel
constructor
A new instance of Channel.
-
#send_queues_drained? ⇒ Boolean
True when the staging and send queues are empty.
-
#unblock_recv ⇒ void
Wakes a blocked #dequeue_recv with a nil sentinel.
Constructor Details
#initialize(engine) ⇒ Channel
Returns a new instance of Channel.
15 16 17 18 19 20 21 |
# File 'lib/omq/routing/channel.rb', line 15 def initialize(engine) @engine = engine @connection = nil @recv_queue = Routing.build_queue(engine..recv_hwm, :block) @send_queue = nil @staging_queue = Routing.build_queue(engine..send_hwm, :block) end |
Instance Attribute Details
#recv_queue ⇒ Async::LimitedQueue (readonly)
10 11 12 |
# File 'lib/omq/routing/channel.rb', line 10 def recv_queue @recv_queue end |
Instance Method Details
#connection_added(connection) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/omq/routing/channel.rb', line 45 def connection_added(connection) raise "CHANNEL allows only one peer" if @connection @connection = connection @engine.start_recv_pump(connection, @recv_queue) unless connection.is_a?(Transport::Inproc::Pipe) @send_queue = Routing.build_queue(@engine..send_hwm, :block) while (msg = @staging_queue.dequeue(timeout: 0)) @send_queue.enqueue(msg) end start_send_pump(connection) end end |
#connection_removed(connection) ⇒ Object
63 64 65 66 67 68 |
# File 'lib/omq/routing/channel.rb', line 63 def connection_removed(connection) if @connection == connection @connection = nil @send_queue = nil end end |
#dequeue_recv ⇒ Array<String>?
Dequeues the next received message. Blocks until one is available.
28 29 30 |
# File 'lib/omq/routing/channel.rb', line 28 def dequeue_recv @recv_queue.dequeue end |
#enqueue(parts) ⇒ Object
73 74 75 76 77 78 79 80 81 82 |
# File 'lib/omq/routing/channel.rb', line 73 def enqueue(parts) conn = @connection if conn.is_a?(Transport::Inproc::Pipe) && conn.direct_recv_queue conn.(parts) elsif @send_queue @send_queue.enqueue(parts) else @staging_queue.enqueue(parts) end end |
#send_queues_drained? ⇒ Boolean
True when the staging and send queues are empty.
87 88 89 |
# File 'lib/omq/routing/channel.rb', line 87 def send_queues_drained? @staging_queue.empty? && (@send_queue.nil? || @send_queue.empty?) end |
#unblock_recv ⇒ void
This method returns an undefined value.
Wakes a blocked #dequeue_recv with a nil sentinel.
37 38 39 |
# File 'lib/omq/routing/channel.rb', line 37 def unblock_recv @recv_queue.enqueue(nil) end |