github.com/mhilton/juju-juju@v0.0.0-20150901100907-a94dd2c73455/worker/leadership/interface.go (about) 1 // Copyright 2015 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package leadership 5 6 import ( 7 "time" 8 9 "github.com/juju/juju/worker" 10 ) 11 12 // Ticket is used to communicate leadership status to Tracker clients. 13 type Ticket interface { 14 15 // Wait returns true if its Tracker is prepared to guarantee leadership 16 // for some period from the ticket request. The guaranteed duration depends 17 // upon the Tracker. 18 Wait() bool 19 20 // Ready returns a channel that will be closed when a result is available 21 // to Wait(), and is helpful for clients that want to select rather than 22 // block on long-waiting tickets. 23 Ready() <-chan struct{} 24 } 25 26 // Tracker allows clients to discover current leadership status by attempting to 27 // claim it for themselves. 28 type Tracker interface { 29 30 // ServiceName returns the name of the service for which leadership claims 31 // are made. 32 ServiceName() string 33 34 // ClaimDuration returns the duration for which a Ticket's true Wait result 35 // is guaranteed valid. 36 ClaimDuration() time.Duration 37 38 // ClaimLeader will return a Ticket which, when Wait()ed for, will return 39 // true if leadership is guaranteed for at least the tracker's duration from 40 // the time the ticket was issued. Leadership claims should be resolved 41 // relatively quickly. 42 ClaimLeader() Ticket 43 44 // WaitLeader will return a Ticket which, when Wait()ed for, will block 45 // until the tracker attains leadership. 46 WaitLeader() Ticket 47 48 // WaitMinion will return a Ticket which, when Wait()ed for, will block 49 // until the tracker's future leadership can no longer be guaranteed. 50 WaitMinion() Ticket 51 } 52 53 // TrackerWorker embeds the Tracker and worker.Worker interfaces. 54 type TrackerWorker interface { 55 worker.Worker 56 Tracker 57 }