Class: OMQ::Routing::Req
- Inherits:
-
Object
- Object
- OMQ::Routing::Req
- Includes:
- FairRecv, RoundRobin
- Defined in:
- lib/omq/routing/req.rb
Overview
REQ socket routing: round-robin send with strict send/recv alternation.
REQ prepends an empty delimiter frame on send and strips it on receive.
Constant Summary collapse
- EMPTY_BINARY =
Shared frozen empty binary string to avoid repeated allocations.
::Protocol::ZMTP::Codec::EMPTY_BINARY
Constants included from RoundRobin
OMQ::Routing::RoundRobin::BATCH_BYTE_CAP, OMQ::Routing::RoundRobin::BATCH_MSG_CAP
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) ⇒ Req
constructor
A new instance of Req.
-
#stop ⇒ void
Stops all background tasks.
Methods included from FairRecv
Methods included from RoundRobin
Constructor Details
Instance Attribute Details
#recv_queue ⇒ FairQueue (readonly)
19 20 21 |
# File 'lib/omq/routing/req.rb', line 19 def recv_queue @recv_queue end |
Instance Method Details
#connection_added(connection) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/omq/routing/req.rb', line 35 def connection_added(connection) add_fair_recv_connection(connection) do |msg| @state = :ready msg.first&.empty? ? msg[1..] : msg end add_round_robin_send_connection(connection) end |
#connection_removed(connection) ⇒ Object
46 47 48 49 50 |
# File 'lib/omq/routing/req.rb', line 46 def connection_removed(connection) @connections.delete(connection) @recv_queue.remove_queue(connection) remove_round_robin_send_connection(connection) end |
#enqueue(parts) ⇒ Object
55 56 57 58 59 |
# File 'lib/omq/routing/req.rb', line 55 def enqueue(parts) raise SocketError, "REQ socket expects send/recv/send/recv order" unless @state == :ready @state = :waiting_reply enqueue_round_robin(parts) end |
#stop ⇒ void
This method returns an undefined value.
Stops all background tasks.
66 67 68 69 |
# File 'lib/omq/routing/req.rb', line 66 def stop @tasks.each(&:stop) @tasks.clear end |