Class: Zoology::Client
Instance Method Summary
collapse
Methods included from Callbacks
#call
Methods included from Logging
disable!, #logger, logger
Constructor Details
#initialize(servers = 'localhost:2181', opts = {}, klass = Zookeeper) ⇒ Client
Returns a new instance of Client.
8
9
10
11
12
13
14
|
# File 'lib/zoology/client.rb', line 8
def initialize(servers = 'localhost:2181', opts = {}, klass = Zookeeper)
@servers = servers
@heartbeat = opts[:heartbeat] || 2000
@klass = klass
callbacks :on_connected, :on_expired, :on_disconnected
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *args, &blk) ⇒ Object
43
44
45
46
|
# File 'lib/zoology/client.rb', line 43
def method_missing(sym, *args, &blk)
logger.debug "Call to zookeeper #{sym}: #{args.map(&:to_s).join(',')}"
@zookeeper.send(sym, *args, &blk)
end
|
Instance Method Details
#connect ⇒ Object
16
17
18
19
|
# File 'lib/zoology/client.rb', line 16
def connect
logger.debug 'Connect to ZK'
@zookeeper = @klass.new(@servers, @heartbeat, method(:watcher))
end
|
#connected? ⇒ Boolean
26
27
28
29
30
31
32
|
# File 'lib/zoology/client.rb', line 26
def connected?
if @zookeeper
@zookeeper.connected?
else
false
end
end
|
#reopen ⇒ Object
21
22
23
24
|
# File 'lib/zoology/client.rb', line 21
def reopen
logger.debug 'reopen it'
@zookeeper.reopen
end
|
#watcher_callback(&blk) ⇒ Object
48
49
50
|
# File 'lib/zoology/client.rb', line 48
def watcher_callback(&blk)
Zookeeper::Callbacks::WatcherCallback.create(&blk)
end
|
#when_path(path, &blk) ⇒ Object
34
35
36
37
38
39
40
41
|
# File 'lib/zoology/client.rb', line 34
def when_path(path, &blk)
req = @zookeeper.get(:path => path)
if req[:rc] == ::Zookeeper::ZOK
blk.call
else
wait_for_path(path, path, [], &blk)
end
end
|