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.
- #node_died(node, reason) ⇒ Object
- #remove(id) ⇒ Object
- #update(id) ⇒ Object
Constructor Details
#initialize ⇒ NodeManager
Returns a new instance of NodeManager.
11 12 13 14 15 16 |
# File 'lib/dcell/node_manager.rb', line 11 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.
9 10 11 |
# File 'lib/dcell/node_manager.rb', line 9 def heartbeat_rate @heartbeat_rate end |
#heartbeat_timeout ⇒ Object (readonly)
Returns the value of attribute heartbeat_timeout.
9 10 11 |
# File 'lib/dcell/node_manager.rb', line 9 def heartbeat_timeout @heartbeat_timeout end |
Instance Method Details
#all ⇒ Object
Return all available nodes in the cluster
19 20 21 22 23 |
# File 'lib/dcell/node_manager.rb', line 19 def all Directory.all.map do |node_id| find node_id end end |
#each ⇒ Object
Iterate across all available nodes
26 27 28 29 30 |
# File 'lib/dcell/node_manager.rb', line 26 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
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/dcell/node_manager.rb', line 33 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) self.link node end @nodes[id] ||= node @nodes[id] end |
#node_died(node, reason) ⇒ Object
52 53 54 55 56 57 58 59 60 |
# File 'lib/dcell/node_manager.rb', line 52 def node_died(node, reason) if reason.nil? # wtf? # this wtf error seems to come from node socket writes # when the socket is not reachable anymore Celluloid::logger.debug "wtf?" return end # Handle dead node??? end |
#remove(id) ⇒ Object
72 73 74 75 76 77 |
# File 'lib/dcell/node_manager.rb', line 72 def remove(id) if @nodes[id] @nodes[id].terminate if @nodes[id].alive? @nodes.delete(id) end end |