NAME

ZooKeeper::Dispatcher

DESCRIPTION

A parent class for event dispatchers to inherit from. Dispatchers directly handle callbacks for ZooKeeper C library, and manage the lifecycle of ZooKeeper::Watcher's.

ATTRIBUTES

channel

A ZooKeeper::Channel, used for sending event data from ZooKeeper C callbacks to perl.

watchers

A hashref of all live watchers.

dispatch_cb

The perl subroutine reference to be invoked whenever the dispatcher is notified of an event. Usually just calls dispatch_event.

METHODS

recv_event

Receive event data from the channel. Returns undef if no event data is available.

create_watcher

Create a new ZooKeeper::Watcher. This is the preferred way to instantiate watchers.

my $watcher = $dispatcher->create_watcher($path, $cb, %args);

    REQUIRED $path - The path of the node to register the watcher on
    REQUIRED $cb   - A perl subroutine reference to be invoked with event data

    %args
        REQUIRED type - The type of event the watcher is for(e.g get_children, exists)

dispatch_event

Read an event from the channel, and execute the corresponding watcher callback.

wait

Synchronously dispatch one event. Returns the event hashref the watcher was called with. Can optionally be passed a timeout(specified in seconds), which will cause wait to return undef if it does not complete in the specified time.

my $event = $zk->wait($seconds)

OPTIONAL $seconds