Class: Evinrude::Peer
- Inherits:
-
Object
- Object
- Evinrude::Peer
- Defined in:
- lib/evinrude/peer.rb
Instance Attribute Summary collapse
-
#conn ⇒ Object
readonly
Returns the value of attribute conn.
-
#match_index ⇒ Object
readonly
Returns the value of attribute match_index.
-
#next_index ⇒ Object
readonly
Returns the value of attribute next_index.
-
#node_info ⇒ Object
readonly
Returns the value of attribute node_info.
Instance Method Summary collapse
- #failed_append(last_index = nil) ⇒ Object
-
#initialize(conn:, next_index:, node_info:, metrics:) ⇒ Peer
constructor
A new instance of Peer.
- #node_name ⇒ Object
- #peer_info ⇒ Object
- #rpc(*a) ⇒ Object
- #successful_append(last_index) ⇒ Object
Constructor Details
#initialize(conn:, next_index:, node_info:, metrics:) ⇒ Peer
Returns a new instance of Peer.
7 8 9 10 11 12 |
# File 'lib/evinrude/peer.rb', line 7 def initialize(conn:, next_index:, node_info:, metrics:) @conn, @next_index, @node_info, @metrics = conn, next_index, node_info, metrics @match_index = 0 update_metrics end |
Instance Attribute Details
#conn ⇒ Object (readonly)
Returns the value of attribute conn.
5 6 7 |
# File 'lib/evinrude/peer.rb', line 5 def conn @conn end |
#match_index ⇒ Object (readonly)
Returns the value of attribute match_index.
5 6 7 |
# File 'lib/evinrude/peer.rb', line 5 def match_index @match_index end |
#next_index ⇒ Object (readonly)
Returns the value of attribute next_index.
5 6 7 |
# File 'lib/evinrude/peer.rb', line 5 def next_index @next_index end |
#node_info ⇒ Object (readonly)
Returns the value of attribute node_info.
5 6 7 |
# File 'lib/evinrude/peer.rb', line 5 def node_info @node_info end |
Instance Method Details
#failed_append(last_index = nil) ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/evinrude/peer.rb', line 14 def failed_append(last_index = nil) if last_index @next_index = last_index + 1 else @next_index = [1, @next_index - 1].max end update_metrics end |
#node_name ⇒ Object
35 36 37 |
# File 'lib/evinrude/peer.rb', line 35 def node_name @node_info.name end |
#peer_info ⇒ Object
31 32 33 |
# File 'lib/evinrude/peer.rb', line 31 def peer_info conn.peer_info end |
#rpc(*a) ⇒ Object
39 40 41 |
# File 'lib/evinrude/peer.rb', line 39 def rpc(*a) conn.rpc(*a) end |
#successful_append(last_index) ⇒ Object
24 25 26 27 28 29 |
# File 'lib/evinrude/peer.rb', line 24 def successful_append(last_index) @next_index = last_index + 1 @match_index = last_index update_metrics end |