Module: ZK::Client::Unixisms
- Includes:
- Exceptions, Zookeeper::Constants
- Included in:
- Threaded
- Defined in:
- lib/zk/client/unixisms.rb
Instance Method Summary collapse
-
#block_until_node_deleted(abs_node_path) ⇒ Object
Will safely block the caller until
abs_node_path
has been removed (this is trickier than it appears at first). -
#find(*paths, &block) ⇒ Object
Acts in a similar way to ruby's Find class.
-
#mkdir_p(path, opts = {}) ⇒ Object
Creates all parent paths and 'path' in zookeeper as persistent nodes with zero data.
-
#rm_rf(paths) ⇒ Object
recursively remove all children of path then remove path itself.
Instance Method Details
#block_until_node_deleted(abs_node_path) ⇒ Object
Will safely block the caller until abs_node_path
has been removed
(this is trickier than it appears at first). This method will wake the
caller if a session event occurs that would ensure the event would
never be delivered.
141 142 143 144 145 146 147 |
# File 'lib/zk/client/unixisms.rb', line 141 def block_until_node_deleted(abs_node_path) assert_we_are_not_on_the_event_dispatch_thread! raise ArgumentError, "argument must be String-ish, not: #{abs_node_path.inspect}" unless abs_node_path NodeDeletionWatcher.new(self, abs_node_path).block_until_deleted end |
#find(*paths, &block) ⇒ Object
Acts in a similar way to ruby's Find class. Performs a depth-first traversal of every node under the given paths, and calls the given block with each path found. Like the ruby Find class, you can call Find.prune to avoid descending further into a given sub-tree
115 116 117 |
# File 'lib/zk/client/unixisms.rb', line 115 def find(*paths, &block) ZK::Find.find(self, *paths, &block) end |
#mkdir_p(path, opts = {}) ⇒ Object
Creates all parent paths and 'path' in zookeeper as persistent nodes with zero data.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/zk/client/unixisms.rb', line 22 def mkdir_p(path, opts={}) data = '' # if we haven't recursed, or we recursed and now we're back at the top if !opts.has_key?(:orig_path) or (path == opts[:orig_path]) data = opts.fetch(:data, '') # only put the data at the leaf node end create(path, data, :mode => :persistent) rescue NodeExists if !opts.has_key?(:orig_path) or (path == opts[:orig_path]) # we're at the leaf node set(path, data) end return rescue NoNode if File.dirname(path) == '/' # ok, we're screwed, blow up raise NonExistentRootError, "could not create '/', are you chrooted into a non-existent path?", caller end opts[:orig_path] ||= path mkdir_p(File.dirname(path), opts) retry end |
#rm_rf(paths) ⇒ Object
recursively remove all children of path then remove path itself
50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/zk/client/unixisms.rb', line 50 def rm_rf(paths) Array(paths).flatten.each do |path| begin children(path).each do |child| rm_rf(File.join(path, child)) end delete(path) nil rescue NoNode end end end |