Class: OMQ::Routing::Dish
- Inherits:
-
Object
- Object
- OMQ::Routing::Dish
- Defined in:
- lib/omq/routing/dish.rb
Overview
DISH socket routing: group-based receive from RADIO peers.
Sends JOIN/LEAVE commands to connected RADIO peers. Receives two-frame messages (group + body) from RADIO.
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
DISH is read-only.
-
#initialize(engine) ⇒ Dish
constructor
A new instance of Dish.
-
#join(group) ⇒ Object
Joins a group.
-
#leave(group) ⇒ Object
Leaves a group.
-
#stop ⇒ Object
Stops all background tasks.
-
#unblock_recv ⇒ void
Wakes a blocked #dequeue_recv with a nil sentinel.
Constructor Details
Instance Attribute Details
#recv_queue ⇒ Async::LimitedQueue (readonly)
24 25 26 |
# File 'lib/omq/routing/dish.rb', line 24 def recv_queue @recv_queue end |
Instance Method Details
#connection_added(connection) ⇒ Object
47 48 49 50 51 52 53 54 |
# File 'lib/omq/routing/dish.rb', line 47 def connection_added(connection) @connections << connection @groups.each do |group| connection.send_command(Protocol::ZMTP::Codec::Command.join(group)) end task = @engine.start_recv_pump(connection, @recv_queue) @tasks << task if task end |
#connection_removed(connection) ⇒ Object
59 60 61 |
# File 'lib/omq/routing/dish.rb', line 59 def connection_removed(connection) @connections.delete(connection) end |
#dequeue_recv ⇒ Array<String>?
Dequeues the next received message. Blocks until one is available.
31 32 33 |
# File 'lib/omq/routing/dish.rb', line 31 def dequeue_recv @recv_queue.dequeue end |
#enqueue(_parts) ⇒ Object
DISH is read-only.
66 67 68 |
# File 'lib/omq/routing/dish.rb', line 66 def enqueue(_parts) raise "DISH sockets cannot send" end |
#join(group) ⇒ Object
Joins a group.
75 76 77 78 79 80 |
# File 'lib/omq/routing/dish.rb', line 75 def join(group) @groups << group @connections.each do |conn| conn.send_command(Protocol::ZMTP::Codec::Command.join(group)) end end |
#leave(group) ⇒ Object
Leaves a group.
87 88 89 90 91 92 |
# File 'lib/omq/routing/dish.rb', line 87 def leave(group) @groups.delete(group) @connections.each do |conn| conn.send_command(Protocol::ZMTP::Codec::Command.leave(group)) end end |
#stop ⇒ Object
Stops all background tasks.
96 97 98 99 |
# File 'lib/omq/routing/dish.rb', line 96 def stop @tasks.each(&:stop) @tasks.clear end |
#unblock_recv ⇒ void
This method returns an undefined value.
Wakes a blocked #dequeue_recv with a nil sentinel.
40 41 42 |
# File 'lib/omq/routing/dish.rb', line 40 def unblock_recv @recv_queue.enqueue(nil) end |