Package org.pipservices3.components.lock
Class Lock
java.lang.Object
org.pipservices3.components.lock.Lock
- All Implemented Interfaces:
org.pipservices3.commons.config.IConfigurable,org.pipservices3.commons.config.IReconfigurable,ILock
- Direct Known Subclasses:
MemoryLock
public abstract class Lock
extends Object
implements ILock, org.pipservices3.commons.config.IReconfigurable
Abstract lock that implements default lock acquisition routine.
### Configuration parameters ###
-
- options:
- - retry_timeout: timeout in milliseconds to retry lock acquisition. (Default: 100)
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidacquireLock(String correlationId, String key, int ttl, long timeout) Makes multiple attempts to acquire a lock by its key within give time interval.voidconfigure(org.pipservices3.commons.config.ConfigParams config) Configures component by passing configuration parameters.abstract voidreleaseLock(String correlationId, String key) Releases prevously acquired lock by its key.abstract booleantryAcquireLock(String correlationId, String key, int ttl) Makes a single attempt to acquire a lock by its key.
-
Constructor Details
-
Lock
public Lock()
-
-
Method Details
-
configure
public void configure(org.pipservices3.commons.config.ConfigParams config) Configures component by passing configuration parameters.- Specified by:
configurein interfaceorg.pipservices3.commons.config.IConfigurable- Parameters:
config- configuration parameters to be set.
-
tryAcquireLock
Makes a single attempt to acquire a lock by its key. It returns immediately a positive or negative result.- Specified by:
tryAcquireLockin interfaceILock- Parameters:
correlationId- (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:
trueif the lock was acquired andfalseotherwise.
-
acquireLock
public void acquireLock(String correlationId, String key, int ttl, long timeout) throws InterruptedException, org.pipservices3.commons.errors.ApplicationException Makes multiple attempts to acquire a lock by its key within give time interval.- Specified by:
acquireLockin interfaceILock- Parameters:
correlationId- (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.- Throws:
InterruptedExceptionorg.pipservices3.commons.errors.ApplicationException
-
releaseLock
Releases prevously acquired lock by its key.- Specified by:
releaseLockin interfaceILock- Parameters:
correlationId- (optional) transaction id to trace execution through call chain.key- a unique lock key to release.
-