Package org.redisson.api
Interface RPermitExpirableSemaphoreAsync
- All Superinterfaces:
RExpirableAsync
,RObjectAsync
- All Known Subinterfaces:
RPermitExpirableSemaphore
- All Known Implementing Classes:
RedissonPermitExpirableSemaphore
Asynchronous interface for 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 TypeMethodDescriptionAcquires a permit and returns its id.acquireAsync
(int permits) Acquires defined amount ofpermits
and returns their ids.acquireAsync
(int permits, long leaseTime, TimeUnit unit) Acquires defined amount ofpermits
and return their ids.acquireAsync
(long leaseTime, TimeUnit unit) Acquires a permit with definedleaseTime
and return its id.Returns the number of acquired permits.addPermitsAsync
(int permits) Increases or decreases the number of available permits by defined value.Returns number of available permits.Returns the number of permits.releaseAsync
(String permitId) Releases a permit by its id.releaseAsync
(List<String> permitsIds) Releases permits by their ids.setPermitsAsync
(int permits) Sets the number of permits to the provided value.Tries to acquire currently available permit and return its id.tryAcquireAsync
(int permits) Tries to acquire defined amount of currently availablepermits
and returns their ids.tryAcquireAsync
(int permits, long waitTime, long leaseTime, TimeUnit unit) Tries to acquire defined amount of currently availablepermits
with definedleaseTime
and returns their ids.tryAcquireAsync
(long waitTime, long leaseTime, TimeUnit unit) Tries to acquire currently available permit with definedleaseTime
and return its id.tryAcquireAsync
(long waitTime, TimeUnit unit) Tries to acquire currently available permit and return its id.tryReleaseAsync
(String permitId) Tries to release permit by its id.tryReleaseAsync
(List<String> permitsIds) Tries to release defined permits by their ids.trySetPermitsAsync
(int permits) Tries to set number of available permits.updateLeaseTimeAsync
(String permitId, long leaseTime, TimeUnit unit) Overrides and updates lease time for defined permit id.Methods inherited from interface org.redisson.api.RExpirableAsync
clearExpireAsync, expireAsync, expireAsync, expireAsync, expireAtAsync, expireAtAsync, expireIfGreaterAsync, expireIfGreaterAsync, expireIfLessAsync, expireIfLessAsync, expireIfNotSetAsync, expireIfNotSetAsync, expireIfSetAsync, expireIfSetAsync, getExpireTimeAsync, remainTimeToLiveAsync
Methods inherited from interface org.redisson.api.RObjectAsync
addListenerAsync, copyAsync, deleteAsync, dumpAsync, getIdleTimeAsync, isExistsAsync, migrateAsync, moveAsync, removeListenerAsync, renameAsync, renamenxAsync, restoreAndReplaceAsync, restoreAndReplaceAsync, restoreAsync, restoreAsync, sizeInMemoryAsync, touchAsync, unlinkAsync
-
Method Details
-
acquireAsync
Acquires a permit and returns its id. Waits if necessary until a permit became available.- Returns:
- permit id
-
acquireAsync
Acquires defined amount ofpermits
and returns their ids. Waits if necessary until all permits became available.- Parameters:
permits
- the number of permits to acquire- Returns:
- permits ids
- Throws:
IllegalArgumentException
- ifpermits
is negative
-
acquireAsync
Acquires a permit with definedleaseTime
and return its id. Waits if necessary until a permit became available.- Parameters:
leaseTime
- permit lease timeunit
- time unit- Returns:
- permit id
-
acquireAsync
Acquires defined amount ofpermits
and return their ids. Waits if necessary until all permits became available.- Parameters:
permits
- the number of permits to acquireleaseTime
- permit lease timeunit
- time unit- Returns:
- permits ids
- Throws:
IllegalArgumentException
- ifpermits
is negative
-
tryAcquireAsync
Tries to acquire currently available permit and return its id.- Returns:
- permit id if a permit was acquired and
null
otherwise
-
tryAcquireAsync
Tries to acquire defined amount of currently availablepermits
and returns their ids.- Parameters:
permits
- the number of permits to acquire- Returns:
- permits ids if permits were acquired and empty list otherwise
- Throws:
IllegalArgumentException
- ifpermits
is negative
-
tryAcquireAsync
Tries to acquire currently available permit and return its id. Waits up to definedwaitTime
if 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
null
if the waiting time elapsed before a permit was acquired
-
tryAcquireAsync
Tries to acquire currently available permit with definedleaseTime
and return its id. Waits up to definedwaitTime
if 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
null
if the waiting time elapsed before a permit was acquired
-
tryAcquireAsync
Tries to acquire defined amount of currently availablepermits
with definedleaseTime
and returns their ids. Waits up to definedwaitTime
if necessary until 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 list if the waiting time elapsed before permit were acquired
- Throws:
IllegalArgumentException
- ifpermits
is negative
-
tryReleaseAsync
Tries to release permit by its id.- Parameters:
permitId
- permit id- Returns:
true
if a permit has been released andfalse
otherwise
-
tryReleaseAsync
Tries to release defined permits by their ids.- Parameters:
permitsIds
- - permits ids- Returns:
- amount of released permits
- Throws:
IllegalArgumentException
- ifpermitsIds
is null or empty
-
releaseAsync
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- Returns:
- void
-
releaseAsync
Releases permits by their ids. Increases the number of available permits. Throws an exception if permits ids don't exist or have already been released.- Parameters:
permitsIds
- - permit id- Throws:
IllegalArgumentException
- ifpermitsIds
is null or empty
-
availablePermitsAsync
Returns number of available permits.- Returns:
- number of permits
-
getPermitsAsync
Returns the number of permits.- Returns:
- number of permits
-
acquiredPermitsAsync
Returns the number of acquired permits.- Returns:
- number of acquired permits
-
trySetPermitsAsync
Tries to set number of available permits.- Parameters:
permits
- - number of permits- Returns:
true
if permits has been set successfully, otherwisefalse
.
-
setPermitsAsync
Sets the number of permits to the provided value. Calculates thedelta
between the givenpermits
value and the current number of permits, then increases the number of available permits bydelta
.- Parameters:
permits
- - number of permits
-
addPermitsAsync
Increases or decreases the number of available permits by defined value.- Parameters:
permits
- amount of permits to add/remove- Returns:
- void
-
updateLeaseTimeAsync
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:
true
if permits has been updated successfully, otherwisefalse
.
-