Class: ZooKeeper::EventHandler
- Inherits:
-
Object
- Object
- ZooKeeper::EventHandler
- Defined in:
- lib/zookeeper/event_handler.rb
Overview
this is the default watcher provided by the zookeeper connection and is used to monitor all watch events on any paths watchers are implemented by adding the :watch => true flag to any #children or #get or #exists calls you never really need to initialize this yourself
Instance Attribute Summary (collapse)
-
- (Object) zk
:nodoc:.
Instance Method Summary (collapse)
-
- (EventHandler) initialize(zookeeper_client)
constructor
:nodoc:.
-
- (Object) process(event)
:nodoc:.
-
- (ZooKeeper::EventHandlerSubscription) register(path, &block) {|connection, event| ... }
(also: #subscribe)
register a path with the handler your block will be called with all events on that path.
-
- (Object) register_state_handler(state, &block) {|connection, event| ... }
registers a "state of the connection" handler.
-
- (Object) unregister(*args)
(also: #unsubscribe)
deprecated
Deprecated.
use #unsubscribe on the subscription object
-
- (Object) unregister_state_handler(*args)
deprecated
Deprecated.
use #unsubscribe on the subscription object
Constructor Details
- (EventHandler) initialize(zookeeper_client)
:nodoc:
16 17 18 19 |
# File 'lib/zookeeper/event_handler.rb', line 16 def initialize(zookeeper_client) @zk = zookeeper_client @callbacks = Hash.new { |h,k| h[k] = [] } end |
Instance Attribute Details
- (Object) zk
:nodoc:
12 13 14 |
# File 'lib/zookeeper/event_handler.rb', line 12 def zk @zk end |
Instance Method Details
- (Object) process(event)
:nodoc:
79 80 81 |
# File 'lib/zookeeper/event_handler.rb', line 79 def process(event) handle_process(event) end |
- (ZooKeeper::EventHandlerSubscription) register(path, &block) {|connection, event| ... } Also known as: subscribe
register a path with the handler your block will be called with all events on that path. aliased as #subscribe
32 33 34 35 36 |
# File 'lib/zookeeper/event_handler.rb', line 32 def register(path, &block) EventHandlerSubscription.new(self, path, block).tap do |subscription| @callbacks[path] << subscription end end |
- (Object) register_state_handler(state, &block) {|connection, event| ... }
registers a "state of the connection" handler
43 44 45 |
# File 'lib/zookeeper/event_handler.rb', line 43 def register_state_handler(state, &block) register("state_#{state}", &block) end |
- (Object) unregister(*args) Also known as: unsubscribe
use #unsubscribe on the subscription object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/zookeeper/event_handler.rb', line 59 def unregister(*args) if args.first.is_a?(EventHandlerSubscription) subscription = args.first elsif args.first.is_a?(String) and args[1].is_a?(EventHandlerSubscription) subscription = args[1] else path, index = args[0..1] @callbacks[path][index] = nil return end ary = @callbacks[subscription.path] if index = ary.index(subscription) ary[index] = nil end end |
- (Object) unregister_state_handler(*args)
use #unsubscribe on the subscription object
49 50 51 52 53 54 55 |
# File 'lib/zookeeper/event_handler.rb', line 49 def unregister_state_handler(*args) if args.first.is_a?(EventHandlerSubscription) unregister(args.first) else unregister("state_#{args.first}", args[1]) end end |