Module: ZK::Client::StateMixin

Included in:
Threaded
Defined in:
lib/zk/client/state_mixin.rb

Overview

Provides client-state related methods. Included in ZK::Client::Base. (refactored out to this class to ease documentation overload)

Instance Method Summary collapse

Instance Method Details

#on_connected(&block) ⇒ Object

Register a block to be called on connection, when the client has connected.

the block will be called with no arguments

returns an EventHandlerSubscription object that can be used to unregister this block from further updates


22
23
24
# File 'lib/zk/client/state_mixin.rb', line 22

def on_connected(&block)
  watcher.register_state_handler(:connected, &block)
end

#on_connecting(&block) ⇒ Object

register a block to be called when the client is attempting to reconnect to the zookeeper server. the documentation says that this state should be taken to mean that the application should enter into "safe mode" and operate conservatively, as it won't be getting updates until it has reconnected


31
32
33
# File 'lib/zk/client/state_mixin.rb', line 31

def on_connecting(&block)
  watcher.register_state_handler(:connecting, &block)
end

#on_expired_session(&block) ⇒ Object

TODO:

need to come up with a way to test this

register a block to be called when our session has expired. This usually happens due to a network partitioning event, and means that all watches must be re-registered with the server (i.e. after the on_connected event is received). Callbacks set up via #register are still valid and will respond to events, it's the event delivery you have to set up again by using :watch.


43
44
45
# File 'lib/zk/client/state_mixin.rb', line 43

def on_expired_session(&block)
  watcher.register_state_handler(:expired_session, &block)
end

#on_state_change {|event| ... } ⇒ Object

Register a block to be called when any connection event occurs

Yields:

  • (event)

    yields the connection event to the block

Yield Parameters:

  • event (ZK::Event)

    the event that occurred


10
11
12
# File 'lib/zk/client/state_mixin.rb', line 10

def on_state_change(&block)
  watcher.register_state_handler(:all, &block)
end