Package org.redisson.api
Interface RPermitExpirableSemaphore
- All Superinterfaces:
RExpirable,RExpirableAsync,RObject,RObjectAsync,RPermitExpirableSemaphoreAsync
- All Known Implementing Classes:
RedissonPermitExpirableSemaphore
Semaphore object with lease time parameter support for each acquired permit.
Each permit identified by own id and could be released only using its id. Permit id is a 128-bits unique random identifier generated each time during acquiring.
Works in non-fair mode. Therefore order of acquiring is unpredictable.
- Author:
- Nikita Koksharov
-
Method Summary
Modifier and TypeMethodDescriptionacquire()Acquires a permit and returns its id.acquire(int permits) Acquires defined amount ofpermits.Acquires defined amount ofpermitswith definedleaseTimeand returns ids.Acquires a permit with definedleaseTimeand return its id.intReturns the number of acquired permits.voidaddPermits(int permits) Increases or decreases the number of available permits by defined value.intReturns number of available permits.intReturns the number of permits.voidReleases a permit by its id.voidReleases permits by their ids.voidsetPermits(int permits) Sets the number of permits to the provided value.Tries to acquire currently available permit and return its id.tryAcquire(int permits) Tries to acquire defined amount of currently availablepermitsand returns ids.tryAcquire(int permits, long waitTime, long leaseTime, TimeUnit unit) Tries to acquire defined amount of currently availablepermitswith definedleaseTimeand return ids.tryAcquire(long waitTime, long leaseTime, TimeUnit unit) Tries to acquire currently available permit with definedleaseTimeand return its id.tryAcquire(long waitTime, TimeUnit unit) Tries to acquire currently available permit and return its id.booleantryRelease(String permitId) Tries to release permit by its id.inttryRelease(List<String> permitsIds) Tries to release permits by their ids.booleantrySetPermits(int permits) Tries to set the initial number of available permits.booleanupdateLeaseTime(String permitId, long leaseTime, TimeUnit unit) Overrides and updates lease time for defined permit id.Methods inherited from interface org.redisson.api.RExpirable
clearExpire, expire, expire, expire, expireAt, expireAt, expireIfGreater, expireIfGreater, expireIfLess, expireIfLess, expireIfNotSet, expireIfNotSet, expireIfSet, expireIfSet, getExpireTime, remainTimeToLiveMethods inherited from interface org.redisson.api.RExpirableAsync
clearExpireAsync, expireAsync, expireAsync, expireAsync, expireAtAsync, expireAtAsync, expireIfGreaterAsync, expireIfGreaterAsync, expireIfLessAsync, expireIfLessAsync, expireIfNotSetAsync, expireIfNotSetAsync, expireIfSetAsync, expireIfSetAsync, getExpireTimeAsync, remainTimeToLiveAsyncMethods inherited from interface org.redisson.api.RObject
addListener, copy, copy, copy, copyAndReplace, copyAndReplace, delete, dump, getCodec, getIdleTime, getName, isExists, migrate, move, removeListener, rename, renamenx, restore, restore, restoreAndReplace, restoreAndReplace, sizeInMemory, touch, unlinkMethods inherited from interface org.redisson.api.RObjectAsync
addListenerAsync, copyAndReplaceAsync, copyAndReplaceAsync, copyAsync, copyAsync, copyAsync, deleteAsync, dumpAsync, getIdleTimeAsync, isExistsAsync, migrateAsync, moveAsync, removeListenerAsync, renameAsync, renamenxAsync, restoreAndReplaceAsync, restoreAndReplaceAsync, restoreAsync, restoreAsync, sizeInMemoryAsync, touchAsync, unlinkAsyncMethods inherited from interface org.redisson.api.RPermitExpirableSemaphoreAsync
acquireAsync, acquireAsync, acquireAsync, acquireAsync, acquiredPermitsAsync, addPermitsAsync, availablePermitsAsync, getPermitsAsync, releaseAsync, releaseAsync, setPermitsAsync, tryAcquireAsync, tryAcquireAsync, tryAcquireAsync, tryAcquireAsync, tryAcquireAsync, tryReleaseAsync, tryReleaseAsync, trySetPermitsAsync, updateLeaseTimeAsync
-
Method Details
-
acquire
Acquires a permit and returns its id. Waits if necessary until a permit became available.- Returns:
- permit id
- Throws:
InterruptedException- if the current thread is interrupted
-
acquire
Acquires defined amount ofpermits. Waits if necessary until enough permits became available.- Parameters:
permits- the number of permits to acquire- Returns:
- permits ids
- Throws:
InterruptedException- if the current thread is interruptedIllegalArgumentException- ifpermitsis negative
-
acquire
Acquires a permit with definedleaseTimeand return its id. Waits if necessary until a permit became available.- Parameters:
leaseTime- permit lease timeunit- time unit- Returns:
- permit id
- Throws:
InterruptedException- if the current thread is interrupted
-
acquire
Acquires defined amount ofpermitswith definedleaseTimeand returns ids. Waits if necessary until enough permits became available.- Parameters:
permits- the number of permits to acquireleaseTime- permit lease timeunit- time unit- Returns:
- permits ids
- Throws:
InterruptedException- if the current thread is interruptedIllegalArgumentException- ifpermitsis negative
-
tryAcquire
String tryAcquire()Tries to acquire currently available permit and return its id.- Returns:
- permit id if a permit was acquired and
nullotherwise
-
tryAcquire
Tries to acquire defined amount of currently availablepermitsand returns ids.- Parameters:
permits- the number of permits to acquire- Returns:
- permits ids if permits were acquired and empty collection otherwise
- Throws:
IllegalArgumentException- ifpermitsis negative
-
tryAcquire
Tries to acquire currently available permit and return its id. Waits up to definedwaitTimeif necessary until a permit became available.- 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
-
tryAcquire
Tries to acquire currently available permit with definedleaseTimeand return its id. Waits up to definedwaitTimeif necessary until a permit became available.- Parameters:
waitTime- the maximum time to waitleaseTime- 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
-
tryAcquire
List<String> tryAcquire(int permits, long waitTime, long leaseTime, TimeUnit unit) throws InterruptedException Tries to acquire defined amount of currently availablepermitswith definedleaseTimeand return ids. Waits up to definedwaitTimeif necessary until enough permits became available.- Parameters:
permits- the number of permits to acquirewaitTime- the maximum time to waitleaseTime- permit lease time, use -1 to make it permanentunit- the time unit- Returns:
- permits ids if permits were acquired and empty collection if the waiting time elapsed before permits were acquired
- Throws:
InterruptedException- if the current thread is interruptedIllegalArgumentException- ifpermitsis negative
-
tryRelease
Tries to release permit by its id.- Parameters:
permitId- permit id- Returns:
trueif a permit has been released andfalseotherwise- Throws:
IllegalArgumentException- ifpermitIdis null
-
tryRelease
Tries to release permits by their ids.- Parameters:
permitsIds- - permits ids- Returns:
- amount of released permits
- Throws:
IllegalArgumentException- ifpermitsIdsis null or empty
-
release
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.- Parameters:
permitId- - permit id- Throws:
IllegalArgumentException- ifpermitIdis null
-
release
Releases permits by their ids. Increases the number of available permits. Throws an exception if permit id doesn't exist or has already been released.- Parameters:
permitsIds- - permits ids- Throws:
IllegalArgumentException- ifpermitsIdsis null or empty
-
availablePermits
int availablePermits()Returns number of available permits.- Returns:
- number of available permits
-
getPermits
int getPermits()Returns the number of permits.- Returns:
- number of permits
-
acquiredPermits
int acquiredPermits()Returns the number of acquired permits.- Returns:
- number of acquired permits
-
trySetPermits
boolean trySetPermits(int permits) Tries to set the initial number of available permits.- Parameters:
permits- - number of permits- Returns:
trueif permits has been set successfully, otherwisefalse.
-
setPermits
void setPermits(int permits) Sets the number of permits to the provided value. Calculates thedeltabetween the givenpermitsvalue and the current number of permits, then increases the number of available permits bydelta.- Parameters:
permits- - number of permits
-
addPermits
void addPermits(int permits) Increases or decreases the number of available permits by defined value.- Parameters:
permits- amount of permits to add/remove
-
updateLeaseTime
Overrides and updates lease time for defined permit id.- Parameters:
permitId- permit idleaseTime- permit lease time, use -1 to make it permanentunit- the time unit- Returns:
trueif permits has been updated successfully, otherwisefalse.
-