pip_services3_components.lock package
Submodules
Module contents
pip_services3_components.__init__
Components module initialization
- copyright
Conceptual Vision Consulting LLC 2018-2019, see AUTHORS for more details.
- license
MIT, see LICENSE for more details.
-
class
pip_services3_components.lock.DefaultLockFactory Bases:
pip_services3_components.build.Factory.FactoryCreates
ILockcomponents by their descriptors.See
Factory,ILock,MemoryLock,NullLock-
MemoryLockDescriptor= <pip_services3_commons.refer.Descriptor.Descriptor object>
-
NullLockDescriptor= <pip_services3_commons.refer.Descriptor.Descriptor object>
-
-
class
pip_services3_components.lock.ILock Bases:
abc.ABCInterface for locks to synchronize work or parallel processes and to prevent collisions.
The lock allows to manage multiple locks identified by unique keys.
-
acquire_lock(correlation_id: Optional[str], key: str, ttl: int, timeout: int) Releases prevously acquired lock by its key.
- Parameters
correlation_id – (optional) transaction id to trace execution through call chain.
key – a unique lock key to acquire.
ttl – a lock timeout (time to live) in milliseconds.
timeout – lock timeout
-
release_lock(correlation_id: Optional[str], key: str) Releases prevously acquired lock by its key.
- Parameters
correlation_id – (optional) transaction id to trace execution through call chain.
key – a unique lock key to acquire.
-
try_acquire_lock(correlation_id: Optional[str], key: str, ttl: int) → bool Makes a single attempt to acquire a lock by its key. It returns immediately a positive or negative result.
- Parameters
correlation_id – (optional) transaction id to trace execution through call chain.
key – a unique lock key to acquire.
ttl – a lock timeout (time to live) in milliseconds.
- Returns
lock result
-
-
class
pip_services3_components.lock.Lock Bases:
pip_services3_components.lock.ILock.ILock,pip_services3_commons.config.IReconfigurable.IReconfigurable-
acquire_lock(correlation_id: Optional[str], key: str, ttl: int, timeout: int) Makes multiple attempts to acquire a lock by its key within give time interval.
- Parameters
correlation_id – (optional) transaction id to trace execution through call chain.
key – a unique lock key to acquire.
ttl – a lock timeout (time to live) in milliseconds.
timeout – a lock acquisition timeout.
-
configure(config: pip_services3_commons.config.ConfigParams.ConfigParams) Configures component by passing configuration parameters.
- Parameters
config – configuration parameters to be set.
-
abstract
release_lock(correlation_id: Optional[str], key: str) Releases prevously acquired lock by its key.
- Parameters
correlation_id – (optional) transaction id to trace execution through call chain.
key – a unique lock key to release.
- Returns
receive null for success.
-
abstract
try_acquire_lock(correlation_id: Optional[str], key: str, ttl: int) → bool Makes a single attempt to acquire a lock by its key. It returns immediately a positive or negative result.
- Parameters
correlation_id – (optional) transaction id to trace execution through call chain.
key – a unique lock key to acquire.
ttl – a lock timeout (time to live) in milliseconds.
- Returns
lock result
-
-
class
pip_services3_components.lock.MemoryLock Bases:
pip_services3_components.lock.Lock.LockLock 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)
Example:
lock = MemoryLock() lock.acquire_lock("123", "key1", None, None) # processing lock.release_lock("123", "key1")
-
release_lock(correlation_id: Optional[str], key: str) Releases the lock with the given key.
- Parameters
correlation_id – not user.
key – the key of the lock that is to be released.
-
try_acquire_lock(correlation_id: Optional[str], key: str, ttl: int) Makes a single attempt to acquire a lock by its key.
It returns immediately a positive or negative result.
- Parameters
correlation_id – (optional) transaction id to trace execution through call chain.
key – a unique lock key to acquire.
ttl – a lock timeout (time to live) in milliseconds.
- Returns
receives a lock result.
-
class
pip_services3_components.lock.NullLock Bases:
pip_services3_components.lock.ILock.ILockDummy lock implementation that doesn’t do anything.
It can be used in testing or in situations when lock is required but shall be disabled.
-
acquire_lock(correlation_id: Optional[str], key: str, ttl: int, timeout: int) Releases prevously acquired lock by its key.
- Parameters
correlation_id – (optional) transaction id to trace execution through call chain.
key – a unique lock key to acquire.
ttl – a lock timeout (time to live) in milliseconds.
timeout – lock timeout
- Returns
lock result
-
release_lock(correlation_id: Optional[str], key: str) - Parameters
correlation_id – (optional) transaction id to trace execution through call chain.
key – a unique lock key to acquire.
- Returns
lock result
-
try_acquire_lock(correlation_id: Optional[str], key: str, ttl: int) → bool Makes a single attempt to acquire a lock by its key. It returns immediately a positive or negative result.
- Parameters
correlation_id – (optional) transaction id to trace execution through call chain.
key – a unique lock key to acquire.
ttl – a lock timeout (time to live) in milliseconds.
- Returns
lock result
-