presence

package
v0.0.0-...-a7271ac Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 4, 2014 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Overview

The presence package implements an interface for observing liveness of arbitrary keys (agents, processes, etc) on top of MongoDB. The design works by periodically updating the database so that watchers can tell an arbitrary key is alive.

Index

Constants

This section is empty.

Variables

View Source
var Debug = false

Debug specifies whether the package will log debug messages. TODO(rog) allow debug level setting in the log package.

Functions

This section is empty.

Types

type Change

type Change struct {
	Key   string
	Alive bool
}

Change holds a liveness change notification.

type Pinger

type Pinger struct {
	// contains filtered or unexported fields
}

Pinger periodically reports that a specific key is alive, so that watchers interested on that fact can react appropriately.

func NewPinger

func NewPinger(base *mgo.Collection, key string) *Pinger

NewPinger returns a new Pinger to report that key is alive. It starts reporting after Start is called.

func (*Pinger) Kill

func (p *Pinger) Kill() error

Stop stops p's periodical ping and immediately report that it is dead.

func (*Pinger) Start

func (p *Pinger) Start() error

Start starts periodically reporting that p's key is alive.

func (*Pinger) Stop

func (p *Pinger) Stop() error

Stop stops p's periodical ping. Watchers will not notice p has stopped pinging until the previous ping times out.

type Watcher

type Watcher struct {
	// contains filtered or unexported fields
}

A Watcher can watch any number of pinger keys for liveness changes.

func NewWatcher

func NewWatcher(base *mgo.Collection) *Watcher

NewWatcher returns a new Watcher.

func (*Watcher) Alive

func (w *Watcher) Alive(key string) (bool, error)

Alive returns whether the key is currently considered alive by w, or an error in case the watcher is dying.

func (*Watcher) Dead

func (w *Watcher) Dead() <-chan struct{}

Dead returns a channel that is closed when the watcher has stopped.

func (*Watcher) Err

func (w *Watcher) Err() error

Err returns the error with which the watcher stopped. It returns nil if the watcher stopped cleanly, tomb.ErrStillAlive if the watcher is still running properly, or the respective error if the watcher is terminating or has terminated with an error.

func (*Watcher) StartSync

func (w *Watcher) StartSync()

StartSync forces the watcher to load new events from the database.

func (*Watcher) Stop

func (w *Watcher) Stop() error

Stop stops all the watcher activities.

func (*Watcher) Sync

func (w *Watcher) Sync()

Sync forces the watcher to load new events from the database and blocks until all events have been dispatched.

func (*Watcher) Unwatch

func (w *Watcher) Unwatch(key string, ch chan<- Change)

Unwatch stops watching the liveness of key via ch.

func (*Watcher) Watch

func (w *Watcher) Watch(key string, ch chan<- Change)

Watch starts watching the liveness of key. An event will be sent onto ch to report the initial status for the key, and from then on a new event will be sent whenever a change is detected. Change values sent to the channel must be consumed, or the whole watcher will blocked.

Notes

Bugs

  • The pings and beings collection currently grow without bound.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL