Class: Aggro::NodeList

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

Overview

Public: Computes which nodes are responsible for a given aggregate ID.

Constant Summary collapse

DEFAULT_REPLICATION_FACTOR =
3

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#stateObject (readonly)

Returns the value of attribute state.



6
7
8
# File 'lib/aggro/node_list.rb', line 6

def state
  @state
end

Instance Method Details

#add(node) ⇒ Object



8
9
10
11
12
# File 'lib/aggro/node_list.rb', line 8

def add(node)
  hash_ring << node

  update_state
end

#nodesObject



21
22
23
# File 'lib/aggro/node_list.rb', line 21

def nodes
  hash_ring.nodes.sort_by(&:id)
end

#nodes_for(id, replication_factor = default_replication_factor) ⇒ Object



14
15
16
17
18
19
# File 'lib/aggro/node_list.rb', line 14

def nodes_for(id, replication_factor = default_replication_factor)
  nodes
    .cycle
    .take(nodes.index(hash_ring.node_for(id)) + replication_factor)
    .last(replication_factor)
end