Package com.github.ddth.dlock.impl.inmem
Class InmemDLock
- java.lang.Object
-
- com.github.ddth.dlock.impl.AbstractDLock
-
- com.github.ddth.dlock.impl.inmem.InmemDLock
-
- All Implemented Interfaces:
IDLock,AutoCloseable
public class InmemDLock extends AbstractDLock
In-memory implementation ofIDLock.- Since:
- 0.1.0
- Author:
- Thanh Nguyen
-
-
Field Summary
-
Fields inherited from interface com.github.ddth.dlock.IDLock
DEFAULT_LOCK_DURATION_MS
-
-
Constructor Summary
Constructors Constructor Description InmemDLock(String name)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description LockResultlock(int waitWeight, String clientId, long lockDurationMs)Acquire the lock forclientIdfor a duration oflockDurationMs.LockResultunlock(String clientId)Release the lock.-
Methods inherited from class com.github.ddth.dlock.impl.AbstractDLock
close, destroy, getClientId, getLockProperties, getLockProperty, getName, getTimestampExpiry, init, lock, lock, lock, setClientId, setLockProperties, setName, setTimestampExpiry, toString, updateLockHolder
-
-
-
-
Constructor Detail
-
InmemDLock
public InmemDLock(String name)
-
-
Method Detail
-
lock
public 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 time- Returns:
LockResult.SUCCESSFULif successful,LockResult.HOLD_BY_ANOTHER_CLIENTif lock is currently hold by another client
-
unlock
public 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)
-
-