Class: RSwim::Agent::PullBased
- Inherits:
-
Object
- Object
- RSwim::Agent::PullBased
- Defined in:
- lib/rswim/agent.rb
Overview
Blocking agent that pops messages from pipe, processes them and pauses before repeating
Direct Known Subclasses
Instance Method Summary collapse
- #append_custom_state(key, value) ⇒ Object
-
#initialize(pipe, node_member_id, seed_member_ids, t_ms, r_ms) ⇒ PullBased
constructor
A new instance of PullBased.
- #run ⇒ Object
- #subscribe(&block) ⇒ Object
Constructor Details
#initialize(pipe, node_member_id, seed_member_ids, t_ms, r_ms) ⇒ PullBased
Returns a new instance of PullBased.
47 48 49 50 |
# File 'lib/rswim/agent.rb', line 47 def initialize(pipe, node_member_id, seed_member_ids, t_ms, r_ms) @pipe = pipe @state = new_protocol_state(node_member_id, seed_member_ids, t_ms, r_ms) end |
Instance Method Details
#append_custom_state(key, value) ⇒ Object
64 65 66 |
# File 'lib/rswim/agent.rb', line 64 def append_custom_state(key, value) @state.append_custom_state(key, value) end |
#run ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/rswim/agent.rb', line 56 def run loop do elapsed_seconds = pause = @state.advance(@pipe.inbound, elapsed_seconds) .each { || @pipe.send() } end end |
#subscribe(&block) ⇒ Object
52 53 54 |
# File 'lib/rswim/agent.rb', line 52 def subscribe(&block) @state.subscribe(&block) end |