juju: github.com/juju/juju/core/watcher Index | Files | Directories

package watcher

import "github.com/juju/juju/core/watcher"

Index

Package Files

entities.go interface.go machinestorageids.go migrationstatus.go multinotify.go notify.go offerstatus.go relationstatus.go relationunits.go strings.go

type CoreWatcher Uses

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 Uses

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 Uses

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 Uses

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 Uses

type MachineStorageIdsWatcher interface {
    CoreWatcher
    Changes() MachineStorageIdsChannel
}

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

type MigrationStatus Uses

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 Uses

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

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

type MultiNotifyWatcher Uses

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

MultiNotifyWatcher implements NotifyWatcher, combining multiple NotifyWatchers.

func NewMultiNotifyWatcher Uses

func NewMultiNotifyWatcher(w ...NotifyWatcher) *MultiNotifyWatcher

NewMultiNotifyWatcher creates a NotifyWatcher that combines each of the NotifyWatchers passed in. Each watcher's initial event is consumed, and a single initial event is sent. Subsequent events are not coalesced.

func (*MultiNotifyWatcher) Changes Uses

func (w *MultiNotifyWatcher) Changes() NotifyChannel

func (*MultiNotifyWatcher) Err Uses

func (w *MultiNotifyWatcher) Err() error

func (*MultiNotifyWatcher) Kill Uses

func (w *MultiNotifyWatcher) Kill()

func (*MultiNotifyWatcher) Stop Uses

func (w *MultiNotifyWatcher) Stop() error

func (*MultiNotifyWatcher) Wait Uses

func (w *MultiNotifyWatcher) Wait() error

type NotifyChannel Uses

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 Uses

type NotifyConfig struct {
    Handler NotifyHandler
}

NotifyConfig holds the direct dependencies of a NotifyWorker.

func (NotifyConfig) Validate Uses

func (config NotifyConfig) Validate() error

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

type NotifyHandler Uses

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 channel 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 Uses

type NotifyWatcher interface {
    CoreWatcher
    Changes() NotifyChannel
}

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

type NotifyWorker Uses

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

NotifyWorker is a worker that wraps a NotifyWatcher.

func NewNotifyWorker Uses

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

NewNotifyWorker starts a new worker that runs a NotifyHandler.

func (*NotifyWorker) Kill Uses

func (nw *NotifyWorker) Kill()

Kill is part of the worker.Worker interface.

func (*NotifyWorker) Report Uses

func (nw *NotifyWorker) Report() map[string]interface{}

Report implements dependency.Reporter.

func (*NotifyWorker) Wait Uses

func (nw *NotifyWorker) Wait() error

Wait is part of the worker.Worker interface.

type OfferStatusChange Uses

type OfferStatusChange struct {
    // Name is the name of the offer.
    Name string

    // Status is the status of the offer.
    Status status.StatusInfo
}

OfferStatusChange describes changes to some offer.

type OfferStatusChannel Uses

type OfferStatusChannel <-chan []OfferStatusChange

OfferStatusChannel is a channel used to notify of changes to an offer's status.

type OfferStatusWatcher Uses

type OfferStatusWatcher interface {
    CoreWatcher
    Changes() OfferStatusChannel
}

OfferStatusWatcher conveniently ties an OfferStatusChannel to the worker.Worker that represents its validity.

type RelationStatusChange Uses

type RelationStatusChange struct {
    // Key is the relation key of the changed relation.
    Key string

    // Suspended is the suspended status of the relation.
    Suspended bool

    // SuspendedReason is an optional message to explain why suspend is true.
    SuspendedReason string

    // Life is the relation life value, eg Alive.
    Life life.Value
}

RelationStatusChange describes changes to some relation.

type RelationStatusChannel Uses

type RelationStatusChannel <-chan []RelationStatusChange

RelationStatusChannel is a channel used to notify of changes to a relation's life or suspended status.

type RelationStatusWatcher Uses

type RelationStatusWatcher interface {
    CoreWatcher
    Changes() RelationStatusChannel
}

RelationStatusWatcher conveniently ties a RelationStatusChannel to the worker.Worker that represents its validity.

type RelationUnitsChange Uses

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 Uses

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 Uses

type RelationUnitsWatcher interface {
    CoreWatcher
    Changes() RelationUnitsChannel
}

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

type StringsChannel Uses

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 Uses

type StringsConfig struct {
    Handler StringsHandler
}

StringsConfig holds the direct dependencies of a StringsWorker.

func (StringsConfig) Validate Uses

func (config StringsConfig) Validate() error

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

type StringsHandler Uses

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 Uses

type StringsWatcher interface {
    CoreWatcher
    Changes() StringsChannel
}

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

type StringsWorker Uses

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

StringsWorker is a worker that wraps a StringsWatcher.

func NewStringsWorker Uses

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

NewStringsWorker starts a new worker that runs a StringsHandler.

func (*StringsWorker) Kill Uses

func (sw *StringsWorker) Kill()

Kill is part of the worker.Worker interface.

func (*StringsWorker) Wait Uses

func (sw *StringsWorker) Wait() error

Wait is part of the worker.Worker interface.

type UnitSettings Uses

type UnitSettings struct {
    Version int64
}

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

Directories

PathSynopsis
watchertest

Package watcher imports 9 packages (graph) and is imported by 277 packages. Updated 2019-10-22. Refresh now. Tools for package owners.