Interface LockManager
- All Known Implementing Classes:
LockManagerImpl
public interface LockManager
- Author:
- Filip Hrisafov
-
Method Summary
Modifier and TypeMethodDescriptionbooleanAcquire the lock.booleanacquireLock(Duration lockForceAcquireAfter) Acquire the lock.voidRelease the lock and delete the resources for the lock if needed.voidRelease the lock.voidwaitForLock(Duration waitTime) Wait for the givenwaitTimeto acquire the lock<T> TwaitForLockRunAndRelease(Duration waitTime, Supplier<T> supplier) Wait to acquire a lock, once a lock is acquired execute the supplier and release finally the lock.
-
Method Details
-
waitForLock
Wait for the givenwaitTimeto acquire the lock- Parameters:
waitTime- the duration to wait before throwing an exception
-
acquireLock
boolean acquireLock()Acquire the lock.- Returns:
trueif the lock was acquired,falseotherwise
-
acquireLock
Acquire the lock. ThelockForceAcquireAfterwill be used to acquire an expired lock- Parameters:
lockForceAcquireAfter- the amount of time after which the lock should be acquired- Returns:
trueif the lock was acquired,falseotherwise
-
releaseLock
void releaseLock()Release the lock. -
releaseAndDeleteLock
void releaseAndDeleteLock()Release the lock and delete the resources for the lock if needed. -
waitForLockRunAndRelease
Wait to acquire a lock, once a lock is acquired execute the supplier and release finally the lock.- Parameters:
waitTime- the duration to wait before throwing an exceptionsupplier- the supplier to be executed once the lock is acquired- Returns:
- the result from the
supplier
-