Package org.redisson
Class RedissonPermitExpirableSemaphore
- java.lang.Object
-
- org.redisson.RedissonObject
-
- org.redisson.RedissonPermitExpirableSemaphore
-
- All Implemented Interfaces:
RExpirable
,RExpirableAsync
,RObject
,RObjectAsync
,RPermitExpirableSemaphore
,RPermitExpirableSemaphoreAsync
public class RedissonPermitExpirableSemaphore extends RedissonObject implements RPermitExpirableSemaphore
- Author:
- Nikita Koksharov
-
-
Field Summary
-
Fields inherited from class org.redisson.RedissonObject
codec, name
-
-
Constructor Summary
Constructors Constructor Description RedissonPermitExpirableSemaphore(CommandAsyncExecutor commandExecutor, String name)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description String
acquire()
Acquires a permit and returns its id.String
acquire(long leaseTime, TimeUnit timeUnit)
Acquires a permit with definedleaseTime
and return its id.RFuture<String>
acquireAsync()
Acquires a permit and returns its id.RFuture<String>
acquireAsync(long leaseTime, TimeUnit timeUnit)
Acquires a permit with definedleaseTime
and return its id.void
addPermits(int permits)
Increases or decreases the number of available permits by defined value.RFuture<Void>
addPermitsAsync(int permits)
Increases or decreases the number of available permits by defined value.int
availablePermits()
Returns amount of available permits.RFuture<Integer>
availablePermitsAsync()
Returns amount of available permits.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.protected RFuture<Boolean>
clearExpireAsync(String... keys)
RFuture<Boolean>
deleteAsync()
Delete object in async modeboolean
expire(long timeToLive, TimeUnit timeUnit)
Set a timeout for object.boolean
expire(Instant instant)
Set an expire date for object.RFuture<Boolean>
expireAsync(long timeToLive, TimeUnit timeUnit)
Set a timeout for object in async mode.protected RFuture<Boolean>
expireAsync(long timeToLive, TimeUnit timeUnit, String... keys)
RFuture<Boolean>
expireAsync(Instant instant)
Set an expire date for object.boolean
expireAt(long timestamp)
UseRExpirable.expire(Instant)
insteadboolean
expireAt(Date timestamp)
UseRExpirable.expire(Instant)
insteadRFuture<Boolean>
expireAtAsync(long timestamp)
UseRExpirableAsync.expireAsync(Instant)
insteadprotected RFuture<Boolean>
expireAtAsync(long timestamp, String... keys)
RFuture<Boolean>
expireAtAsync(Date timestamp)
UseRExpirableAsync.expireAsync(Instant)
insteadprotected String
generateId()
static String
getChannelName(String name)
void
release(String permitId)
Releases a permit by its id.RFuture<Void>
releaseAsync(String permitId)
Releases a permit by its id.long
remainTimeToLive()
Remaining time to live of Redisson object that has a timeoutRFuture<Long>
remainTimeToLiveAsync()
Remaining time to live of Redisson object that has a timeoutRFuture<Long>
sizeInMemoryAsync()
Returns bytes amount used by object in Redis memory.String
tryAcquire()
Tries to acquire currently available permit and return its id.String
tryAcquire(long waitTime, long ttl, TimeUnit unit)
Tries to acquire currently available permit with definedleaseTime
and return its id.String
tryAcquire(long waitTime, TimeUnit unit)
Tries to acquire currently available permit and return its id.RFuture<String>
tryAcquireAsync()
Tries to acquire currently available permit and return its id.RFuture<String>
tryAcquireAsync(int permits, long timeoutDate)
RFuture<String>
tryAcquireAsync(long waitTime, long ttl, TimeUnit unit)
Tries to acquire currently available permit with definedleaseTime
and return its id.RFuture<String>
tryAcquireAsync(long waitTime, TimeUnit unit)
Tries to acquire currently available permit and return its id.boolean
tryRelease(String permitId)
Tries to release permit by its id.RFuture<Boolean>
tryReleaseAsync(String permitId)
Tries to release permit by its id.boolean
trySetPermits(int permits)
Tries to set number of permits.RFuture<Boolean>
trySetPermitsAsync(int permits)
Tries to set number of permits.boolean
updateLeaseTime(String permitId, long leaseTime, TimeUnit unit)
Overrides and updates lease time for defined permit id.RFuture<Boolean>
updateLeaseTimeAsync(String permitId, long leaseTime, TimeUnit unit)
Overrides and updates lease time for defined permit id.-
Methods inherited from class org.redisson.RedissonObject
addListener, addListener, addListenerAsync, addListenerAsync, copy, copyAsync, delete, deleteAsync, dump, dumpAsync, encode, encode, encode, encode, encodeMapKey, encodeMapKeys, encodeMapValue, encodeMapValues, get, getCodec, getIdleTime, getIdleTimeAsync, getLockByMapKey, getLockByValue, getName, getRawName, getRawName, isExists, isExistsAsync, migrate, migrateAsync, move, moveAsync, prefixName, removeListener, removeListenerAsync, removeListenersAsync, rename, renameAsync, renamenx, renamenxAsync, restore, restore, restoreAndReplace, restoreAndReplace, restoreAndReplaceAsync, restoreAndReplaceAsync, restoreAsync, restoreAsync, setName, sizeInMemory, sizeInMemoryAsync, sizeInMemoryAsync, suffixName, toSeconds, toStream, touch, touchAsync, unlink, unlinkAsync
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.redisson.api.RExpirable
clearExpire, expire, expire, expireAt, expireAt, remainTimeToLive
-
Methods inherited from interface org.redisson.api.RExpirableAsync
expireAsync, expireAtAsync, expireAtAsync, remainTimeToLiveAsync
-
Methods inherited from interface org.redisson.api.RObject
addListener, copy, delete, dump, getCodec, getIdleTime, getName, isExists, migrate, move, removeListener, rename, renamenx, restore, restore, restoreAndReplace, restoreAndReplace, sizeInMemory, touch, unlink
-
Methods inherited from interface org.redisson.api.RObjectAsync
addListenerAsync, copyAsync, dumpAsync, getIdleTimeAsync, isExistsAsync, migrateAsync, moveAsync, removeListenerAsync, renameAsync, renamenxAsync, restoreAndReplaceAsync, restoreAndReplaceAsync, restoreAsync, restoreAsync, touchAsync, unlinkAsync
-
-
-
-
Constructor Detail
-
RedissonPermitExpirableSemaphore
public RedissonPermitExpirableSemaphore(CommandAsyncExecutor commandExecutor, String name)
-
-
Method Detail
-
acquire
public String acquire() throws InterruptedException
Description copied from interface:RPermitExpirableSemaphore
Acquires a permit and returns its id. Waits if necessary until a permit became available.- Specified by:
acquire
in interfaceRPermitExpirableSemaphore
- Returns:
- permit id
- Throws:
InterruptedException
- if the current thread is interrupted
-
acquire
public String acquire(long leaseTime, TimeUnit timeUnit) throws InterruptedException
Description copied from interface:RPermitExpirableSemaphore
Acquires a permit with definedleaseTime
and return its id. Waits if necessary until a permit became available.- Specified by:
acquire
in interfaceRPermitExpirableSemaphore
- Parameters:
leaseTime
- permit lease timetimeUnit
- time unit- Returns:
- permit id
- Throws:
InterruptedException
- if the current thread is interrupted
-
acquireAsync
public RFuture<String> acquireAsync(long leaseTime, TimeUnit timeUnit)
Description copied from interface:RPermitExpirableSemaphoreAsync
Acquires a permit with definedleaseTime
and return its id. Waits if necessary until a permit became available.- Specified by:
acquireAsync
in interfaceRPermitExpirableSemaphoreAsync
- Parameters:
leaseTime
- permit lease timetimeUnit
- time unit- Returns:
- permit id
-
acquireAsync
public RFuture<String> acquireAsync()
Description copied from interface:RPermitExpirableSemaphoreAsync
Acquires a permit and returns its id. Waits if necessary until a permit became available.- Specified by:
acquireAsync
in interfaceRPermitExpirableSemaphoreAsync
- Returns:
- permit id
-
tryAcquire
public String tryAcquire()
Description copied from interface:RPermitExpirableSemaphore
Tries to acquire currently available permit and return its id.- Specified by:
tryAcquire
in interfaceRPermitExpirableSemaphore
- Returns:
- permit id if a permit was acquired and
null
otherwise
-
tryAcquireAsync
public RFuture<String> tryAcquireAsync()
Description copied from interface:RPermitExpirableSemaphoreAsync
Tries to acquire currently available permit and return its id.- Specified by:
tryAcquireAsync
in interfaceRPermitExpirableSemaphoreAsync
- Returns:
- permit id if a permit was acquired and
null
otherwise
-
generateId
protected String generateId()
-
tryAcquireAsync
public RFuture<String> tryAcquireAsync(long waitTime, TimeUnit unit)
Description copied from interface:RPermitExpirableSemaphoreAsync
Tries to acquire currently available permit and return its id. Waits up to definedwaitTime
if necessary until a permit became available.- Specified by:
tryAcquireAsync
in interfaceRPermitExpirableSemaphoreAsync
- Parameters:
waitTime
- the maximum time to waitunit
- the time unit- Returns:
- permit id if a permit was acquired and
null
if the waiting time elapsed before a permit was acquired
-
tryAcquire
public String tryAcquire(long waitTime, long ttl, TimeUnit unit) throws InterruptedException
Description copied from interface:RPermitExpirableSemaphore
Tries to acquire currently available permit with definedleaseTime
and return its id. Waits up to definedwaitTime
if necessary until a permit became available.- Specified by:
tryAcquire
in interfaceRPermitExpirableSemaphore
- Parameters:
waitTime
- the maximum time to waitttl
- permit lease time, use -1 to make it permanentunit
- the time unit- Returns:
- permit id if a permit was acquired and
null
if the waiting time elapsed before a permit was acquired - Throws:
InterruptedException
- if the current thread is interrupted
-
tryAcquireAsync
public RFuture<String> tryAcquireAsync(long waitTime, long ttl, TimeUnit unit)
Description copied from interface:RPermitExpirableSemaphoreAsync
Tries to acquire currently available permit with definedleaseTime
and return its id. Waits up to definedwaitTime
if necessary until a permit became available.- Specified by:
tryAcquireAsync
in interfaceRPermitExpirableSemaphoreAsync
- Parameters:
waitTime
- the maximum time to waitttl
- permit lease time, use -1 to make it permanentunit
- the time unit- Returns:
- permit id if a permit was acquired and
null
if the waiting time elapsed before a permit was acquired
-
tryAcquire
public String tryAcquire(long waitTime, TimeUnit unit) throws InterruptedException
Description copied from interface:RPermitExpirableSemaphore
Tries to acquire currently available permit and return its id. Waits up to definedwaitTime
if necessary until a permit became available.- Specified by:
tryAcquire
in interfaceRPermitExpirableSemaphore
- Parameters:
waitTime
- the maximum time to waitunit
- the time unit- Returns:
- permit id if a permit was acquired and
null
if the waiting time elapsed before a permit was acquired - Throws:
InterruptedException
- if the current thread is interrupted
-
release
public void release(String permitId)
Description copied from interface:RPermitExpirableSemaphore
Releases a permit by its id. Increases the number of available permits. Throws an exception if permit id doesn't exist or has already been released.- Specified by:
release
in interfaceRPermitExpirableSemaphore
- Parameters:
permitId
- - permit id
-
tryRelease
public boolean tryRelease(String permitId)
Description copied from interface:RPermitExpirableSemaphore
Tries to release permit by its id.- Specified by:
tryRelease
in interfaceRPermitExpirableSemaphore
- Parameters:
permitId
- permit id- Returns:
true
if a permit has been released andfalse
otherwise
-
tryReleaseAsync
public RFuture<Boolean> tryReleaseAsync(String permitId)
Description copied from interface:RPermitExpirableSemaphoreAsync
Tries to release permit by its id.- Specified by:
tryReleaseAsync
in interfaceRPermitExpirableSemaphoreAsync
- Parameters:
permitId
- permit id- Returns:
true
if a permit has been released andfalse
otherwise
-
sizeInMemoryAsync
public RFuture<Long> sizeInMemoryAsync()
Description copied from interface:RObjectAsync
Returns bytes amount used by object in Redis memory.- Specified by:
sizeInMemoryAsync
in interfaceRObjectAsync
- Overrides:
sizeInMemoryAsync
in classRedissonObject
- Returns:
- size in bytes
-
deleteAsync
public RFuture<Boolean> deleteAsync()
Description copied from interface:RObjectAsync
Delete object in async mode- Specified by:
deleteAsync
in interfaceRObjectAsync
- Overrides:
deleteAsync
in classRedissonObject
- Returns:
true
if object was deletedfalse
if not
-
expireAsync
public RFuture<Boolean> expireAsync(long timeToLive, TimeUnit timeUnit)
Description copied from interface:RExpirableAsync
Set a timeout for object in async mode. After the timeout has expired, the key will automatically be deleted.- Specified by:
expireAsync
in interfaceRExpirableAsync
- Parameters:
timeToLive
- - timeout before object will be deletedtimeUnit
- - timeout time unit- Returns:
true
if the timeout was set andfalse
if not
-
clearExpireAsync
public RFuture<Boolean> clearExpireAsync()
Description copied from interface:RExpirableAsync
Clear an expire timeout or expire date for object in async mode. Object will not be deleted.- Specified by:
clearExpireAsync
in interfaceRExpirableAsync
- Returns:
true
if the timeout was cleared andfalse
if not
-
releaseAsync
public RFuture<Void> releaseAsync(String permitId)
Description copied from interface:RPermitExpirableSemaphoreAsync
Releases a permit by its id. Increases the number of available permits. Throws an exception if permit id doesn't exist or has already been released.- Specified by:
releaseAsync
in interfaceRPermitExpirableSemaphoreAsync
- Parameters:
permitId
- - permit id- Returns:
- void
-
availablePermits
public int availablePermits()
Description copied from interface:RPermitExpirableSemaphore
Returns amount of available permits.- Specified by:
availablePermits
in interfaceRPermitExpirableSemaphore
- Returns:
- number of permits
-
availablePermitsAsync
public RFuture<Integer> availablePermitsAsync()
Description copied from interface:RPermitExpirableSemaphoreAsync
Returns amount of available permits.- Specified by:
availablePermitsAsync
in interfaceRPermitExpirableSemaphoreAsync
- Returns:
- number of permits
-
trySetPermits
public boolean trySetPermits(int permits)
Description copied from interface:RPermitExpirableSemaphore
Tries to set number of permits.- Specified by:
trySetPermits
in interfaceRPermitExpirableSemaphore
- Parameters:
permits
- - number of permits- Returns:
true
if permits has been set successfully, otherwisefalse
.
-
trySetPermitsAsync
public RFuture<Boolean> trySetPermitsAsync(int permits)
Description copied from interface:RPermitExpirableSemaphoreAsync
Tries to set number of permits.- Specified by:
trySetPermitsAsync
in interfaceRPermitExpirableSemaphoreAsync
- Parameters:
permits
- - number of permits- Returns:
true
if permits has been set successfully, otherwisefalse
.
-
addPermits
public void addPermits(int permits)
Description copied from interface:RPermitExpirableSemaphore
Increases or decreases the number of available permits by defined value.- Specified by:
addPermits
in interfaceRPermitExpirableSemaphore
- Parameters:
permits
- amount of permits to add/remove
-
addPermitsAsync
public RFuture<Void> addPermitsAsync(int permits)
Description copied from interface:RPermitExpirableSemaphoreAsync
Increases or decreases the number of available permits by defined value.- Specified by:
addPermitsAsync
in interfaceRPermitExpirableSemaphoreAsync
- Parameters:
permits
- amount of permits to add/remove- Returns:
- void
-
updateLeaseTimeAsync
public RFuture<Boolean> updateLeaseTimeAsync(String permitId, long leaseTime, TimeUnit unit)
Description copied from interface:RPermitExpirableSemaphoreAsync
Overrides and updates lease time for defined permit id.- Specified by:
updateLeaseTimeAsync
in interfaceRPermitExpirableSemaphoreAsync
- Parameters:
permitId
- permit idleaseTime
- permit lease time, use -1 to make it permanentunit
- the time unit- Returns:
true
if permits has been updated successfully, otherwisefalse
.
-
updateLeaseTime
public boolean updateLeaseTime(String permitId, long leaseTime, TimeUnit unit)
Description copied from interface:RPermitExpirableSemaphore
Overrides and updates lease time for defined permit id.- Specified by:
updateLeaseTime
in interfaceRPermitExpirableSemaphore
- Parameters:
permitId
- permit idleaseTime
- permit lease time, use -1 to make it permanentunit
- the time unit- Returns:
true
if permits has been updated successfully, otherwisefalse
.
-
expire
public boolean expire(long timeToLive, TimeUnit timeUnit)
Description copied from interface:RExpirable
Set a timeout for object. After the timeout has expired, the key will automatically be deleted.- Specified by:
expire
in interfaceRExpirable
- Parameters:
timeToLive
- - timeout before object will be deletedtimeUnit
- - timeout time unit- Returns:
true
if the timeout was set andfalse
if not
-
expireAt
public boolean expireAt(long timestamp)
Description copied from interface:RExpirable
UseRExpirable.expire(Instant)
instead- Specified by:
expireAt
in interfaceRExpirable
- Parameters:
timestamp
- - expire date in milliseconds (Unix timestamp)- Returns:
true
if the timeout was set andfalse
if not
-
expireAtAsync
public RFuture<Boolean> expireAtAsync(long timestamp)
Description copied from interface:RExpirableAsync
UseRExpirableAsync.expireAsync(Instant)
instead- Specified by:
expireAtAsync
in interfaceRExpirableAsync
- Parameters:
timestamp
- - expire date in milliseconds (Unix timestamp)- Returns:
true
if the timeout was set andfalse
if not
-
expire
public boolean expire(Instant instant)
Description copied from interface:RExpirable
Set an expire date for object. When expire date comes the key will automatically be deleted.- Specified by:
expire
in interfaceRExpirable
- Parameters:
instant
- - expire date- Returns:
true
if the timeout was set andfalse
if not
-
expireAsync
public RFuture<Boolean> expireAsync(Instant instant)
Description copied from interface:RExpirableAsync
Set an expire date for object. When expire date comes the key will automatically be deleted.- Specified by:
expireAsync
in interfaceRExpirableAsync
- Parameters:
instant
- - expire date- Returns:
true
if the timeout was set andfalse
if not
-
expireAt
public boolean expireAt(Date timestamp)
Description copied from interface:RExpirable
UseRExpirable.expire(Instant)
instead- Specified by:
expireAt
in interfaceRExpirable
- Parameters:
timestamp
- - expire date- Returns:
true
if the timeout was set andfalse
if not
-
expireAtAsync
public RFuture<Boolean> expireAtAsync(Date timestamp)
Description copied from interface:RExpirableAsync
UseRExpirableAsync.expireAsync(Instant)
instead- Specified by:
expireAtAsync
in interfaceRExpirableAsync
- Parameters:
timestamp
- - expire date- Returns:
true
if the timeout was set andfalse
if not
-
clearExpire
public boolean clearExpire()
Description copied from interface:RExpirable
Clear an expire timeout or expire date for object.- Specified by:
clearExpire
in interfaceRExpirable
- Returns:
true
if timeout was removedfalse
if object does not exist or does not have an associated timeout
-
remainTimeToLive
public long remainTimeToLive()
Description copied from interface:RExpirable
Remaining time to live of Redisson object that has a timeout- Specified by:
remainTimeToLive
in interfaceRExpirable
- Returns:
- time in milliseconds -2 if the key does not exist. -1 if the key exists but has no associated expire.
-
remainTimeToLiveAsync
public RFuture<Long> remainTimeToLiveAsync()
Description copied from interface:RExpirableAsync
Remaining time to live of Redisson object that has a timeout- Specified by:
remainTimeToLiveAsync
in interfaceRExpirableAsync
- Returns:
- time in milliseconds -2 if the key does not exist. -1 if the key exists but has no associated expire.
-
expireAsync
protected RFuture<Boolean> expireAsync(long timeToLive, TimeUnit timeUnit, String... keys)
-
-