Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrLockFound = errors.New("lock found") ErrNotLocked = errors.New("not locked") )
Functions ¶
Types ¶
type Lock ¶
func (*Lock) Lock ¶
Lock implements a distributed lock on zookeeper where only one instance will be able to proceed while the rest of them will wait.
func (*Lock) TryLock ¶
TryLock will attempt to acquire the lock only if it is free at the time of invocation. If it's free it will return nil, if not it will return the error recipes.ErrLockFound unless any other error is found.
func (*Lock) WithCleaner ¶
WithCleaner adds a cleaner to the lock, this will remove all the files in the Lock.Path older than t.
WithCleaner is used to support special cases where we want to execute the code protected by one path twice when the user holding the lock does not unlock it in less than t. The initial user holding the lock will know that his lock was removed because the Unlock will return the zk.ErrNoNode error.
type PathWatcher ¶
type PathWatcher struct { Path string // contains filtered or unexported fields }
PathWatcher is a recipe that watches for child events in a ZNode. It will trigger an event when a child is created or deleted.
Usage:
client := ezk.NewClient(ezk.ClientConfig{}) watcher := recipes.NewPathWatcher(client, "/") watcher.Start() go func() { for { select { case e, ok := <-watcher.Event(): if !ok { return } if e.Type == zk.EventNodeChildrenChanged { // do something } case err := <-watcher.Error(): // do something } } }() ... // Stop the watcher watcher.Stop()
func NewPathWatcher ¶
func NewPathWatcher(client *ezk.Client, path string) *PathWatcher
NewPathWatcher creates a new PathWatcher on the passed path.
func (*PathWatcher) Error ¶
func (p *PathWatcher) Error() <-chan error
Error is the channel used to listen for errors.
func (*PathWatcher) Event ¶
func (p *PathWatcher) Event() <-chan zk.Event
Event returns the channel used to listen for child events.
func (*PathWatcher) Start ¶
func (p *PathWatcher) Start()
Start starts PathWatcher. It will send the events to event channel and the errors to th error channel.
func (*PathWatcher) Stop ¶
func (p *PathWatcher) Stop()
Stop stops the watcher. Stop will close the event channel and return once the watcher finishes.