1
// Copyright 2015 Canonical Ltd.
2
// Licensed under the AGPLv3, see LICENCE file for details.
9
"github.com/juju/errors"
12
// ErrClaimDenied indicates that a Claimer.Claim() has been denied.
13
var ErrClaimDenied = errors.New("lease claim denied")
15
// ErrNotHeld indicates that some holder does not hold some lease.
16
var ErrNotHeld = errors.New("lease not held")
18
// Claimer exposes lease acquisition and expiry notification capabilities.
19
type Claimer interface {
21
// Claim acquires or extends the named lease for the named holder. If it
22
// succeeds, the holder is guaranteed to keep the lease until at least
23
// duration after the *start* of the call. If it returns ErrClaimDenied,
24
// the holder is guaranteed not to have the lease. If it returns any other
25
// error, no reasonable inferences may be made.
26
Claim(leaseName, holderName string, duration time.Duration) error
28
// WaitUntilExpired returns nil when the named lease is no longer held. If it
29
// returns any other error, no reasonable inferences may be made.
30
WaitUntilExpired(leaseName string) error
33
// Checker exposes facts about lease ownership.
34
type Checker interface {
36
// Token returns a Token that can be interrogated at any time to discover
37
// whether the supplied lease is currently held by the supplied holder.
38
Token(leaseName, holderName string) Token
41
// Token represents a fact -- but not necessarily a *true* fact -- about some
42
// holder's ownership of some lease.
43
type Token interface {
45
// Check returns ErrNotHeld if the lease it represents is not held by the
46
// holder it represents. If trapdoorKey is nil, and Check returns nil, then
47
// the token continues to represent a true fact.
49
// If the token represents a true fact and trapdoorKey is *not* nil, it will
50
// be passed through layers for the attention of the underlying lease.Client
51
// implementation. If you need to do this, consult the documentation for the
52
// particular Client you're using to determine what key should be passed and
53
// what errors that might induce.
54
Check(trapdoorKey interface{}) error