presence

package
v0.0.0-...-f19ae85 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2015 License: AGPL-3.0 Imports: 10 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

This section is empty.

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, envTag names.EnvironTag, 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

Kill stops p's periodical ping and immediately reports 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 Presencer

type Presencer interface {
	AgentPresence() (bool, error)
	SetAgentPresence() (*Pinger, error)
	WaitAgentPresence(time.Duration) error
}

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, envTag names.EnvironTag) *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