Class: DCell::NodeManager
- Inherits:
-
Object
- Object
- DCell::NodeManager
- Includes:
- Celluloid::ZMQ, Enumerable
- Defined in:
- lib/dcell/node_manager.rb
Overview
Manage nodes we’re connected to
Instance Attribute Summary collapse
-
#heartbeat_rate ⇒ Object
readonly
Returns the value of attribute heartbeat_rate.
-
#heartbeat_timeout ⇒ Object
readonly
Returns the value of attribute heartbeat_timeout.
Instance Method Summary collapse
-
#all ⇒ Object
Return all available nodes in the cluster.
-
#each ⇒ Object
Iterate across all available nodes.
-
#find(id) ⇒ Object
(also: #[])
Find a node by its node ID.
-
#initialize ⇒ NodeManager
constructor
A new instance of NodeManager.
Constructor Details
#initialize ⇒ NodeManager
Returns a new instance of NodeManager.
9 10 11 12 13 14 |
# File 'lib/dcell/node_manager.rb', line 9 def initialize @nodes = {} @heartbeat_rate = 5 # How often to send heartbeats in seconds @heartbeat_timeout = 10 # How soon until a lost heartbeat triggers a node partition end |
Instance Attribute Details
#heartbeat_rate ⇒ Object (readonly)
Returns the value of attribute heartbeat_rate.
7 8 9 |
# File 'lib/dcell/node_manager.rb', line 7 def heartbeat_rate @heartbeat_rate end |
#heartbeat_timeout ⇒ Object (readonly)
Returns the value of attribute heartbeat_timeout.
7 8 9 |
# File 'lib/dcell/node_manager.rb', line 7 def heartbeat_timeout @heartbeat_timeout end |
Instance Method Details
#all ⇒ Object
Return all available nodes in the cluster
17 18 19 20 21 |
# File 'lib/dcell/node_manager.rb', line 17 def all Directory.all.map do |node_id| find node_id end end |
#each ⇒ Object
Iterate across all available nodes
24 25 26 27 28 |
# File 'lib/dcell/node_manager.rb', line 24 def each Directory.all.each do |node_id| yield find node_id end end |
#find(id) ⇒ Object Also known as: []
Find a node by its node ID
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/dcell/node_manager.rb', line 31 def find(id) node = @nodes[id] return node if node addr = Directory[id] return unless addr if id == DCell.id node = DCell.me else node = Node.new(id, addr) end @nodes[id] ||= node @nodes[id] end |