Class: RSwim::Agent::PullBased

Inherits:
Object
  • Object
show all
Defined in:
lib/rswim/agent.rb

Overview

Blocking agent that pops messages from pipe, processes them and pauses before repeating

Direct Known Subclasses

FiberBased, SleepBased

Instance Method Summary collapse

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

#runObject



56
57
58
59
60
61
62
# File 'lib/rswim/agent.rb', line 56

def run
  loop do
    elapsed_seconds = pause
    output_messages = @state.advance(@pipe.inbound, elapsed_seconds)
    output_messages.each { |message| @pipe.send(message) }
  end
end

#subscribe(&block) ⇒ Object



52
53
54
# File 'lib/rswim/agent.rb', line 52

def subscribe(&block)
  @state.subscribe(&block)
end