NAME

ZooKeeper::Dispatcher

DESCRIPTION

A parent class for event dispatchers to inherit from. Dispatchers directly handle callbacks for ZooKeeper the 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.

ignore_session_events

Controls whether watchers should be triggered for session events.

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.

trigger_event

Manually trigger an event on a ZooKeeper::Watch.

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