Class: OMQ::Routing::Dish
- Inherits:
-
Object
- Object
- OMQ::Routing::Dish
- Includes:
- FairRecv
- 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 ⇒ FairQueue readonly
Instance Method Summary collapse
- #connection_added(connection) ⇒ Object
- #connection_removed(connection) ⇒ Object
-
#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.
Constructor Details
#initialize(engine) ⇒ Dish
Returns a new instance of Dish.
15 16 17 18 19 20 21 |
# File 'lib/omq/routing/dish.rb', line 15 def initialize(engine) @engine = engine @connections = [] @recv_queue = FairQueue.new @groups = Set.new @tasks = [] end |
Instance Attribute Details
#recv_queue ⇒ FairQueue (readonly)
26 27 28 |
# File 'lib/omq/routing/dish.rb', line 26 def recv_queue @recv_queue end |
Instance Method Details
#connection_added(connection) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/omq/routing/dish.rb', line 30 def connection_added(connection) @connections << connection @groups.each do |group| connection.send_command(Protocol::ZMTP::Codec::Command.join(group)) end add_fair_recv_connection(connection) end |
#connection_removed(connection) ⇒ Object
41 42 43 44 |
# File 'lib/omq/routing/dish.rb', line 41 def connection_removed(connection) @connections.delete(connection) @recv_queue.remove_queue(connection) end |
#enqueue(_parts) ⇒ Object
DISH is read-only.
49 50 51 |
# File 'lib/omq/routing/dish.rb', line 49 def enqueue(_parts) raise "DISH sockets cannot send" end |
#join(group) ⇒ Object
Joins a group.
58 59 60 61 62 63 |
# File 'lib/omq/routing/dish.rb', line 58 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.
70 71 72 73 74 75 |
# File 'lib/omq/routing/dish.rb', line 70 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.
79 80 81 82 |
# File 'lib/omq/routing/dish.rb', line 79 def stop @tasks.each(&:stop) @tasks.clear end |