Class: DCell::Registry::ZkPresenceAdapter::GlobalRegistry

Inherits:
Object
  • Object
show all
Defined in:
lib/dcell/registries/zk_presence_adapter.rb

Constant Summary collapse

PREFIX =
"/dcell_global"

Instance Method Summary collapse

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, options)
	options = options.inject({}) { |h,(k,v)| h[k.to_s] = v; h }
	
	@service_name = service_name
	@env = options['env'] || 'production'
	@base_path = "#{PREFIX}/#{@env}"
end

Instance Method Details

#clearObject



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_keysObject

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