Class: DCell::Registry::ZkAdapter::NodeRegistry
- Inherits:
-
Object
- Object
- DCell::Registry::ZkAdapter::NodeRegistry
- Defined in:
- lib/dcell/registries/zk_adapter.rb
Instance Method Summary collapse
- #clear ⇒ Object
- #get(node_id) ⇒ Object
-
#initialize(zk, base_path) ⇒ NodeRegistry
constructor
A new instance of NodeRegistry.
- #nodes ⇒ Object
- #set(node_id, addr) ⇒ Object
Constructor Details
#initialize(zk, base_path) ⇒ NodeRegistry
Returns a new instance of NodeRegistry.
52 53 54 55 |
# File 'lib/dcell/registries/zk_adapter.rb', line 52 def initialize(zk, base_path) @zk, @base_path = zk, "#{base_path}/nodes" @zk.mkdir_p @base_path end |
Instance Method Details
#clear ⇒ Object
74 75 76 77 |
# File 'lib/dcell/registries/zk_adapter.rb', line 74 def clear @zk.rm_rf @base_path @zk.mkdir_p @base_path end |
#get(node_id) ⇒ Object
57 58 59 60 61 |
# File 'lib/dcell/registries/zk_adapter.rb', line 57 def get(node_id) result, _ = @zk.get("#{@base_path}/#{node_id}") result rescue ZK::Exceptions::NoNode end |
#nodes ⇒ Object
70 71 72 |
# File 'lib/dcell/registries/zk_adapter.rb', line 70 def nodes @zk.children @base_path end |
#set(node_id, addr) ⇒ Object
63 64 65 66 67 68 |
# File 'lib/dcell/registries/zk_adapter.rb', line 63 def set(node_id, addr) path = "#{@base_path}/#{node_id}" @zk.set path, addr rescue ZK::Exceptions::NoNode @zk.create path, addr end |