Class: RSwim::ProtocolState
- Inherits:
-
Object
- Object
- RSwim::ProtocolState
- Defined in:
- lib/rswim/protocol_state.rb
Instance Method Summary collapse
- #advance(input_messages, elapsed_seconds) ⇒ Object
- #append_custom_state(key, value) ⇒ Object
-
#initialize(node_member_id, seed_member_ids, t_ms, r_ms) ⇒ ProtocolState
constructor
A new instance of ProtocolState.
- #subscribe(&block) ⇒ Object
Constructor Details
#initialize(node_member_id, seed_member_ids, t_ms, r_ms) ⇒ ProtocolState
Returns a new instance of ProtocolState.
5 6 7 8 9 10 11 |
# File 'lib/rswim/protocol_state.rb', line 5 def initialize(node_member_id, seed_member_ids, t_ms, r_ms) @t_ms = t_ms @r_ms = r_ms @member_pool = new_member_pool(node_member_id, seed_member_ids) @node_member_id = node_member_id @t = @r = 1 end |
Instance Method Details
#advance(input_messages, elapsed_seconds) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/rswim/protocol_state.rb', line 21 def advance(, elapsed_seconds) @t += elapsed_seconds * 1000 @t = 0 if @t >= @t_ms @r += elapsed_seconds * 1000 @r = 0 if @r >= @r_ms .each do || raise 'message must be of type Message' unless .is_a? Message update_member() end @member_pool.update_members(elapsed_seconds) = @member_pool.prepare_output # TODO: more deterministic steady state mechanism, # e.g. output_messages = @member_pool.next_steady_state(elapsed_seconds) # using a flag set by member state 3.times do @member_pool.update_members(0) .concat(@member_pool.prepare_output) end @member_pool.send_ping_to_random_healthy_member if @t == 0 3.times do @member_pool.update_members(0) .concat(@member_pool.prepare_output) end @member_pool.status_report if @r == 0 end |
#append_custom_state(key, value) ⇒ Object
17 18 19 |
# File 'lib/rswim/protocol_state.rb', line 17 def append_custom_state(key, value) @member_pool.append_custom_state(key, value) end |
#subscribe(&block) ⇒ Object
13 14 15 |
# File 'lib/rswim/protocol_state.rb', line 13 def subscribe(&block) @member_pool.subscribe(&block) end |