Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewDefaultLockFactory ¶
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 ILockOverrides ¶ added in v1.1.0
type ILockOverrides interface { ILock }
type Lock ¶
type Lock struct { Overrides ILockOverrides // contains filtered or unexported fields }
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
Inherit lock fron ILock Returns *Lock
func (*Lock) AcquireLock ¶
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 (*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 ¶
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 ¶
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 ¶
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 ¶
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