Package org.redisson.api
Interface RFencedLock
- All Superinterfaces:
Lock
,RFencedLockAsync
,RLock
,RLockAsync
- All Known Implementing Classes:
RedissonFencedLock
Redis based implementation of Fenced Lock with reentrancy support.
Each lock acquisition increases fencing token. It should be checked if it's greater or equal with the previous one by the service guarded by this lock and reject operation if condition is false.
- Author:
- Nikita Koksharov
-
Method Summary
Modifier and TypeMethodDescriptiongetToken()
Returns current fencing tokenAcquires the lock and returns increased fencing token.lockAndGetToken
(long leaseTime, TimeUnit unit) Acquires the lock with definedleaseTime
and returns increased fencing token.Tries to acquire the lock and returns increased fencing token if operation successful.tryLockAndGetToken
(long waitTime, long leaseTime, TimeUnit unit) Tries to acquire the lock with definedleaseTime
and returns increased fencing token.tryLockAndGetToken
(long waitTime, TimeUnit unit) Tries to acquire the lock and returns increased fencing token.Methods inherited from interface java.util.concurrent.locks.Lock
lock, lockInterruptibly, newCondition, tryLock, tryLock, unlock
Methods inherited from interface org.redisson.api.RFencedLockAsync
getTokenAsync, lockAndGetTokenAsync, lockAndGetTokenAsync, tryLockAndGetTokenAsync, tryLockAndGetTokenAsync, tryLockAndGetTokenAsync
Methods inherited from interface org.redisson.api.RLock
forceUnlock, getHoldCount, getName, isHeldByCurrentThread, isHeldByThread, isLocked, lock, lockInterruptibly, remainTimeToLive, tryLock
Methods inherited from interface org.redisson.api.RLockAsync
forceUnlockAsync, getHoldCountAsync, isLockedAsync, lockAsync, lockAsync, lockAsync, lockAsync, remainTimeToLiveAsync, tryLockAsync, tryLockAsync, tryLockAsync, tryLockAsync, tryLockAsync, unlockAsync, unlockAsync
-
Method Details
-
getToken
Long getToken()Returns current fencing token- Returns:
- fencing token
-
lockAndGetToken
Long lockAndGetToken()Acquires the lock and returns increased fencing token. Waits if necessary until lock became available.- Returns:
- fencing token
-
lockAndGetToken
Acquires the lock with definedleaseTime
and returns increased fencing token. Waits if necessary until lock became available.Lock will be released automatically after defined
leaseTime
interval.- Parameters:
leaseTime
- the maximum time to hold the lock after it's acquisition, if it hasn't already been released by invokingunlock
. If leaseTime is -1, hold the lock until explicitly unlocked.unit
- the time unit- Returns:
- fencing token
-
tryLockAndGetToken
Long tryLockAndGetToken()Tries to acquire the lock and returns increased fencing token if operation successful.- Returns:
- fencing token if lock acquired otherwise
null
-
tryLockAndGetToken
Tries to acquire the lock and returns increased fencing token. Waits up to definedwaitTime
if necessary until the lock became available.- Parameters:
waitTime
- the maximum time to acquire the lockunit
- time unit- Returns:
- fencing token if lock is successfully acquired,
otherwise
null
if lock is already set.
-
tryLockAndGetToken
Tries to acquire the lock with definedleaseTime
and returns increased fencing token. Waits up to definedwaitTime
if necessary until the lock became available.Lock will be released automatically after defined
leaseTime
interval.- Parameters:
waitTime
- the maximum time to acquire the lockleaseTime
- lease timeunit
- time unit- Returns:
- fencing token if lock is successfully acquired,
otherwise
null
if lock is already set.
-