lib/dcell/registries/zk_adapter.rb in dcell-0.9.0 vs lib/dcell/registries/zk_adapter.rb in dcell-0.10.0
- old
+ new
@@ -34,55 +34,17 @@
"#{server}:#{DEFAULT_PORT}"
end
end
@zk = ZK.new(*servers)
- @node_registry = NodeRegistry.new(@zk, @base_path)
@global_registry = GlobalRegistry.new(@zk, @base_path)
end
- def clear_nodes
- @node_registry.clear
- end
-
def clear_globals
@global_registry.clear
end
- class NodeRegistry
- def initialize(zk, base_path)
- @zk, @base_path = zk, "#{base_path}/nodes"
- @zk.mkdir_p @base_path
- end
-
- def get(node_id)
- result, _ = @zk.get("#{@base_path}/#{node_id}")
- result
- rescue ZK::Exceptions::NoNode
- end
-
- def set(node_id, addr)
- path = "#{@base_path}/#{node_id}"
- @zk.set path, addr
- rescue ZK::Exceptions::NoNode
- @zk.create path, addr
- end
-
- def nodes
- @zk.children @base_path
- end
-
- def clear
- @zk.rm_rf @base_path
- @zk.mkdir_p @base_path
- end
- end
-
- def get_node(node_id); @node_registry.get(node_id) end
- def set_node(node_id, addr); @node_registry.set(node_id, addr) end
- def nodes; @node_registry.nodes end
-
class GlobalRegistry
def initialize(zk, base_path)
@zk, @base_path = zk, "#{base_path}/globals"
@zk.mkdir_p @base_path
end
@@ -117,6 +79,6 @@
def get_global(key); @global_registry.get(key) end
def set_global(key, value); @global_registry.set(key, value) end
def global_keys; @global_registry.global_keys end
end
end
-end
\ No newline at end of file
+end