Package org.pipservices3.components.lock
Interface ILock
- All Known Implementing Classes:
Lock,MemoryLock,NullLock
public interface ILock
Interface for locks to synchronize work or parallel processes and to prevent collisions.
The lock allows to manage multiple locks identified by unique keys.
-
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.voidreleaseLock(String correlationId, String key) Releases prevously acquired lock by its key.booleantryAcquireLock(String correlationId, String key, int ttl) Makes a single attempt to acquire a lock by its key.
-
Method Details
-
tryAcquireLock
Makes a single attempt to acquire a lock by its key. It returns immediately a positive or negative result.- 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
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.- 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.- Parameters:
correlationId- (optional) transaction id to trace execution through call chain.key- a unique lock key to release.
-