Package com.coditory.sherlock
Interface Sherlock
-
- All Known Implementing Classes:
SherlockStub
public interface SherlockCreates and manages distributed locks.
-
-
Method Summary
Modifier and Type Method Description DistributedLockcreateLock(java.lang.String lockId)Create a distributed lock.DistributedLockcreateLock(java.lang.String lockId, java.time.Duration duration)Create a lock.DistributedLockcreateOverridingLock(java.lang.String lockId)Create a distributed overriding lock.DistributedLockcreateOverridingLock(java.lang.String lockId, java.time.Duration duration)Create a distributed overriding lock.DistributedLockcreateReentrantLock(java.lang.String lockId)Create a distributed reentrant lock.DistributedLockcreateReentrantLock(java.lang.String lockId, java.time.Duration duration)Create a distributed reentrant lock.java.time.DurationgetLockDuration()java.lang.StringgetOwnerId()
-
-
-
Method Detail
-
getOwnerId
java.lang.String getOwnerId()
- Returns:
- owner id is most often the application instance id
-
getLockDuration
java.time.Duration getLockDuration()
- Returns:
- the default lock duration
-
createLock
DistributedLock createLock(java.lang.String lockId)
Create a distributed lock. Lock expires aftergetLockDuration().- 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 aftergetLockDuration().- 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 aftergetLockDuration().- 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
-
-