Package org.redisson.api
Interface RPermitExpirableSemaphoreReactive
- All Superinterfaces:
RExpirableReactive
,RObjectReactive
Reactive 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 TypeMethodDescriptionreactor.core.publisher.Mono
<String> acquire()
Acquires a permit and returns its id.acquire
(int permits) Acquires defined amount ofpermits
.Acquires defined amount ofpermits
with definedleaseTime
and returns ids.reactor.core.publisher.Mono
<String> Acquires a permit with definedleaseTime
and return its id.reactor.core.publisher.Mono
<Integer> Returns the number of acquired permits.reactor.core.publisher.Mono
<Void> addPermits
(int permits) Increases or decreases the number of available permits by defined value.reactor.core.publisher.Mono
<Integer> Returns amount of available permits.reactor.core.publisher.Mono
<Integer> Returns the number of permits.reactor.core.publisher.Mono
<Void> Releases a permit by its id.reactor.core.publisher.Mono
<Void> Releases a permits by their ids.reactor.core.publisher.Mono
<Void> setPermits
(int permits) Sets the number of permits to the provided value.reactor.core.publisher.Mono
<String> Tries to acquire currently available permit and return its id.tryAcquire
(int permits) Tries to acquire defined amount of currently availablepermits
and returns ids.tryAcquire
(int permits, long waitTime, long leaseTime, TimeUnit unit) Tries to acquire defined amount of currently availablepermits
with definedleaseTime
and return their ids.reactor.core.publisher.Mono
<String> tryAcquire
(long waitTime, long leaseTime, TimeUnit unit) Tries to acquire currently available permit with definedleaseTime
and return its id.reactor.core.publisher.Mono
<String> tryAcquire
(long waitTime, TimeUnit unit) Tries to acquire currently available permit and return its id.reactor.core.publisher.Mono
<Boolean> tryRelease
(String permitId) Tries to release permit by its id.reactor.core.publisher.Mono
<Integer> tryRelease
(List<String> permitsIds) Tries to release permits by their ids.reactor.core.publisher.Mono
<Boolean> trySetPermits
(int permits) Tries to set number of permits.reactor.core.publisher.Mono
<Boolean> updateLeaseTime
(String permitId, long leaseTime, TimeUnit unit) Overrides and updates lease time for defined permit id.Methods inherited from interface org.redisson.api.RExpirableReactive
clearExpire, expire, expire, expire, expireAt, expireAt, expireIfGreater, expireIfGreater, expireIfLess, expireIfLess, expireIfNotSet, expireIfNotSet, expireIfSet, expireIfSet, getExpireTime, remainTimeToLive
Methods inherited from interface org.redisson.api.RObjectReactive
addListener, copy, copy, copy, copyAndReplace, copyAndReplace, delete, dump, getCodec, getIdleTime, getName, isExists, migrate, move, removeListener, rename, renamenx, restore, restore, restoreAndReplace, restoreAndReplace, sizeInMemory, touch, unlink
-
Method Details
-
acquire
reactor.core.publisher.Mono<String> acquire()Acquires a permit and returns its id. Waits if necessary until a permit became available.- Returns:
- permit id
-
acquire
Acquires defined amount ofpermits
. Waits if necessary until all permits became available.- Parameters:
permits
- the number of permits to acquire- Returns:
- permits ids
-
acquire
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
-
acquire
Acquires defined amount ofpermits
with definedleaseTime
and returns ids. Waits if necessary until all permits became available.- Parameters:
permits
- the number of permits to acquireleaseTime
- permits lease timeunit
- time unit- Returns:
- permits ids
-
tryAcquire
reactor.core.publisher.Mono<String> tryAcquire()Tries to acquire currently available permit and return its id.- Returns:
- permit id if a permit was acquired and
null
otherwise
-
tryAcquire
Tries to acquire defined amount of currently availablepermits
and returns ids.- Parameters:
permits
- the number of permits to acquire- Returns:
- permits ids if permits were acquired and empty collection otherwise
-
tryAcquire
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
-
tryAcquire
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
-
tryAcquire
reactor.core.publisher.Mono<List<String>> tryAcquire(int permits, long waitTime, long leaseTime, TimeUnit unit) Tries to acquire defined amount of currently availablepermits
with definedleaseTime
and return their ids. Waits up to definedwaitTime
if necessary until enough permits became available.- Parameters:
permits
- the number of permits to acquirewaitTime
- the maximum time to waitleaseTime
- permits lease time, use -1 to make them permanentunit
- the time unit- Returns:
- permits ids if permits were acquired and empty collection if the waiting time elapsed before permits were acquired
-
tryRelease
Tries to release permit by its id.- Parameters:
permitId
- permit id- Returns:
true
if a permit has been released andfalse
otherwise
-
tryRelease
Tries to release permits by their ids.- Parameters:
permitsIds
- permits ids- Returns:
- amount of released permits
-
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- Returns:
- void
-
release
Releases a 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- Returns:
- void
-
availablePermits
reactor.core.publisher.Mono<Integer> availablePermits()Returns amount of available permits.- Returns:
- number of permits
-
getPermits
reactor.core.publisher.Mono<Integer> getPermits()Returns the number of permits.- Returns:
- number of permits
-
acquiredPermits
reactor.core.publisher.Mono<Integer> acquiredPermits()Returns the number of acquired permits.- Returns:
- number of acquired permits
-
trySetPermits
Tries to set number of permits.- Parameters:
permits
- - number of permits- Returns:
true
if permits has been set successfully, otherwisefalse
.
-
setPermits
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
-
addPermits
Increases or decreases the number of available permits by defined value.- Parameters:
permits
- amount of permits to add/remove- Returns:
- void
-
updateLeaseTime
reactor.core.publisher.Mono<Boolean> updateLeaseTime(String permitId, long leaseTime, TimeUnit unit) 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
.
-