lock

package
v1.0.6-10 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2022 License: MIT Imports: 7 Imported by: 4

Documentation

Index

Constants

View Source
const (
	DefaultRetryTimeout            int64  = 100
	ConfigParamOptionsRetryTimeout string = "options.retry_timeout"
)

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")

Functions

func NewDefaultLockFactory

func NewDefaultLockFactory() *build.Factory

NewDefaultLockFactory create a new instance of the factory.

Returns: *build.Factory

Types

type ILock

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

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

	// ReleaseLock releases previously acquired lock by its key.
	ReleaseLock(ctx context.Context, correlationId string, key string) error
}

ILock Interface for locks to synchronize work or parallel processes and to prevent collisions. The lock allows managing multiple locks identified by unique keys.

type ILockOverrides added in v1.0.4

type ILockOverrides interface {
	ILock
}

type Lock

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

Lock abstract lock that implements default lock acquisition routine.

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

func InheritLock

func InheritLock(overrides ILockOverrides) *Lock

InheritLock inherit lock from ILockOverrides

Returns: *Lock

func (*Lock) AcquireLock

func (c *Lock) AcquireLock(ctx context.Context, correlationId string,
	key string, ttl int64, timeout int64) error

AcquireLock makes multiple attempts to acquire a lock by its key within give time interval.

Parameters:
	- ctx context.Context
	- 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(ctx context.Context, config *config.ConfigParams)

Configure component by passing configuration parameters.

Parameters:
	- ctx context.Context
	- config *config.ConfigParams configuration parameters to be set.

type MemoryLock

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

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

Configuration parameters:
	options:
	retry_timeout: timeout in milliseconds to retry lock acquisition. (Default: 100)
see ILock
see Lock
Example:
	lock := NewMemoryLock()
	err = lock.AcquireLock(context.Background(), "123", "key1")
	if err == nil {
		 _ = lock.ReleaseLock(context.Background(), "123", "key1")
		// Processing...
	}

func NewMemoryLock

func NewMemoryLock() *MemoryLock

NewMemoryLock create new memory lock

Returns: *MemoryLock

func (*MemoryLock) ReleaseLock

func (c *MemoryLock) ReleaseLock(ctx context.Context, correlationId string,
	key string) error

ReleaseLock releases the lock with the given key.

Parameters:
	- ctx context.Context
	- 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(ctx context.Context, correlationId string,
	key string, ttl int64) (bool, error)

TryAcquireLock makes a single attempt to acquire a lock by its key. It returns immediately a positive or negative result.

Parameters:
	- ctx context.Context
	- 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{}

NullLock 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(ctx context.Context, correlationId string,
	key string, ttl int, timeout int) error

AcquireLock makes multiple attempts to acquire a lock by its key within give time interval.

Parameters:
	- ctx context.Context
	- 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(ctx context.Context, correlationId string,
	key string) error

ReleaseLock releases the lock with the given key.

Parameters:
	- ctx context.Context
	- 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(ctx context.Context, correlationId string,
	key string, ttl int) (bool, error)

TryAcquireLock makes a single attempt to acquire a lock by its key. It returns immediately a positive or negative result.

Parameters:
	- ctx context.Context
	- 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