public class RedissonLock extends RedissonObject implements RLock
Lock
Implements reentrant lock.Implements a non-fair locking so doesn't guarantees an acquire order.
Modifier and Type | Class and Description |
---|---|
static class |
RedissonLock.ExpirationEntry |
Modifier and Type | Field and Description |
---|---|
protected long |
internalLockLeaseTime |
protected LockPubSub |
pubSub |
codec, name
Constructor and Description |
---|
RedissonLock(CommandAsyncExecutor commandExecutor,
String name) |
Modifier and Type | Method and Description |
---|---|
protected RFuture<Void> |
acquireFailedAsync(long threadId) |
boolean |
clearExpire()
Clear an expire timeout or expire date for object.
|
RFuture<Boolean> |
clearExpireAsync()
Clear an expire timeout or expire date for object in async mode.
|
RFuture<Boolean> |
deleteAsync()
Delete object in async mode
|
boolean |
expire(long timeToLive,
TimeUnit timeUnit)
Set a timeout for object.
|
RFuture<Boolean> |
expireAsync(long timeToLive,
TimeUnit timeUnit)
Set a timeout for object in async mode.
|
boolean |
expireAt(Date timestamp)
Set an expire date for object.
|
boolean |
expireAt(long timestamp)
Set an expire date for object.
|
RFuture<Boolean> |
expireAtAsync(Date timestamp)
Set an expire date for object in async mode.
|
RFuture<Boolean> |
expireAtAsync(long timestamp)
Set an expire date for object in async mode.
|
boolean |
forceUnlock()
Unlocks lock independently of state
|
RFuture<Boolean> |
forceUnlockAsync()
Unlocks the lock independently of state
|
protected RedissonLockEntry |
getEntry(long threadId) |
protected String |
getEntryName() |
int |
getHoldCount()
Number of holds on this lock by the current thread
|
RFuture<Integer> |
getHoldCountAsync()
Number of holds on this lock by the current thread
|
protected String |
getLockName(long threadId) |
RFuture<Boolean> |
isExistsAsync()
Check object existence in async mode.
|
boolean |
isHeldByCurrentThread()
Checks if this lock is held by the current thread
|
boolean |
isHeldByThread(long threadId)
Checks if this lock is held by the current thread
|
boolean |
isLocked()
Checks if this lock locked by any thread
|
RFuture<Boolean> |
isLockedAsync()
Checks if this lock locked by any thread
|
void |
lock() |
void |
lock(long leaseTime,
TimeUnit unit)
Acquires the lock.
|
RFuture<Void> |
lockAsync()
Acquires the lock.
|
RFuture<Void> |
lockAsync(long currentThreadId)
Acquires the lock by thread with specified
threadId . |
RFuture<Void> |
lockAsync(long leaseTime,
TimeUnit unit)
Acquires the lock.
|
RFuture<Void> |
lockAsync(long leaseTime,
TimeUnit unit,
long currentThreadId)
Acquires the lock by thread with specified
threadId . |
void |
lockInterruptibly() |
void |
lockInterruptibly(long leaseTime,
TimeUnit unit)
Acquires the lock.
|
Condition |
newCondition() |
long |
remainTimeToLive()
Remaining time to live of Redisson object that has a timeout
|
RFuture<Long> |
remainTimeToLiveAsync()
Remaining time to live of Redisson object that has a timeout
|
protected RFuture<Boolean> |
renewExpirationAsync(long threadId) |
protected RFuture<RedissonLockEntry> |
subscribe(long threadId) |
boolean |
tryLock() |
boolean |
tryLock(long waitTime,
long leaseTime,
TimeUnit unit)
Returns
true as soon as the lock is acquired. |
boolean |
tryLock(long waitTime,
TimeUnit unit) |
RFuture<Boolean> |
tryLockAsync()
Tries to acquire the lock.
|
RFuture<Boolean> |
tryLockAsync(long threadId)
Tries to acquire the lock by thread with specified
threadId . |
RFuture<Boolean> |
tryLockAsync(long waitTime,
long leaseTime,
TimeUnit unit)
Tries to acquire the lock.
|
RFuture<Boolean> |
tryLockAsync(long waitTime,
long leaseTime,
TimeUnit unit,
long currentThreadId)
Tries to acquire the lock by thread with specified
threadId . |
RFuture<Boolean> |
tryLockAsync(long waitTime,
TimeUnit unit)
Tries to acquire the lock.
|
void |
unlock() |
RFuture<Void> |
unlockAsync()
Unlocks the lock
|
RFuture<Void> |
unlockAsync(long threadId)
Unlocks the lock.
|
protected RFuture<Boolean> |
unlockInnerAsync(long threadId) |
protected void |
unsubscribe(RFuture<RedissonLockEntry> future,
long threadId) |
addListener, addListenerAsync, copy, copyAsync, delete, dump, dumpAsync, encode, encode, encode, encodeMapKey, encodeMapKeys, encodeMapValue, encodeMapValues, get, getCodec, getLockByMapKey, getLockByValue, getName, getName, isExists, migrate, migrateAsync, move, moveAsync, prefixName, removeListener, removeListenerAsync, rename, renameAsync, renamenx, renamenxAsync, restore, restore, restoreAndReplace, restoreAndReplace, restoreAndReplaceAsync, restoreAndReplaceAsync, restoreAsync, restoreAsync, sizeInMemory, sizeInMemoryAsync, sizeInMemoryAsync, suffixName, toSeconds, toStream, touch, touchAsync, unlink, unlinkAsync
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getName, remainTimeToLive
remainTimeToLiveAsync
addListener, copy, delete, dump, getCodec, getName, isExists, migrate, move, removeListener, rename, renamenx, restore, restore, restoreAndReplace, restoreAndReplace, sizeInMemory, touch, unlink
addListenerAsync, copyAsync, dumpAsync, migrateAsync, moveAsync, removeListenerAsync, renameAsync, renamenxAsync, restoreAndReplaceAsync, restoreAndReplaceAsync, restoreAsync, restoreAsync, sizeInMemoryAsync, touchAsync, unlinkAsync
protected long internalLockLeaseTime
protected final LockPubSub pubSub
public RedissonLock(CommandAsyncExecutor commandExecutor, String name)
protected String getEntryName()
protected String getLockName(long threadId)
public void lock(long leaseTime, TimeUnit unit)
RLock
If the lock is not available then the current thread becomes
disabled for thread scheduling purposes and lies dormant until the
lock has been acquired.
If the lock is acquired, it is held until unlock
is invoked,
or until leaseTime milliseconds have passed
since the lock was granted - whichever comes first.
lock
in interface RLock
leaseTime
- the maximum time to hold the lock after granting it,
before automatically releasing it if it hasn't already been released by invoking unlock
.
If leaseTime is -1, hold the lock until explicitly unlocked.unit
- the time unit of the leaseTime
argumentpublic void lockInterruptibly() throws InterruptedException
lockInterruptibly
in interface Lock
InterruptedException
public void lockInterruptibly(long leaseTime, TimeUnit unit) throws InterruptedException
RLock
If the lock is not available then the current thread becomes
disabled for thread scheduling purposes and lies dormant until the
lock has been acquired.
If the lock is acquired, it is held until unlock
is invoked,
or until leaseTime have passed
since the lock was granted - whichever comes first.
lockInterruptibly
in interface RLock
leaseTime
- the maximum time to hold the lock after granting it,
before automatically releasing it if it hasn't already been released by invoking unlock
.
If leaseTime is -1, hold the lock until explicitly unlocked.unit
- the time unit of the leaseTime
argumentInterruptedException
- - if the thread is interrupted before or during this method.public boolean tryLock(long waitTime, long leaseTime, TimeUnit unit) throws InterruptedException
RLock
true
as soon as the lock is acquired.
If the lock is currently held by another thread in this or any
other process in the distributed system this method keeps trying
to acquire the lock for up to waitTime
before
giving up and returning false
. If the lock is acquired,
it is held until unlock
is invoked, or until leaseTime
have passed since the lock was granted - whichever comes first.tryLock
in interface RLock
waitTime
- the maximum time to aquire the lockleaseTime
- lease timeunit
- time unittrue
if lock has been successfully acquiredInterruptedException
- - if the thread is interrupted before or during this method.protected RedissonLockEntry getEntry(long threadId)
protected RFuture<RedissonLockEntry> subscribe(long threadId)
protected void unsubscribe(RFuture<RedissonLockEntry> future, long threadId)
public boolean tryLock(long waitTime, TimeUnit unit) throws InterruptedException
tryLock
in interface Lock
InterruptedException
public Condition newCondition()
newCondition
in interface Lock
public boolean forceUnlock()
RLock
forceUnlock
in interface RLock
true
if lock existed and now unlocked otherwise false
public RFuture<Boolean> forceUnlockAsync()
RLockAsync
forceUnlockAsync
in interface RLockAsync
true
if lock existed and now unlocked otherwise false
public boolean isLocked()
RLock
public RFuture<Boolean> isLockedAsync()
RLockAsync
isLockedAsync
in interface RLockAsync
true
if locked otherwise false
public RFuture<Boolean> isExistsAsync()
RObjectAsync
isExistsAsync
in interface RObjectAsync
isExistsAsync
in class RedissonObject
true
if object exists and false
otherwisepublic boolean isHeldByCurrentThread()
RLock
isHeldByCurrentThread
in interface RLock
true
if held by current thread
otherwise false
public boolean isHeldByThread(long threadId)
RLock
isHeldByThread
in interface RLock
threadId
- Thread ID of locking threadtrue
if held by given thread
otherwise false
public RFuture<Integer> getHoldCountAsync()
RLockAsync
getHoldCountAsync
in interface RLockAsync
0
if this lock is not held by current threadpublic int getHoldCount()
RLock
getHoldCount
in interface RLock
0
if this lock is not held by current threadpublic RFuture<Boolean> deleteAsync()
RObjectAsync
deleteAsync
in interface RObjectAsync
deleteAsync
in class RedissonObject
true
if object was deleted false
if notpublic RFuture<Void> unlockAsync()
RLockAsync
unlockAsync
in interface RLockAsync
public RFuture<Void> unlockAsync(long threadId)
RLockAsync
IllegalMonitorStateException
if lock isn't locked by thread with specified threadId
.unlockAsync
in interface RLockAsync
threadId
- id of threadpublic RFuture<Void> lockAsync()
RLockAsync
lockAsync
in interface RLockAsync
public RFuture<Void> lockAsync(long leaseTime, TimeUnit unit)
RLockAsync
If the lock is not available then the current thread becomes
disabled for thread scheduling purposes and lies dormant until the
lock has been acquired.
If the lock is acquired, it is held until unlock
is invoked,
or until leaseTime milliseconds have passed
since the lock was granted - whichever comes first.
lockAsync
in interface RLockAsync
leaseTime
- the maximum time to hold the lock after granting it,
before automatically releasing it if it hasn't already been released by invoking unlock
.
If leaseTime is -1, hold the lock until explicitly unlocked.unit
- the time unit of the leaseTime
argumentpublic RFuture<Void> lockAsync(long currentThreadId)
RLockAsync
threadId
.lockAsync
in interface RLockAsync
currentThreadId
- id of threadpublic RFuture<Void> lockAsync(long leaseTime, TimeUnit unit, long currentThreadId)
RLockAsync
threadId
.
If the lock is not available then the current thread becomes
disabled for thread scheduling purposes and lies dormant until the
lock has been acquired.
If the lock is acquired, it is held until unlock
is invoked,
or until leaseTime milliseconds have passed
since the lock was granted - whichever comes first.
lockAsync
in interface RLockAsync
leaseTime
- the maximum time to hold the lock after granting it,
before automatically releasing it if it hasn't already been released by invoking unlock
.
If leaseTime is -1, hold the lock until explicitly unlocked.unit
- the time unit of the leaseTime
argumentcurrentThreadId
- id of threadpublic RFuture<Boolean> tryLockAsync()
RLockAsync
tryLockAsync
in interface RLockAsync
true
if lock acquired otherwise false
public RFuture<Boolean> tryLockAsync(long threadId)
RLockAsync
threadId
.tryLockAsync
in interface RLockAsync
threadId
- id of threadtrue
if lock acquired otherwise false
public RFuture<Boolean> tryLockAsync(long waitTime, TimeUnit unit)
RLockAsync
waitTime
time interval to acquire it.tryLockAsync
in interface RLockAsync
waitTime
- interval to acquire lockunit
- the time unit of the waitTime
argumenttrue
if lock acquired otherwise false
public RFuture<Boolean> tryLockAsync(long waitTime, long leaseTime, TimeUnit unit)
RLockAsync
waitTime
time interval to acquire it.
Lock will be release automatically after defined leaseTime
interval.tryLockAsync
in interface RLockAsync
waitTime
- time interval to acquire lockleaseTime
- time interval after which lock will be released automaticallyunit
- the time unit of the waitTime
and leaseTime
argumentstrue
if lock acquired otherwise false
public RFuture<Boolean> tryLockAsync(long waitTime, long leaseTime, TimeUnit unit, long currentThreadId)
RLockAsync
threadId
. If the lock is not available waits
up to specified waitTime
time interval to acquire it.
Lock will be release automatically after defined leaseTime
interval.tryLockAsync
in interface RLockAsync
waitTime
- time interval to acquire lockleaseTime
- time interval after which lock will be released automaticallyunit
- the time unit of the waitTime
and leaseTime
argumentscurrentThreadId
- id of threadtrue
if lock acquired otherwise false
public boolean expire(long timeToLive, TimeUnit timeUnit)
RExpirable
expire
in interface RExpirable
timeToLive
- - timeout before object will be deletedtimeUnit
- - timeout time unittrue
if the timeout was set and false
if notpublic RFuture<Boolean> expireAsync(long timeToLive, TimeUnit timeUnit)
RExpirableAsync
expireAsync
in interface RExpirableAsync
timeToLive
- - timeout before object will be deletedtimeUnit
- - timeout time unittrue
if the timeout was set and false
if notpublic boolean expireAt(long timestamp)
RExpirable
expireAt
in interface RExpirable
timestamp
- - expire date in milliseconds (Unix timestamp)true
if the timeout was set and false
if notpublic RFuture<Boolean> expireAtAsync(long timestamp)
RExpirableAsync
expireAtAsync
in interface RExpirableAsync
timestamp
- - expire date in milliseconds (Unix timestamp)true
if the timeout was set and false
if notpublic boolean expireAt(Date timestamp)
RExpirable
expireAt
in interface RExpirable
timestamp
- - expire datetrue
if the timeout was set and false
if notpublic RFuture<Boolean> expireAtAsync(Date timestamp)
RExpirableAsync
expireAtAsync
in interface RExpirableAsync
timestamp
- - expire datetrue
if the timeout was set and false
if notpublic boolean clearExpire()
RExpirable
clearExpire
in interface RExpirable
true
if timeout was removed
false
if object does not exist or does not have an associated timeoutpublic RFuture<Boolean> clearExpireAsync()
RExpirableAsync
clearExpireAsync
in interface RExpirableAsync
true
if the timeout was cleared and false
if notpublic long remainTimeToLive()
RExpirable
remainTimeToLive
in interface RExpirable
public RFuture<Long> remainTimeToLiveAsync()
RExpirableAsync
remainTimeToLiveAsync
in interface RExpirableAsync
Copyright © 2014–2019 The Redisson Project. All rights reserved.