1
// Copyright 2016 Canonical Ltd.
2
// Licensed under the AGPLv3, see LICENCE file for details.
7
"github.com/juju/juju/core/lease"
8
"github.com/juju/juju/state/presence"
9
"github.com/juju/juju/state/watcher"
10
"github.com/juju/juju/worker"
13
// Workers doesn't really need to exist -- it could basically just exist
14
// in the state package -- but that'd entail duplication of the
15
// TxnLogWatcher, PresenceWatcher, and LeaseManager interfaces in both
16
// packages to avoid import cycles, and, yuck.
18
// See the DumbWorkers and RestartWorkers types for implementations.
19
type Workers interface {
22
TxnLogWatcher() TxnLogWatcher
23
PresenceWatcher() PresenceWatcher
24
LeadershipManager() LeaseManager
25
SingularManager() LeaseManager
28
// Factory supplies implementations of various workers used in state,
29
// and is generally a critical dependency of a Workers implementation
30
// such as DumbWorkers or RestartWorkers.
32
// It'll generally just be a thin wrapper over a *State -- this package
33
// exists only to paper over worker-lifetime issues that are hard to
34
// address in the state package, not really to pave the way to alternate
35
// backends or anything.
36
type Factory interface {
37
NewTxnLogWorker() (TxnLogWorker, error)
38
NewPresenceWorker() (PresenceWorker, error)
39
NewLeadershipWorker() (LeaseWorker, error)
40
NewSingularWorker() (LeaseWorker, error)
43
// ExposedFailer encapsulates methods for shutdown detection and
44
// handling, used widely inside state watcher types.
46
// Would be lovely to remove this dependency -- by adding new watchers
47
// to something that tracked watcher and/or state validity, and stopped
48
// them automatically -- but that's likely to have impacts reverberating
49
// through state and apiserver and deserves its own careful analysis.
50
type ExposedFailer interface {
51
Dead() <-chan struct{}
55
// TxnLogWatcher exposes the methods of watcher.Watcher that are needed
56
// by the state package.
57
type TxnLogWatcher interface {
60
// horrible hack for goosing it into activity (for tests).
63
// single-document watching
64
Watch(coll string, id interface{}, revno int64, ch chan<- watcher.Change)
65
Unwatch(coll string, id interface{}, ch chan<- watcher.Change)
67
// collection-watching
68
WatchCollection(coll string, ch chan<- watcher.Change)
69
WatchCollectionWithFilter(coll string, ch chan<- watcher.Change, filter func(interface{}) bool)
70
UnwatchCollection(coll string, ch chan<- watcher.Change)
73
// TxnLogWorker includes the watcher.Watcher's worker.Worker methods,
74
// so that a Workers implementation can manage its lifetime.
75
type TxnLogWorker interface {
80
// PresenceWatcher exposes the methods of presence.Watcher that are
81
// needed by the state package.
82
type PresenceWatcher interface {
85
// Horrible hack for goosing it into activity. Not clear why
86
// this is used by state in place of StartSync, but it is.
89
// Presence-reading and -watching.
90
Alive(key string) (bool, error)
91
Watch(key string, ch chan<- presence.Change)
92
Unwatch(key string, ch chan<- presence.Change)
95
// PresenceWorker includes the presence.Watcher's worker.Worker methods,
96
// so that a Workers implementation can manage its lifetime.
97
type PresenceWorker interface {
102
// LeaseManager exposes the methods of lease.Manager that are needed by
103
// the state package.
104
type LeaseManager interface {
109
// LeaseWorker includes the lease.Manager's worker.Worker methods,
110
// so that a Workers implementation can manage its lifetime.
111
type LeaseWorker interface {