lib/dcell/node_manager.rb in dcell-0.16.0 vs lib/dcell/node_manager.rb in dcell-0.16.1
- old
+ new
@@ -2,10 +2,12 @@
# Manage nodes we're connected to
class NodeManager
include Celluloid::ZMQ
include Enumerable
+ trap_exit :node_died
+
attr_reader :heartbeat_rate, :heartbeat_timeout
def initialize
@nodes = {}
@@ -37,13 +39,41 @@
if id == DCell.id
node = DCell.me
else
node = Node.new(id, addr)
+ self.link node
end
@nodes[id] ||= node
@nodes[id]
end
alias_method :[], :find
+
+ 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
+
+ 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
+
+ def remove(id)
+ if @nodes[id]
+ @nodes[id].terminate if @nodes[id].alive?
+ @nodes.delete(id)
+ end
+ end
end
end