lock

package
v0.3.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 23, 2015 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SemaphorePrefix = keyPrefix + "/" + semaphoreBranch
)

Variables

View Source
var (
	ErrExist    = errors.New("holder exists")
	ErrNotExist = errors.New("holder does not exist")
)

Functions

This section is empty.

Types

type EtcdLockClient

type EtcdLockClient struct {
	// contains filtered or unexported fields
}

EtcdLockClient is a wrapper around the etcd client that provides simple primitives to operate on the internal semaphore and holders structs through etcd.

func NewEtcdLockClient

func NewEtcdLockClient(ec etcd.EtcdClient, group string) (client *EtcdLockClient, err error)

NewEtcdLockClient creates a new EtcdLockClient. The group parameter defines the etcd key path in which the client will manipulate the semaphore. If the group is the empty string, the default semaphore will be used.

func (*EtcdLockClient) Get

func (c *EtcdLockClient) Get() (sem *Semaphore, err error)

Get fetches the Semaphore from etcd.

func (*EtcdLockClient) Init

func (c *EtcdLockClient) Init() (err error)

Init sets an initial copy of the semaphore if it doesn't exist yet.

func (*EtcdLockClient) Set

func (c *EtcdLockClient) Set(sem *Semaphore) (err error)

Set sets a Semaphore in etcd.

type Lock

type Lock struct {
	// contains filtered or unexported fields
}

func New

func New(id string, client LockClient) (lock *Lock)

func (*Lock) Get

func (l *Lock) Get() (sem *Semaphore, err error)

func (*Lock) Lock

func (l *Lock) Lock() (err error)

func (*Lock) SetMax

func (l *Lock) SetMax(max int) (sem *Semaphore, oldMax int, err error)

func (*Lock) Unlock

func (l *Lock) Unlock() error

type LockClient

type LockClient interface {
	Init() error
	Get() (*Semaphore, error)
	Set(*Semaphore) error
}

type Semaphore

type Semaphore struct {
	Index     uint64   `json:"-"`
	Semaphore int      `json:"semaphore"`
	Max       int      `json:"max"`
	Holders   []string `json:"holders"`
}

func (*Semaphore) Lock

func (s *Semaphore) Lock(h string) error

func (*Semaphore) SetMax

func (s *Semaphore) SetMax(max int) error

func (*Semaphore) String

func (s *Semaphore) String() string

func (*Semaphore) Unlock

func (s *Semaphore) Unlock(h string) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL