Class: Evinrude::Peer

Inherits:
Object
  • Object
show all
Defined in:
lib/evinrude/peer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#connObject (readonly)

Returns the value of attribute conn.



5
6
7
# File 'lib/evinrude/peer.rb', line 5

def conn
  @conn
end

#match_indexObject (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_indexObject (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_infoObject (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_nameObject



35
36
37
# File 'lib/evinrude/peer.rb', line 35

def node_name
	@node_info.name
end

#peer_infoObject



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