Class: DCell::Registry::ZkPresenceAdapter::GlobalRegistry
- Inherits:
-
Object
- Object
- DCell::Registry::ZkPresenceAdapter::GlobalRegistry
- Defined in:
- lib/dcell/registries/zk_presence_adapter.rb
Constant Summary collapse
- PREFIX =
"/dcell_global"
Instance Method Summary collapse
- #clear ⇒ Object
- #get(key) ⇒ Object
-
#global_keys ⇒ Object
The keys to all globals in the system.
-
#initialize(service_name, options) ⇒ GlobalRegistry
constructor
A new instance of GlobalRegistry.
-
#set(key, value) ⇒ Object
Set a global value.
Constructor Details
#initialize(service_name, options) ⇒ GlobalRegistry
Returns a new instance of GlobalRegistry.
106 107 108 109 110 111 112 |
# File 'lib/dcell/registries/zk_presence_adapter.rb', line 106 def initialize(service_name, ) = .inject({}) { |h,(k,v)| h[k.to_s] = v; h } @service_name = service_name @env = ['env'] || 'production' @base_path = "#{PREFIX}/#{@env}" end |
Instance Method Details
#clear ⇒ Object
135 136 137 138 |
# File 'lib/dcell/registries/zk_presence_adapter.rb', line 135 def clear zk.rm_rf @base_path zk.mkdir_p @base_path end |
#get(key) ⇒ Object
114 115 116 117 118 |
# File 'lib/dcell/registries/zk_presence_adapter.rb', line 114 def get(key) value, _ = zk.get "#{@base_path}/#{key}" Marshal.load value rescue ZK::Exceptions::NoNode end |
#global_keys ⇒ Object
The keys to all globals in the system
131 132 133 |
# File 'lib/dcell/registries/zk_presence_adapter.rb', line 131 def global_keys zk.children(@base_path) end |
#set(key, value) ⇒ Object
Set a global value
121 122 123 124 125 126 127 128 |
# File 'lib/dcell/registries/zk_presence_adapter.rb', line 121 def set(key, value) path = "#{@base_path}/#{key}" string = Marshal.dump value zk.set path, string rescue ZK::Exceptions::NoNode zk.create path, string end |