Class: Aggro::Locator

Inherits:
Object
  • Object
show all
Defined in:
lib/aggro/locator.rb

Overview

Public: Locates the nodes responsible for a given entity ID.

Instance Method Summary collapse

Constructor Details

#initialize(id) ⇒ Locator

Returns a new instance of Locator.



4
5
6
# File 'lib/aggro/locator.rb', line 4

def initialize(id)
  @id = id
end

Instance Method Details

#local?Boolean

Returns:

  • (Boolean)


8
9
10
# File 'lib/aggro/locator.rb', line 8

def local?
  primary_node.is_a? LocalNode
end

#nodesObject



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/aggro/locator.rb', line 12

def nodes
  current_node_list_state = Aggro.node_list.state

  if @last_node_list_state == current_node_list_state
    @nodes ||= Aggro.node_list.nodes_for(@id)
  else
    @last_node_list_state = current_node_list_state

    @nodes = Aggro.node_list.nodes_for(@id)
  end
end

#primary_nodeObject



24
25
26
# File 'lib/aggro/locator.rb', line 24

def primary_node
  nodes.first
end

#secondary_nodesObject



28
29
30
# File 'lib/aggro/locator.rb', line 28

def secondary_nodes
  nodes[1..-1]
end