lock

package
v3.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2020 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var MemoryLockDescriptor = refer.NewDescriptor("pip-services", "lock", "memory", "*", "1.0")
View Source
var NullLockDescriptor = refer.NewDescriptor("pip-services", "lock", "null", "*", "1.0")

Creates ILock components by their descriptors.

Functions

func NewDefaultLockFactory

func NewDefaultLockFactory() *build.Factory

Create a new instance of the factory. Returns *build.Factory

Types

type ILock

type ILock interface {
	// Makes a single attempt to acquire a lock by its key. It returns immediately a positive or negative result.
	TryAcquireLock(correlationId string, key string, ttl int64) (bool, error)

	// Makes multiple attempts to acquire a lock by its key within give time interval.
	AcquireLock(correlationId string, key string, ttl int64, timeout int64) error

	// Releases prevously acquired lock by its key.
	ReleaseLock(correlationId string, key string) error
}

Interface for locks to synchronize work or parallel processes and to prevent collisions.

The lock allows to manage multiple locks identified by unique keys.

type Lock

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

func InheritLock

func InheritLock(locker ILock) *Lock

Inherit lock fron ILock Returns *Lock

func (*Lock) AcquireLock

func (c *Lock) AcquireLock(correlationId string,
	key string, ttl int64, timeout int64) error

Makes multiple attempts to acquire a lock by its key within give time interval. Parameters:

  • correlationId string transaction id to trace execution through call chain.
  • key string a unique lock key to acquire. ttl int64 a lock timeout (time to live) in milliseconds. timeout int64 a lock acquisition timeout.

Returns error

func (*Lock) Configure

func (c *Lock) Configure(config *config.ConfigParams)

Configures component by passing configuration parameters. Parameters:

  • config *config.ConfigParams configuration parameters to be set.

type MemoryLock

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

Lock that is used to synchronize execution within one process using shared memory.

Remember: This implementation is not suitable for synchronization of distributed processes.

Configuration parameters options: retry_timeout: timeout in milliseconds to retry lock acquisition. (Default: 100) see ILock

see Lock

Example lock := NewMemoryLock() err = lock.Acquire("123", "key1")

if err == nil {
    defer _ = lock.ReleaseLock("123", "key1")
    // Processing...
}

func NewMemoryLock

func NewMemoryLock() *MemoryLock

Create new memory lock Returns *MemoryLock

func (*MemoryLock) ReleaseLock

func (c *MemoryLock) ReleaseLock(correlationId string,
	key string) error

Releases the lock with the given key. Parameters:

  • correlationId string not used.
  • key string the key of the lock that is to be released.

Return error

func (*MemoryLock) TryAcquireLock

func (c *MemoryLock) TryAcquireLock(correlationId string,
	key string, ttl int64) (bool, error)

Makes a single attempt to acquire a lock by its key. It returns immediately a positive or negative result. Parameters:

  • correlationId string transaction id to trace execution through call chain.
  • key string a unique lock key to acquire.
  • ttl int64 a lock timeout (time to live) in milliseconds.

Returns bool, error true if locked. Error object

type NullLock

type NullLock struct{}

Dummy lock implementation that doesn't do anything. It can be used in testing or in situations when lock is required but shall be disabled.

func NewNullLock

func NewNullLock() *NullLock

func (*NullLock) AcquireLock

func (c *NullLock) AcquireLock(correlationId string,
	key string, ttl int, timeout int) error

Makes multiple attempts to acquire a lock by its key within give time interval. Parameters:

  • correlationId string transaction id to trace execution through call chain.
  • key string a unique lock key to acquire. ttl int64 a lock timeout (time to live) in milliseconds. timeout int64 a lock acquisition timeout.

Returns error

func (*NullLock) ReleaseLock

func (c *NullLock) ReleaseLock(correlationId string,
	key string) error

Releases the lock with the given key. Parameters:

  • correlationId string not used.
  • key string the key of the lock that is to be released.

Return error

func (*NullLock) TryAcquireLock

func (c *NullLock) TryAcquireLock(correlationId string,
	key string, ttl int) (bool, error)

Makes a single attempt to acquire a lock by its key. It returns immediately a positive or negative result. Parameters:

  • correlationId string transaction id to trace execution through call chain.
  • key string a unique lock key to acquire.
  • ttl int64 a lock timeout (time to live) in milliseconds.

Returns bool, error true if locked. Error object

Jump to

Keyboard shortcuts

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