Package com.github.ddth.dlock
Interface IDLock
-
- All Known Implementing Classes:
AbstractDLock,BaseRedisDLock,ClusteredRedisDLock,InmemDLock,RedisDLock
public interface IDLockDistributed lock interface.Implementation:
- Each lock is identified by a unique name(space).
- Within a name(space), only one client is allowed to hold lock as a given time; each client is identified by a unique client-id (within the namespace).
- Since:
- 0.1.0
- Author:
- Thanh Nguyen
-
-
Field Summary
Fields Modifier and Type Field Description static longDEFAULT_LOCK_DURATION_MS
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description StringgetName()Get lock's name(space).LockResultlock(int waitWeight, String clientId)Acquire the lock forclientIdwith default duration.LockResultlock(int waitWeight, String clientId, long lockDurationMs)Acquire the lock forclientIdfor a duration oflockDurationMs.LockResultlock(String clientId)Acquire the lock forclientIdwith default duration.LockResultlock(String clientId, long lockDurationMs)Acquire the lock forclientIdfor a duration oflockDurationMs.LockResultunlock(String clientId)Release the lock.
-
-
-
Field Detail
-
DEFAULT_LOCK_DURATION_MS
static final long DEFAULT_LOCK_DURATION_MS
- See Also:
- Constant Field Values
-
-
Method Detail
-
getName
String getName()
Get lock's name(space).- Returns:
-
lock
LockResult lock(String clientId) throws DLockException
Acquire the lock forclientIdwith default duration.Reentrant: lock can be acquired multiple times by the same
clientId. Lock's expiry will be extended accordingly.- Parameters:
clientId- within a namespace, only one client is allowed to hold lock as a given time- Returns:
LockResult.SUCCESSFULif successful,LockResult.HOLD_BY_ANOTHER_CLIENTif lock is currently hold by another client- Throws:
DLockException
-
lock
LockResult lock(String clientId, long lockDurationMs)
Acquire the lock forclientIdfor a duration oflockDurationMs.Reentrant: lock can be acquired multiple times by the same
clientId. Lock's expiry will be extended accordingly.- Parameters:
clientId- within a namespace, only one client is allowed to hold the lock as a given timelockDurationMs-- Returns:
LockResult.SUCCESSFULif successful,LockResult.HOLD_BY_ANOTHER_CLIENTif lock is currently hold by another client
-
lock
LockResult lock(int waitWeight, String clientId)
Acquire the lock forclientIdwith default duration.Reentrant: lock can be acquired multiple times by the same
clientId. Lock's expiry will be extended accordingly.- Parameters:
waitWeight- "fairness":clientIdwith higherwaitWeightvalue might have higher chance to acquire the lock, negative value means "no fairness"clientId- within a namespace, only one client is allowed to hold the lock as a given time- Returns:
LockResult.SUCCESSFULif successful,LockResult.HOLD_BY_ANOTHER_CLIENTif lock is currently hold by another client- Since:
- 0.1.2
-
lock
LockResult lock(int waitWeight, String clientId, long lockDurationMs)
Acquire the lock forclientIdfor a duration oflockDurationMs.Reentrant: lock can be acquired multiple times by the same
clientId. Lock's expiry will be extended accordingly.- Parameters:
waitWeight- "fairness":clientIdwith higherwaitWeightvalue might have higher chance to acquire the lock, negative value means "no fairness"clientId- within a namespace, only one client is allowed to hold the lock as a given timelockDurationMs-- Returns:
LockResult.SUCCESSFULif successful,LockResult.HOLD_BY_ANOTHER_CLIENTif lock is currently hold by another client- Since:
- 0.1.2
-
unlock
LockResult unlock(String clientId)
Release the lock.- Parameters:
clientId- within a namespace, only one client is allowed to hold the lock as a given time- Returns:
LockResult.SUCCESSFULif successful,LockResult.HOLD_BY_ANOTHER_CLIENTif lock is currently hold by another client,LockResult.NOT_FOUNDif the lock is not currently hold by any client (not locked before, or already expired)
-
-