class DCell::NodeManager

Manage nodes we’re connected to

Attributes

heartbeat_rate[R]
heartbeat_timeout[R]

Public Class Methods

new() click to toggle source
# 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

Public Instance Methods

[](id)
Alias for: find
all() click to toggle source

Return all available nodes in the cluster

# File lib/dcell/node_manager.rb, line 19
def all
  Directory.all.map do |node_id|
    find node_id
  end
end
each() { |find node_id| ... } click to toggle source

Iterate across all available nodes

# File lib/dcell/node_manager.rb, line 26
def each
  Directory.all.each do |node_id|
    yield find node_id
  end
end
find(id) click to toggle source

Find a node by its node ID

# 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
Also aliased as: []
node_died(node, reason) click to toggle source
# 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) click to toggle source
# 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
update(id) click to toggle source
# File lib/dcell/node_manager.rb, line 62
def update(id)
  addr = Directory[id]
  return unless addr
  if ( node = @nodes[id] ) and node.alive?
    node.update_client_address( addr )
  else
    @nodes[id] = Node.new( id, addr )
  end
end