lib/cellect/client/node_set.rb in cellect-client-0.1.2 vs lib/cellect/client/node_set.rb in cellect-client-0.1.3
- old
+ new
@@ -3,29 +3,33 @@
module Cellect
module Client
class NodeSet < Cellect::NodeSet
attr_accessor :nodes
+ # Sets up an empty node set
def initialize(zk_url = nil)
self.nodes = { }
super
end
protected
+ # Respond to a node coming online or timing out
def nodes_changed(nodes)
self.nodes = { }
nodes.each do |node|
self.nodes[node] = zk.get("/nodes/#{ node }").first
end
end
+ # Register with ZooKeeper and get the list of nodes
def setup
watch_nodes
zk.mkdir_p '/nodes'
nodes_changed zk.children('/nodes', watch: true)
end
+ # Watch ZooKeeper for changes to the node set
def watch_nodes
zk.register('/nodes') do |event|
nodes_changed zk.children('/nodes', watch: true)
end
end