github.com/altoros/juju-vmware@v0.0.0-20150312064031-f19ae857ccca/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/errors"
    10  
    11  	"github.com/juju/juju/lease"
    12  )
    13  
    14  // LeadershipClaimDeniedErr is the error which will be returned when a
    15  // leadership claim has been denied.
    16  var LeadershipClaimDeniedErr = errors.New("leadership claim denied")
    17  
    18  type LeadershipManager interface {
    19  	// ClaimLeadership claims a leadership for the given serviceId and
    20  	// unitId. If successful, the duration of the leadership lease is
    21  	// returned.
    22  	ClaimLeadership(serviceId, unitId string) (nextClaimInterval time.Duration, err error)
    23  
    24  	// ReleaseLeadership releases a leadership claim for the given
    25  	// serviceId and unitId.
    26  	ReleaseLeadership(serviceId, unitId string) (err error)
    27  
    28  	// BlockUntilLeadershipReleased blocks the caller until leadership is
    29  	// released for the given serviceId.
    30  	BlockUntilLeadershipReleased(serviceId string) (err error)
    31  }
    32  
    33  type LeadershipLeaseManager interface {
    34  	// Claimlease claims a lease for the given duration for the given
    35  	// namespace and id. If the lease is already owned, a
    36  	// LeaseClaimDeniedErr will be returned. Either way the current lease
    37  	// owner's ID will be returned.
    38  	ClaimLease(namespace, id string, forDur time.Duration) (leaseOwnerId string, err error)
    39  
    40  	// ReleaseLease releases the lease held for namespace by id.
    41  	ReleaseLease(namespace, id string) (err error)
    42  
    43  	// RetrieveLease retrieves the current lease token for a given
    44  	// namespace. This is not intended to be exposed to clients, and is
    45  	// only available within a server-process.
    46  	RetrieveLease(namespace string) lease.Token
    47  
    48  	// LeaseReleasedNotifier returns a channel a caller can block on to be
    49  	// notified of when a lease is released for namespace. This channel is
    50  	// reusable, but will be closed if it does not respond within
    51  	// "notificationTimeout".
    52  	LeaseReleasedNotifier(namespace string) (notifier <-chan struct{})
    53  }