lib/cellect/client/node_set.rb in cellect-client-1.3.3 vs lib/cellect/client/node_set.rb in cellect-client-2.0.0.beta1

- old
+ new

@@ -1,38 +1,14 @@ -require 'cellect/node_set' - module Cellect module Client - class NodeSet < Cellect::NodeSet + class 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) + # Gets the current list of nodes and listens to changes + def initialize + self.nodes = Attention.instances + Attention.on_change do |change, instances| + self.nodes = instances end end end end end