Class: OMQ::Routing::Pair
- Inherits:
-
Object
- Object
- OMQ::Routing::Pair
- Includes:
- FairRecv
- Defined in:
- lib/omq/routing/pair.rb
Overview
PAIR socket routing: exclusive 1-to-1 bidirectional.
Only one peer connection is allowed at a time. The send queue is socket-level (one shared bounded queue), and a single send pump fiber drains it into the connected peer. On disconnect, the in-flight batch is dropped (matching libzmq).
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) ⇒ Pair
constructor
A new instance of Pair.
-
#send_queues_drained? ⇒ Boolean
True when the shared send queue is empty.
-
#stop ⇒ void
Stops all background tasks.
Methods included from FairRecv
Constructor Details
#initialize(engine) ⇒ Pair
Returns a new instance of Pair.
23 24 25 26 27 28 29 30 |
# File 'lib/omq/routing/pair.rb', line 23 def initialize(engine) @engine = engine @connection = nil @recv_queue = FairQueue.new @send_queue = Routing.build_queue(@engine..send_hwm, :block) @send_pump = nil @tasks = [] end |
Instance Attribute Details
#recv_queue ⇒ FairQueue (readonly)
18 19 20 |
# File 'lib/omq/routing/pair.rb', line 18 def recv_queue @recv_queue end |
Instance Method Details
#connection_added(connection) ⇒ Object
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/omq/routing/pair.rb', line 36 def connection_added(connection) raise "PAIR allows only one peer" if @connection @connection = connection add_fair_recv_connection(connection) unless connection.is_a?(Transport::Inproc::DirectPipe) start_send_pump(connection) end end |
#connection_removed(connection) ⇒ Object
50 51 52 53 54 55 56 57 |
# File 'lib/omq/routing/pair.rb', line 50 def connection_removed(connection) if @connection == connection @connection = nil @recv_queue.remove_queue(connection) @send_pump&.stop @send_pump = nil end end |
#enqueue(parts) ⇒ Object
62 63 64 65 66 67 68 69 |
# File 'lib/omq/routing/pair.rb', line 62 def enqueue(parts) conn = @connection if conn.is_a?(Transport::Inproc::DirectPipe) && conn.direct_recv_queue conn.(parts) else @send_queue.enqueue(parts) end end |
#send_queues_drained? ⇒ Boolean
Returns true when the shared send queue is empty.
84 85 86 |
# File 'lib/omq/routing/pair.rb', line 84 def send_queues_drained? @send_queue.empty? end |
#stop ⇒ void
This method returns an undefined value.
Stops all background tasks.
76 77 78 79 |
# File 'lib/omq/routing/pair.rb', line 76 def stop @tasks.each(&:stop) @tasks.clear end |