watcher

package
v0.0.0-...-6cf1bc9 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2016 License: AGPL-3.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CoreWatcher

type CoreWatcher interface {
	worker.Worker
}

CoreWatcher encodes some features of a watcher. The most obvious one:

Changes() <-chan <T>

...can't be expressed cleanly; and this is annoying because every such chan needs to share common behaviours for the abstraction to be generally helpful. The critical features of a Changes chan are as follows:

  • The channel should never be closed.
  • The channel should send a single baseline value, representing the change from a nil state; and subsequently send values representing deltas from whatever had previously been sent.
  • The channel should really never be closed. Many existing watchers *do* close their channels when the watcher stops; this is harmful because it mixes lifetime-handling into change-handling at the cost of clarity (and in some cases correctness). So long as a watcher implements Worker, it can be safely managed with the worker/catacomb package; of course, all sensible clients will still check for closed channels (never trust a contract...) but can treat that scenario as a simple error.

To convert a state/watcher.Watcher to a CoreWatcher, ensure that the watcher no longer closes its Changes() channel; and replace Stop() and Err() with the usual worker boilerplate. Namely:

// Kill is part of the worker.Worker interface.
func (w *watcher) Kill() {
    w.tomb.Kill(nil)
}

// Wait is part of the worker.Worker interface.
func (w *watcher) Wait() error {
    return w.tomb.Wait()
}

Tests using state/testing/{$Kind}WatcherC should be converted to use the equivalents in watcher/watchertest.

type EntitiesWatcher

type EntitiesWatcher interface {
	CoreWatcher
	Changes() StringsChannel
}

EntitiesWatcher conveniently ties an StringsChannel to the worker.Worker that represents its validity.

It purports to deliver strings that can be parsed as tags, but since it doesn't actually produce tags today we may as well make it compatible with StringsWatcher so we can use it with a StringsHandler. In an ideal world we'd have something like `type EntitiesChannel <-chan []names.Tag` instead.

type MachineStorageId

type MachineStorageId struct {
	MachineTag    string
	AttachmentTag string
}

MachineStorageId associates a machine entity with a storage entity. They're expressed as tags because they arrived here as a move, not a change; ideally a MachineStorageIdsWatcher would return them in a more model-appropriate format (i.e. not as strings-that-probably-parse-to-tags).

type MachineStorageIdsChannel

type MachineStorageIdsChannel <-chan []MachineStorageId

MachineStorageIdsChannel is a change channel as described in the CoreWatcher docs.

It reports additions and removals to a set of attachments; and lifecycle changes within the active set.

type MachineStorageIdsWatcher

type MachineStorageIdsWatcher interface {
	CoreWatcher
	Changes() MachineStorageIdsChannel
}

MachineStorageIdsWatcher conveniently ties a MachineStorageIdsChannel to the worker.Worker that represents its validity.

type MigrationStatus

type MigrationStatus struct {
	MigrationId    string
	Attempt        int
	Phase          migration.Phase
	SourceAPIAddrs []string
	SourceCACert   string
	TargetAPIAddrs []string
	TargetCACert   string
}

MigrationStatus is the client side version of params.MigrationStatus.

type MigrationStatusWatcher

type MigrationStatusWatcher interface {
	CoreWatcher
	Changes() <-chan MigrationStatus
}

MigrationStatusWatcher describes a watcher that reports the latest status of a migration for a model.

type NotifyChannel

type NotifyChannel <-chan struct{}

NotifyChannel is a change channel as described in the CoreWatcher docs.

It sends a single value to indicate that the watch is active, and subsequent values whenever the value(s) under observation change(s).

type NotifyConfig

type NotifyConfig struct {
	Handler NotifyHandler
}

NotifyConfig holds the direct dependencies of a NotifyWorker.

func (NotifyConfig) Validate

func (config NotifyConfig) Validate() error

Validate returns an error if the config cannot start a NotifyWorker.

type NotifyHandler

type NotifyHandler interface {

	// SetUp is called once when creating a NotifyWorker. It must return a
	// NotifyWatcher or an error. The NotifyHandler takes responsibility for
	// stopping any returned watcher and handling any errors.
	SetUp() (NotifyWatcher, error)

	// Handle is called whenever a value is received from the NotifyWatcher
	// returned by SetUp. If it returns an error, the NotifyWorker will be
	// stopped.
	//
	// If Handle runs any blocking operations it must pass through, or select
	// on, the supplied abort channel; this channnel will be closed when the
	// NotifyWorker is killed. An aborted Handle should not return an error.
	Handle(abort <-chan struct{}) error

	// TearDown is called once when stopping a NotifyWorker, whether or not
	// SetUp succeeded. It need not concern itself with the NotifyWatcher, but
	// must clean up any other resources created in SetUp or Handle.
	TearDown() error
}

NotifyHandler defines the operation of a NotifyWorker.

type NotifyWatcher

type NotifyWatcher interface {
	CoreWatcher
	Changes() NotifyChannel
}

NotifyWatcher conveniently ties a NotifyChannel to the worker.Worker that represents its validity.

type NotifyWorker

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

NotifyWorker is a worker that wraps a NotifyWatcher.

func NewNotifyWorker

func NewNotifyWorker(config NotifyConfig) (*NotifyWorker, error)

NewNotifyWorker starts a new worker that runs a NotifyHandler.

func (*NotifyWorker) Kill

func (nw *NotifyWorker) Kill()

Kill is part of the worker.Worker interface.

func (*NotifyWorker) Wait

func (nw *NotifyWorker) Wait() error

Wait is part of the worker.Worker interface.

type RelationUnitsChange

type RelationUnitsChange struct {

	// Changed holds a set of units that are known to be in scope, and the
	// latest known settings version for each.
	Changed map[string]UnitSettings

	// Departed holds a set of units that have previously been reported to
	// be in scope, but which no longer are.
	Departed []string
}

RelationUnitsChange describes the membership and settings of; or changes to; some relation scope.

type RelationUnitsChannel

type RelationUnitsChannel <-chan RelationUnitsChange

RelationUnitsChannel is a change channel as described in the CoreWatcher docs.

It sends a single value representing the current membership of a relation scope; and the versions of the settings documents for each; and subsequent values representing entry, settings-change, and departure for units in that scope.

It feeds the joined-changed-departed logic in worker/uniter, but these events do not map 1:1 with hooks.

type RelationUnitsWatcher

type RelationUnitsWatcher interface {
	CoreWatcher
	Changes() RelationUnitsChannel
}

RelationUnitsWatcher conveniently ties a RelationUnitsChannel to the worker.Worker that represents its validity.

type StringsChannel

type StringsChannel <-chan []string

StringsChannel is a change channel as described in the CoreWatcher docs.

It sends a single value indicating a baseline set of values, and subsequent values representing additions, changes, and/or removals of those values. The precise semantics may depend upon the individual watcher.

type StringsConfig

type StringsConfig struct {
	Handler StringsHandler
}

StringsConfig holds the direct dependencies of a StringsWorker.

func (StringsConfig) Validate

func (config StringsConfig) Validate() error

Validate returns ann error if the config cannot start a StringsWorker.

type StringsHandler

type StringsHandler interface {

	// SetUp is called once when creating a StringsWorker. It must return a
	// StringsWatcher or an error. The StringsHandler takes responsibility for
	// stopping any returned watcher and handling any errors.
	SetUp() (StringsWatcher, error)

	// Handle is called with every value received from the StringsWatcher
	// returned by SetUp. If it returns an error, the StringsWorker will be
	// stopped.
	//
	// If Handle runs any blocking operations it must pass through, or select
	// on, the supplied abort channel; this channel will be closed when the
	// StringsWorker is killed. An aborted Handle should not return an error.
	Handle(abort <-chan struct{}, changes []string) error

	// TearDown is called once when stopping a StringsWorker, whether or not
	// SetUp succeeded. It need not concern itself with the StringsWatcher, but
	// must clean up any other resources created in SetUp or Handle.
	TearDown() error
}

StringsHandler defines the operation of a StringsWorker.

type StringsWatcher

type StringsWatcher interface {
	CoreWatcher
	Changes() StringsChannel
}

StringsWatcher conveniently ties a StringsChannel to the worker.Worker that represents its validity.

type StringsWorker

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

StringsWorker is a worker that wraps a StringsWatcher.

func NewStringsWorker

func NewStringsWorker(config StringsConfig) (*StringsWorker, error)

NewStringsWorker starts a new worker that runs a StringsHandler.

func (*StringsWorker) Kill

func (sw *StringsWorker) Kill()

Kill is part of the worker.Worker interface.

func (*StringsWorker) Wait

func (sw *StringsWorker) Wait() error

Wait is part of the worker.Worker interface.

type UnitSettings

type UnitSettings struct {
	Version int64
}

UnitSettings specifies the version of some unit's settings in some relation.

Directories

Path Synopsis
Package legacy contains state-watcher-tuned worker harnesses; the canonical implementations are in the watcher package, but aren't type-compatible with original-style watchers -- such as those returned from state methods -- which we still have a couple of uses for (and the certupdater use might even be legitimate).
Package legacy contains state-watcher-tuned worker harnesses; the canonical implementations are in the watcher package, but aren't type-compatible with original-style watchers -- such as those returned from state methods -- which we still have a couple of uses for (and the certupdater use might even be legitimate).

Jump to

Keyboard shortcuts

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