lib/z_k/event_handler.rb in zk-0.6.5 vs lib/z_k/event_handler.rb in zk-0.7.1

- old
+ new

@@ -41,11 +41,11 @@ # @return [ZooKeeper::EventHandlerSubscription] the subscription object # you can use to to unsubscribe from an event # @see ZooKeeper::WatcherEvent # @see ZooKeeper::EventHandlerSubscription def register(path, &block) - logger.debug { "EventHandler#register path=#{path.inspect}" } +# logger.debug { "EventHandler#register path=#{path.inspect}" } EventHandlerSubscription.new(self, path, block).tap do |subscription| synchronize { @callbacks[path] << subscription } end end alias :subscribe :register @@ -92,11 +92,11 @@ end alias :unsubscribe :unregister # called from the client-registered callback when an event fires def process(event) #:nodoc: - logger.debug { "EventHandler#process dispatching event: #{event.inspect}" } unless event.type == -1 +# logger.debug { "EventHandler#process dispatching event: #{event.inspect}" }# unless event.type == -1 event.zk = @zk cb_key = if event.node_event? event.path @@ -104,14 +104,16 @@ state_key(event.state) else raise ZKError, "don't know how to process event: #{event.inspect}" end +# logger.debug { "EventHandler#process: cb_key: #{cb_key}" } + cb_ary = synchronize do if event.node_event? if watch_type = ZOOKEEPER_WATCH_TYPE_MAP[event.type] - logger.debug { "re-allowing #{watch_type.inspect} watches on path #{event.path.inspect}" } +# logger.debug { "re-allowing #{watch_type.inspect} watches on path #{event.path.inspect}" } # we recieved a watch event for this path, now we allow code to set new watchers @outstanding_watches[watch_type].delete(event.path) end end @@ -159,11 +161,11 @@ if set.add?(path) # this path has no outstanding watchers, let it do its thing opts[:watcher] = watcher_callback else # outstanding watch for path and data pair already exists, so ignore - logger.debug { "outstanding watch request for path #{path.inspect} and watcher type #{watch_type.inspect}, not re-registering" } +# logger.debug { "outstanding watch request for path #{path.inspect} and watcher type #{watch_type.inspect}, not re-registering" } end end end protected @@ -186,10 +188,10 @@ rescue NameError raise ArgumentError, "#{arg} is not a valid zookeeper state", caller end def safe_call(callbacks, *args) - callbacks.each do |cb| + while cb = callbacks.shift begin cb.call(*args) if cb.respond_to?(:call) rescue Exception => e logger.error { "Error caught in user supplied callback" } logger.error { e.to_std_format }