github.com/axw/juju@v0.0.0-20161005053422-4bd6544d08d4/core/lease/claimer.go (about) 1 // Copyright 2015 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package lease 5 6 import ( 7 "time" 8 9 "github.com/juju/errors" 10 ) 11 12 // ErrClaimDenied indicates that a Claimer.Claim() has been denied. 13 var ErrClaimDenied = errors.New("lease claim denied") 14 15 // ErrNotHeld indicates that some holder does not hold some lease. 16 var ErrNotHeld = errors.New("lease not held") 17 18 // Claimer exposes lease acquisition and expiry notification capabilities. 19 type Claimer interface { 20 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 27 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 31 } 32 33 // Checker exposes facts about lease ownership. 34 type Checker interface { 35 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 39 } 40 41 // Token represents a fact -- but not necessarily a *true* fact -- about some 42 // holder's ownership of some lease. 43 type Token interface { 44 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. 48 // 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 55 }