Package com.coditory.sherlock
Interface Sherlock
-
- All Known Implementing Classes:
SherlockStub
public interface Sherlock
Creates and manages distributed locks.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description DistributedLock
createLock(java.lang.String lockId)
Create a distributed lock.DistributedLock
createLock(java.lang.String lockId, java.time.Duration duration)
Create a lock.DistributedLock
createOverridingLock(java.lang.String lockId)
Create a distributed overriding lock.DistributedLock
createOverridingLock(java.lang.String lockId, java.time.Duration duration)
Create a distributed overriding lock.DistributedLock
createReentrantLock(java.lang.String lockId)
Create a distributed reentrant lock.DistributedLock
createReentrantLock(java.lang.String lockId, java.time.Duration duration)
Create a distributed reentrant lock.void
initialize()
Initializes underlying infrastructure.
-
-
-
Method Detail
-
initialize
void initialize()
Initializes underlying infrastructure. If it's database then indexes and tables are created. If this method is not invoked directly then it is invoked implicitly when acquiring or releasing a lock for the first time.
-
createLock
DistributedLock createLock(java.lang.String lockId)
Create a distributed lock. Lock expires after configured lock duration.- Parameters:
lockId
- the lock id- Returns:
- the lock
- See Also:
createLock(String, Duration)
-
createLock
DistributedLock createLock(java.lang.String lockId, java.time.Duration duration)
Create a lock. Created lock may be acquired only once by the same application instance:assert reentrantLock.acquire() == true assert reentrantLock.acquire() == false
- Parameters:
lockId
- the lock idduration
- after that time lock expires and is released- Returns:
- the lock
-
createReentrantLock
DistributedLock createReentrantLock(java.lang.String lockId)
Create a distributed reentrant lock. Lock expires after configured lock duration.- Parameters:
lockId
- the lock id- Returns:
- the reentrant lock
- See Also:
createReentrantLock(String, Duration)
-
createReentrantLock
DistributedLock createReentrantLock(java.lang.String lockId, java.time.Duration duration)
Create a distributed reentrant lock. Reentrant lock maybe acquired multiple times by the same application instance:assert reentrantLock.acquire() == true assert reentrantLock.acquire() == true
- Parameters:
lockId
- the lock idduration
- after that time lock expires and is released- Returns:
- the reentrant lock
-
createOverridingLock
DistributedLock createOverridingLock(java.lang.String lockId)
Create a distributed overriding lock. Lock expires after configured lock duration.- Parameters:
lockId
- the lock id- Returns:
- the reentrant lock
- See Also:
createOverridingLock(String, Duration)
-
createOverridingLock
DistributedLock createOverridingLock(java.lang.String lockId, java.time.Duration duration)
Create a distributed overriding lock. Returned lock overrides lock state without checking if it was released.- Parameters:
lockId
- the lock idduration
- after that time lock expires and is released- Returns:
- the reentrant lock
-
-