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 Stringacquire()Acquires a permit and returns its id.Stringacquire(long leaseTime, TimeUnit timeUnit)Acquires a permit with definedleaseTimeand return its id.RFuture<String>acquireAsync()Acquires a permit and returns its id.RFuture<String>acquireAsync(long leaseTime, TimeUnit timeUnit)Acquires a permit with definedleaseTimeand return its id.voidaddPermits(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.intavailablePermits()Returns amount of available permits.RFuture<Integer>availablePermitsAsync()Returns amount of available permits.booleanclearExpire()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 modebooleanexpire(long timeToLive, TimeUnit timeUnit)Set a timeout for object.booleanexpire(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.booleanexpireAt(long timestamp)UseRExpirable.expire(Instant)insteadbooleanexpireAt(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 StringgenerateId()static StringgetChannelName(String name)voidrelease(String permitId)Releases a permit by its id.RFuture<Void>releaseAsync(String permitId)Releases a permit by its id.longremainTimeToLive()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.StringtryAcquire()Tries to acquire currently available permit and return its id.StringtryAcquire(long waitTime, long ttl, TimeUnit unit)Tries to acquire currently available permit with definedleaseTimeand return its id.StringtryAcquire(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 definedleaseTimeand return its id.RFuture<String>tryAcquireAsync(long waitTime, TimeUnit unit)Tries to acquire currently available permit and return its id.booleantryRelease(String permitId)Tries to release permit by its id.RFuture<Boolean>tryReleaseAsync(String permitId)Tries to release permit by its id.booleantrySetPermits(int permits)Tries to set number of permits.RFuture<Boolean>trySetPermitsAsync(int permits)Tries to set number of permits.booleanupdateLeaseTime(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:RPermitExpirableSemaphoreAcquires a permit and returns its id. Waits if necessary until a permit became available.- Specified by:
acquirein 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:RPermitExpirableSemaphoreAcquires a permit with definedleaseTimeand return its id. Waits if necessary until a permit became available.- Specified by:
acquirein 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:RPermitExpirableSemaphoreAsyncAcquires a permit with definedleaseTimeand return its id. Waits if necessary until a permit became available.- Specified by:
acquireAsyncin interfaceRPermitExpirableSemaphoreAsync- Parameters:
leaseTime- permit lease timetimeUnit- time unit- Returns:
- permit id
-
acquireAsync
public RFuture<String> acquireAsync()
Description copied from interface:RPermitExpirableSemaphoreAsyncAcquires a permit and returns its id. Waits if necessary until a permit became available.- Specified by:
acquireAsyncin interfaceRPermitExpirableSemaphoreAsync- Returns:
- permit id
-
tryAcquire
public String tryAcquire()
Description copied from interface:RPermitExpirableSemaphoreTries to acquire currently available permit and return its id.- Specified by:
tryAcquirein interfaceRPermitExpirableSemaphore- Returns:
- permit id if a permit was acquired and
nullotherwise
-
tryAcquireAsync
public RFuture<String> tryAcquireAsync()
Description copied from interface:RPermitExpirableSemaphoreAsyncTries to acquire currently available permit and return its id.- Specified by:
tryAcquireAsyncin interfaceRPermitExpirableSemaphoreAsync- Returns:
- permit id if a permit was acquired and
nullotherwise
-
generateId
protected String generateId()
-
tryAcquireAsync
public RFuture<String> tryAcquireAsync(long waitTime, TimeUnit unit)
Description copied from interface:RPermitExpirableSemaphoreAsyncTries to acquire currently available permit and return its id. Waits up to definedwaitTimeif necessary until a permit became available.- Specified by:
tryAcquireAsyncin interfaceRPermitExpirableSemaphoreAsync- Parameters:
waitTime- the maximum time to waitunit- the time unit- Returns:
- permit id if a permit was acquired and
nullif 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:RPermitExpirableSemaphoreTries to acquire currently available permit with definedleaseTimeand return its id. Waits up to definedwaitTimeif necessary until a permit became available.- Specified by:
tryAcquirein 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
nullif 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:RPermitExpirableSemaphoreAsyncTries to acquire currently available permit with definedleaseTimeand return its id. Waits up to definedwaitTimeif necessary until a permit became available.- Specified by:
tryAcquireAsyncin 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
nullif the waiting time elapsed before a permit was acquired
-
tryAcquire
public String tryAcquire(long waitTime, TimeUnit unit) throws InterruptedException
Description copied from interface:RPermitExpirableSemaphoreTries to acquire currently available permit and return its id. Waits up to definedwaitTimeif necessary until a permit became available.- Specified by:
tryAcquirein interfaceRPermitExpirableSemaphore- Parameters:
waitTime- the maximum time to waitunit- the time unit- Returns:
- permit id if a permit was acquired and
nullif 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:RPermitExpirableSemaphoreReleases 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:
releasein interfaceRPermitExpirableSemaphore- Parameters:
permitId- - permit id
-
tryRelease
public boolean tryRelease(String permitId)
Description copied from interface:RPermitExpirableSemaphoreTries to release permit by its id.- Specified by:
tryReleasein interfaceRPermitExpirableSemaphore- Parameters:
permitId- permit id- Returns:
trueif a permit has been released andfalseotherwise
-
tryReleaseAsync
public RFuture<Boolean> tryReleaseAsync(String permitId)
Description copied from interface:RPermitExpirableSemaphoreAsyncTries to release permit by its id.- Specified by:
tryReleaseAsyncin interfaceRPermitExpirableSemaphoreAsync- Parameters:
permitId- permit id- Returns:
trueif a permit has been released andfalseotherwise
-
sizeInMemoryAsync
public RFuture<Long> sizeInMemoryAsync()
Description copied from interface:RObjectAsyncReturns bytes amount used by object in Redis memory.- Specified by:
sizeInMemoryAsyncin interfaceRObjectAsync- Overrides:
sizeInMemoryAsyncin classRedissonObject- Returns:
- size in bytes
-
deleteAsync
public RFuture<Boolean> deleteAsync()
Description copied from interface:RObjectAsyncDelete object in async mode- Specified by:
deleteAsyncin interfaceRObjectAsync- Overrides:
deleteAsyncin classRedissonObject- Returns:
trueif object was deletedfalseif not
-
expireAsync
public RFuture<Boolean> expireAsync(long timeToLive, TimeUnit timeUnit)
Description copied from interface:RExpirableAsyncSet a timeout for object in async mode. After the timeout has expired, the key will automatically be deleted.- Specified by:
expireAsyncin interfaceRExpirableAsync- Parameters:
timeToLive- - timeout before object will be deletedtimeUnit- - timeout time unit- Returns:
trueif the timeout was set andfalseif not
-
clearExpireAsync
public RFuture<Boolean> clearExpireAsync()
Description copied from interface:RExpirableAsyncClear an expire timeout or expire date for object in async mode. Object will not be deleted.- Specified by:
clearExpireAsyncin interfaceRExpirableAsync- Returns:
trueif the timeout was cleared andfalseif not
-
releaseAsync
public RFuture<Void> releaseAsync(String permitId)
Description copied from interface:RPermitExpirableSemaphoreAsyncReleases 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:
releaseAsyncin interfaceRPermitExpirableSemaphoreAsync- Parameters:
permitId- - permit id- Returns:
- void
-
availablePermits
public int availablePermits()
Description copied from interface:RPermitExpirableSemaphoreReturns amount of available permits.- Specified by:
availablePermitsin interfaceRPermitExpirableSemaphore- Returns:
- number of permits
-
availablePermitsAsync
public RFuture<Integer> availablePermitsAsync()
Description copied from interface:RPermitExpirableSemaphoreAsyncReturns amount of available permits.- Specified by:
availablePermitsAsyncin interfaceRPermitExpirableSemaphoreAsync- Returns:
- number of permits
-
trySetPermits
public boolean trySetPermits(int permits)
Description copied from interface:RPermitExpirableSemaphoreTries to set number of permits.- Specified by:
trySetPermitsin interfaceRPermitExpirableSemaphore- Parameters:
permits- - number of permits- Returns:
trueif permits has been set successfully, otherwisefalse.
-
trySetPermitsAsync
public RFuture<Boolean> trySetPermitsAsync(int permits)
Description copied from interface:RPermitExpirableSemaphoreAsyncTries to set number of permits.- Specified by:
trySetPermitsAsyncin interfaceRPermitExpirableSemaphoreAsync- Parameters:
permits- - number of permits- Returns:
trueif permits has been set successfully, otherwisefalse.
-
addPermits
public void addPermits(int permits)
Description copied from interface:RPermitExpirableSemaphoreIncreases or decreases the number of available permits by defined value.- Specified by:
addPermitsin interfaceRPermitExpirableSemaphore- Parameters:
permits- amount of permits to add/remove
-
addPermitsAsync
public RFuture<Void> addPermitsAsync(int permits)
Description copied from interface:RPermitExpirableSemaphoreAsyncIncreases or decreases the number of available permits by defined value.- Specified by:
addPermitsAsyncin 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:RPermitExpirableSemaphoreAsyncOverrides and updates lease time for defined permit id.- Specified by:
updateLeaseTimeAsyncin interfaceRPermitExpirableSemaphoreAsync- Parameters:
permitId- permit idleaseTime- permit lease time, use -1 to make it permanentunit- the time unit- Returns:
trueif permits has been updated successfully, otherwisefalse.
-
updateLeaseTime
public boolean updateLeaseTime(String permitId, long leaseTime, TimeUnit unit)
Description copied from interface:RPermitExpirableSemaphoreOverrides and updates lease time for defined permit id.- Specified by:
updateLeaseTimein interfaceRPermitExpirableSemaphore- Parameters:
permitId- permit idleaseTime- permit lease time, use -1 to make it permanentunit- the time unit- Returns:
trueif permits has been updated successfully, otherwisefalse.
-
expire
public boolean expire(long timeToLive, TimeUnit timeUnit)Description copied from interface:RExpirableSet a timeout for object. After the timeout has expired, the key will automatically be deleted.- Specified by:
expirein interfaceRExpirable- Parameters:
timeToLive- - timeout before object will be deletedtimeUnit- - timeout time unit- Returns:
trueif the timeout was set andfalseif not
-
expireAt
public boolean expireAt(long timestamp)
Description copied from interface:RExpirableUseRExpirable.expire(Instant)instead- Specified by:
expireAtin interfaceRExpirable- Parameters:
timestamp- - expire date in milliseconds (Unix timestamp)- Returns:
trueif the timeout was set andfalseif not
-
expireAtAsync
public RFuture<Boolean> expireAtAsync(long timestamp)
Description copied from interface:RExpirableAsyncUseRExpirableAsync.expireAsync(Instant)instead- Specified by:
expireAtAsyncin interfaceRExpirableAsync- Parameters:
timestamp- - expire date in milliseconds (Unix timestamp)- Returns:
trueif the timeout was set andfalseif not
-
expire
public boolean expire(Instant instant)
Description copied from interface:RExpirableSet an expire date for object. When expire date comes the key will automatically be deleted.- Specified by:
expirein interfaceRExpirable- Parameters:
instant- - expire date- Returns:
trueif the timeout was set andfalseif not
-
expireAsync
public RFuture<Boolean> expireAsync(Instant instant)
Description copied from interface:RExpirableAsyncSet an expire date for object. When expire date comes the key will automatically be deleted.- Specified by:
expireAsyncin interfaceRExpirableAsync- Parameters:
instant- - expire date- Returns:
trueif the timeout was set andfalseif not
-
expireAt
public boolean expireAt(Date timestamp)
Description copied from interface:RExpirableUseRExpirable.expire(Instant)instead- Specified by:
expireAtin interfaceRExpirable- Parameters:
timestamp- - expire date- Returns:
trueif the timeout was set andfalseif not
-
expireAtAsync
public RFuture<Boolean> expireAtAsync(Date timestamp)
Description copied from interface:RExpirableAsyncUseRExpirableAsync.expireAsync(Instant)instead- Specified by:
expireAtAsyncin interfaceRExpirableAsync- Parameters:
timestamp- - expire date- Returns:
trueif the timeout was set andfalseif not
-
clearExpire
public boolean clearExpire()
Description copied from interface:RExpirableClear an expire timeout or expire date for object.- Specified by:
clearExpirein interfaceRExpirable- Returns:
trueif timeout was removedfalseif object does not exist or does not have an associated timeout
-
remainTimeToLive
public long remainTimeToLive()
Description copied from interface:RExpirableRemaining time to live of Redisson object that has a timeout- Specified by:
remainTimeToLivein 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:RExpirableAsyncRemaining time to live of Redisson object that has a timeout- Specified by:
remainTimeToLiveAsyncin 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)
-
-