lib/z_k/client.rb in zk-0.6.4 vs lib/z_k/client.rb in zk-0.6.5

- old
+ new

@@ -267,11 +267,11 @@ else raise ArgumentError, "Unknown mode: #{mode.inspect}" end end - rv = check_rc(@cnx.create(h)) + rv = check_rc(@cnx.create(h), h) h[:callback] ? rv : rv[:path] end # Return the data and stat of the node of the given path. @@ -321,11 +321,11 @@ def get(path, opts={}) h = { :path => path }.merge(opts) setup_watcher!(:data, h) - rv = check_rc(@cnx.get(h)) + rv = check_rc(@cnx.get(h), h) opts[:callback] ? rv : rv.values_at(:data, :stat) end # Set the data for the node of the given path if such a node exists and the @@ -370,11 +370,11 @@ # zk.set("/path", "foo", :callback => callback, :context => context) #++ def set(path, data, opts={}) h = { :path => path, :data => data }.merge(opts) - rv = check_rc(@cnx.set(h)) + rv = check_rc(@cnx.set(h), h) opts[:callback] ? nil : rv[:stat] end # Return the stat of the node of the given path. Return nil if the node @@ -434,11 +434,11 @@ case rv[:rc] when Zookeeper::ZOK, Zookeeper::ZNONODE rv[:stat] else - check_rc(rv) # throws the appropriate error + check_rc(rv, h) # throws the appropriate error end end # sugar around stat # @@ -512,11 +512,11 @@ # # zk.delete(/path", :callback => callback, :context => context) #++ def delete(path, opts={}) h = { :path => path, :version => -1 }.merge(opts) - rv = check_rc(@cnx.delete(h)) + rv = check_rc(@cnx.delete(h), h) nil end # Return the list of the children of the node of the given path. # @@ -569,11 +569,11 @@ def children(path, opts={}) h = { :path => path }.merge(opts) setup_watcher!(:child, h) - rv = check_rc(@cnx.get_children(h)) + rv = check_rc(@cnx.get_children(h), h) opts[:callback] ? nil : rv[:children] end # Return the ACL and stat of the node of the given path. # @@ -613,11 +613,11 @@ # context = Object.new # zk.acls("/path", :callback => callback, :context => context) #++ def get_acl(path, opts={}) h = { :path => path }.merge(opts) - rv = check_rc(@cnx.get_acl(h)) + rv = check_rc(@cnx.get_acl(h), h) opts[:callback] ? nil : rv.values_at(:children, :stat) end # Set the ACL for the node of the given path if such a node exists and the # given version matches the version of the node. Return the stat of the @@ -643,16 +643,14 @@ # ==== Examples # TBA - waiting on clarification of method use # def set_acl(path, acls, opts={}) h = { :path => path, :acl => acls }.merge(opts) - rv = check_rc(@cnx.set_acl(h)) + rv = check_rc(@cnx.set_acl(h), h) opts[:callback] ? nil : rv[:stat] end - - #-- # # EXTENSIONS # # convenience methods for dealing with zookeeper (rm -rf, mkdir -p, etc) @@ -703,10 +701,15 @@ rescue Exceptions::NoNode end end end + # see ZK::Find for explanation + def find(*paths, &block) + ZK::Find.find(self, *paths, &block) + end + # will block the caller until +abs_node_path+ has been removed # # NOTE: this is dangerous to use in callbacks! there is only one # event-delivery thread, so if you use this method in a callback or # watcher, you *will* deadlock! @@ -888,13 +891,14 @@ # gah, lame error parsing here raise e unless e.message == 'zookeeper handle is closed' false end - def check_rc(hash) + def check_rc(hash, inputs=nil) hash.tap do |h| if code = h[:rc] - raise Exceptions::KeeperException.by_code(code) unless code == Zookeeper::ZOK + msg = inputs ? "inputs: #{inputs.inspect}" : nil + raise Exceptions::KeeperException.by_code(code), msg unless code == Zookeeper::ZOK end end end def setup_watcher!(watch_type, opts)