Sha256: 8ccb8d880fdb94e4d46d13784017b776d97cb03da46ca1514ea34aead05469d6

Contents?: true

Size: 918 Bytes

Versions: 1

Compression:

Stored size: 918 Bytes

Contents

require 'cellect/node_set'

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
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cellect-client-0.1.3 lib/cellect/client/node_set.rb