Class: RSwim::Member::Peer
- Inherits:
-
Base
- Object
- Base
- RSwim::Member::Peer
show all
- Defined in:
- lib/rswim/member/peer.rb
Defined Under Namespace
Classes: CustomStateHolder
Instance Method Summary
collapse
Constructor Details
#initialize(id, node_member_id, member_pool) ⇒ Peer
Returns a new instance of Peer.
6
7
8
9
10
11
12
13
14
|
# File 'lib/rswim/member/peer.rb', line 6
def initialize(id, node_member_id, member_pool)
super(id)
@member_pool = member_pool
@node_member_id = node_member_id
@transmission_state = TransmissionState::Ready.new(id, node_member_id, member_pool)
@health_state = HealthState::Alive.new(id, node_member_id, member_pool)
@forwarding_state = ForwardingState::Ready.new(id, node_member_id)
@custom_state_holder = CustomStateHolder.new(id, node_member_id)
end
|
Instance Method Details
#can_be_pinged? ⇒ Boolean
84
85
86
|
# File 'lib/rswim/member/peer.rb', line 84
def can_be_pinged?
@health_state.can_be_pinged?
end
|
#failed_to_reply ⇒ Object
44
45
46
|
# File 'lib/rswim/member/peer.rb', line 44
def failed_to_reply
@health_state.member_failed_to_reply
end
|
#forward_ack ⇒ Object
54
55
56
|
# File 'lib/rswim/member/peer.rb', line 54
def forward_ack
@forwarding_state.forward_ack_to_member
end
|
#halt ⇒ Object
50
51
52
|
# File 'lib/rswim/member/peer.rb', line 50
def halt
@transmission_state = TransmissionState::Off.new(@id, @node_member_id)
end
|
#incorporate_gossip(update_entry) ⇒ Object
78
79
80
81
82
|
# File 'lib/rswim/member/peer.rb', line 78
def incorporate_gossip(update_entry)
update_custom_state(update_entry.custom_state, update_entry.incarnation_number)
update_suspicion(update_entry.status, update_entry.incarnation_number)
@incarnation_number = update_entry.incarnation_number if update_entry.incarnation_number > @incarnation_number
end
|
#increment_propagation_count ⇒ Object
64
65
66
67
|
# File 'lib/rswim/member/peer.rb', line 64
def increment_propagation_count
@health_state.increment_propagation_count
@custom_state_holder.increment_propagation_count
end
|
#ping! ⇒ Object
send a ping message to this peer
19
20
21
|
# File 'lib/rswim/member/peer.rb', line 19
def ping!
@transmission_state.enqueue_ping
end
|
#ping_from!(source_id) ⇒ Object
send a ping message to this peer on behalf of source with source_id
29
30
31
|
# File 'lib/rswim/member/peer.rb', line 29
def ping_from!(source_id)
@transmission_state.enqueue_ping_from(source_id)
end
|
#ping_request!(target_id) ⇒ Object
send ping request to this peer trying to reach target with target_id
24
25
26
|
# File 'lib/rswim/member/peer.rb', line 24
def ping_request!(target_id)
@transmission_state.enqueue_ping_request(target_id)
end
|
#prepare_output ⇒ Object
69
70
71
|
# File 'lib/rswim/member/peer.rb', line 69
def prepare_output
[@transmission_state, @forwarding_state].flat_map(&:prepare_output)
end
|
#prepare_update_entry ⇒ Object
73
74
75
76
|
# File 'lib/rswim/member/peer.rb', line 73
def prepare_update_entry
pc = [@health_state, @custom_state_holder].map!(&:propagation_count).min
UpdateEntry.new(@id, @health_state.status, @incarnation_number, @custom_state_holder.state, pc)
end
|
#replied_in_time ⇒ Object
40
41
42
|
# File 'lib/rswim/member/peer.rb', line 40
def replied_in_time
update_suspicion(:alive)
end
|
#replied_with_ack ⇒ Object
call this when you received ack from member
36
37
38
|
# File 'lib/rswim/member/peer.rb', line 36
def replied_with_ack
@transmission_state.member_replied_with_ack
end
|
#update(elapsed_seconds) ⇒ Object
58
59
60
61
62
|
# File 'lib/rswim/member/peer.rb', line 58
def update(elapsed_seconds)
@transmission_state = @transmission_state.advance(elapsed_seconds)
@forwarding_state = @forwarding_state.advance(elapsed_seconds)
@health_state = @health_state.advance(elapsed_seconds)
end
|