Class: OMQ::Routing::Channel
- Inherits:
-
Object
- Object
- OMQ::Routing::Channel
- Includes:
- FairRecv
- Defined in:
- lib/omq/routing/channel.rb
Overview
CHANNEL socket routing: exclusive 1-to-1 bidirectional.
Instance Attribute Summary collapse
- #recv_queue ⇒ FairQueue readonly
Instance Method Summary collapse
- #connection_added(connection) ⇒ Object
- #connection_removed(connection) ⇒ Object
- #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.
-
#stop ⇒ Object
Stops all background tasks (send pumps).
Constructor Details
#initialize(engine) ⇒ Channel
Returns a new instance of Channel.
12 13 14 15 16 17 18 19 20 |
# File 'lib/omq/routing/channel.rb', line 12 def initialize(engine) @engine = engine @connection = nil @recv_queue = FairQueue.new @send_queue = nil @staging_queue = Routing.build_queue(@engine..send_hwm, :block) @send_pump = nil @tasks = [] end |
Instance Attribute Details
#recv_queue ⇒ FairQueue (readonly)
25 26 27 |
# File 'lib/omq/routing/channel.rb', line 25 def recv_queue @recv_queue end |
Instance Method Details
#connection_added(connection) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/omq/routing/channel.rb', line 30 def connection_added(connection) raise "CHANNEL allows only one peer" if @connection @connection = connection add_fair_recv_connection(connection) unless connection.is_a?(Transport::Inproc::DirectPipe) @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
48 49 50 51 52 53 54 55 56 |
# File 'lib/omq/routing/channel.rb', line 48 def connection_removed(connection) if @connection == connection @connection = nil @recv_queue.remove_queue(connection) @send_queue = nil @send_pump&.stop @send_pump = nil end end |
#enqueue(parts) ⇒ Object
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/omq/routing/channel.rb', line 61 def enqueue(parts) conn = @connection if conn.is_a?(Transport::Inproc::DirectPipe) && 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.
82 83 84 |
# File 'lib/omq/routing/channel.rb', line 82 def send_queues_drained? @staging_queue.empty? && (@send_queue.nil? || @send_queue.empty?) end |
#stop ⇒ Object
Stops all background tasks (send pumps).
74 75 76 77 |
# File 'lib/omq/routing/channel.rb', line 74 def stop @tasks.each(&:stop) @tasks.clear end |