Interface RPermitExpirableSemaphoreRx
- All Superinterfaces:
RExpirableRx
,RObjectRx
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 TypeMethodDescriptionio.reactivex.rxjava3.core.Single<String>
acquire()
Acquires a permit from this semaphore, blocking until one is available, or the thread is interrupted.acquire
(int permits) Acquires defined amount ofpermits
from this semaphore, blocking until enough permits are available, or the thread is interrupted.Acquires defined amount ofpermits
with defined lease time from this semaphore, blocking until enough permits are available, or the thread is interrupted.io.reactivex.rxjava3.core.Single<String>
Acquires a permit with defined lease time from this semaphore, blocking until one is available, or the thread is interrupted.io.reactivex.rxjava3.core.Single<Integer>
Returns the number of acquired permits.io.reactivex.rxjava3.core.Completable
addPermits
(int permits) Increases or decreases the number of available permits by defined value.io.reactivex.rxjava3.core.Single<Integer>
Returns the current number of available permits.io.reactivex.rxjava3.core.Single<Integer>
Returns the number of permits.io.reactivex.rxjava3.core.Completable
Releases a permit by its id, returning it to the semaphore.io.reactivex.rxjava3.core.Completable
Releases permits by their ids, returning them to the semaphore.io.reactivex.rxjava3.core.Single<Void>
setPermits
(int permits) Sets the number of permits to the provided value.io.reactivex.rxjava3.core.Maybe<String>
Acquires a permit only if one is available at the time of invocation.tryAcquire
(int permits) Acquires defined amount ofpermits
only if they are available at the time of invocation.tryAcquire
(int permits, long waitTime, long leaseTime, TimeUnit unit) Acquires defined amount ofpermits
with defined lease time from this semaphore, if enough permits become available within the given waiting time and the current thread has not been interrupted.io.reactivex.rxjava3.core.Maybe<String>
tryAcquire
(long waitTime, long leaseTime, TimeUnit unit) Acquires a permit with defined lease time from this semaphore, if one becomes available within the given waiting time and the current thread has not been interrupted.io.reactivex.rxjava3.core.Maybe<String>
tryAcquire
(long waitTime, TimeUnit unit) Acquires a permit from this semaphore, if one becomes available within the given waiting time and the current thread has not been interrupted.io.reactivex.rxjava3.core.Single<Boolean>
tryRelease
(String permitId) Releases a permit by its id, returning it to the semaphore.io.reactivex.rxjava3.core.Single<Integer>
tryRelease
(List<String> permitsIds) Releases permits by their ids, returning them to the semaphore.io.reactivex.rxjava3.core.Single<Boolean>
trySetPermits
(int permits) Sets number of permits.io.reactivex.rxjava3.core.Single<Boolean>
updateLeaseTime
(String permitId, long leaseTime, TimeUnit unit) Overrides and updates lease time for defined permit id.Methods inherited from interface org.redisson.api.RExpirableRx
clearExpire, expire, expire, expire, expireAt, expireAt, expireIfGreater, expireIfGreater, expireIfLess, expireIfLess, expireIfNotSet, expireIfNotSet, expireIfSet, expireIfSet, getExpireTime, remainTimeToLive
Methods inherited from interface org.redisson.api.RObjectRx
addListener, copy, delete, dump, getCodec, getIdleTime, getName, isExists, migrate, move, removeListener, rename, renamenx, restore, restore, restoreAndReplace, restoreAndReplace, sizeInMemory, touch, unlink
-
Method Details
-
acquire
io.reactivex.rxjava3.core.Single<String> acquire()Acquires a permit from this semaphore, blocking until one is available, or the thread is interrupted.Acquires a permit, if one is available and returns its id, reducing the number of available permits by one.
If no permit is available then the current thread becomes disabled for thread scheduling purposes and lies dormant until one of two things happens:
- Some other thread invokes the
release(String)
method for this semaphore and the current thread is next to be assigned a permit; or - Some other thread interrupts the current thread.
- Returns:
- permit id
- Some other thread invokes the
-
acquire
Acquires defined amount ofpermits
from this semaphore, blocking until enough permits are available, or the thread is interrupted.Acquires
permits
permits, if they are available and returns their ids, reducing the number of available permits bypermits
.If not enough permits are available then the current thread becomes disabled for thread scheduling purposes and lies dormant until one of two things happens:
- Some other thread invokes the
release(String)
method for this semaphore and the current thread is next to be assigned a permit; or - Some other thread interrupts the current thread.
- Parameters:
permits
- - the number of permits to acquire- Returns:
- permits ids
- Some other thread invokes the
-
acquire
Acquires a permit with defined lease time from this semaphore, blocking until one is available, or the thread is interrupted.Acquires a permit, if one is available and returns its id, reducing the number of available permits by one.
If no permit is available then the current thread becomes disabled for thread scheduling purposes and lies dormant until one of two things happens:
- Some other thread invokes the
release(java.lang.String)
method for this semaphore and the current thread is next to be assigned a permit; or - Some other thread interrupts the current thread.
- Parameters:
leaseTime
- - permit lease timeunit
- - time unit- Returns:
- permit id
- Some other thread invokes the
-
acquire
Acquires defined amount ofpermits
with defined lease time from this semaphore, blocking until enough permits are available, or the thread is interrupted.Acquires
permits
permits, if they are available and returns their ids, reducing the number of available permits bypermits
.If not enough permits are available then the current thread becomes disabled for thread scheduling purposes and lies dormant until one of two things happens:
- Some other thread invokes the
release(java.lang.String)
method for this semaphore and the current thread is next to be assigned a permit; or - Some other thread interrupts the current thread.
- Parameters:
permits
- - the number of permits to acquireleaseTime
- - permit lease timeunit
- - time unit- Returns:
- permits ids
- Some other thread invokes the
-
tryAcquire
io.reactivex.rxjava3.core.Maybe<String> tryAcquire()Acquires a permit only if one is available at the time of invocation.Acquires a permit, if one is available and returns immediately, with the permit id, reducing the number of available permits by one.
If no permit is available then this method will return immediately with the value
null
.- Returns:
- permit id if a permit was acquired and
null
otherwise
-
tryAcquire
Acquires defined amount ofpermits
only if they are available at the time of invocation.Acquires
permits
permits, if they are available and returns immediately, with the permits ids, reducing the number of available permits bypermits
.If not enough permits are available then this method will return immediately with empty collection.
- Parameters:
permits
- - the number of permits to acquire- Returns:
- permits ids if permit were acquired and empty collection otherwise
-
tryAcquire
Acquires a permit from this semaphore, if one becomes available within the given waiting time and the current thread has not been interrupted.Acquires a permit, if one is available and returns immediately, with the permit id, reducing the number of available permits by one.
If no permit is available then the current thread becomes disabled for thread scheduling purposes and lies dormant until one of three things happens:
- Some other thread invokes the
release(String)
method for this semaphore and the current thread is next to be assigned a permit; or - Some other thread interrupts the current thread; or
- The specified waiting time elapses.
If a permit is acquired then the permit id is returned.
If the specified waiting time elapses then the value
null
is returned. If the time is less than or equal to zero, the method will not wait at all.- Parameters:
waitTime
- the maximum time to wait for a permitunit
- the time unit of thetimeout
argument- Returns:
- permit id if a permit was acquired and
null
if the waiting time elapsed before a permit was acquired
- Some other thread invokes the
-
tryAcquire
Acquires a permit with defined lease time from this semaphore, if one becomes available within the given waiting time and the current thread has not been interrupted.Acquires a permit, if one is available and returns immediately, with the permit id, reducing the number of available permits by one.
If no permit is available then the current thread becomes disabled for thread scheduling purposes and lies dormant until one of three things happens:
- Some other thread invokes the
release(String)
method for this semaphore and the current thread is next to be assigned a permit; or - Some other thread interrupts the current thread; or
- The specified waiting time elapses.
If a permit is acquired then the permit id is returned.
If the specified waiting time elapses then the value
null
is returned. If the time is less than or equal to zero, the method will not wait at all.- Parameters:
waitTime
- the maximum time to wait for a permitleaseTime
- permit lease timeunit
- the time unit of thetimeout
argument- Returns:
- permit id if a permit was acquired and
null
if the waiting time elapsed before a permit was acquired
- Some other thread invokes the
-
tryAcquire
io.reactivex.rxjava3.core.Single<List<String>> tryAcquire(int permits, long waitTime, long leaseTime, TimeUnit unit) Acquires defined amount ofpermits
with defined lease time from this semaphore, if enough permits become available within the given waiting time and the current thread has not been interrupted.Acquires
permits
permits, if they are available and returns immediately, with the permits ids, reducing the number of available permits bypermits
.If not enough permits are available then the current thread becomes disabled for thread scheduling purposes and lies dormant until one of three things happens:
- Some other thread invokes the
release(String)
method for this semaphore and the current thread is next to be assigned a permit; or - Some other thread interrupts the current thread; or
- The specified waiting time elapses.
If permit are acquired then permits ids are returned.
If the specified waiting time elapses then the empty collection is returned. If the time is less than or equal to zero, the method will not wait at all.
- Parameters:
permits
- the number of permits to acquirewaitTime
- the maximum time to wait for permitsleaseTime
- permits lease timeunit
- the time unit of thetimeout
argument- Returns:
- permits ids if permit were acquired and empty collection if the waiting time elapsed before permits were acquired
- Some other thread invokes the
-
tryRelease
Releases a permit by its id, returning it to the semaphore.Releases a permit, increasing the number of available permits by one. If any threads of Redisson client are trying to acquire a permit, then one is selected and given the permit that was just released.
There is no requirement that a thread that releases a permit must have acquired that permit by calling
acquire()
. Correct usage of a semaphore is established by programming convention in the application.- Parameters:
permitId
- - permit id- Returns:
true
if a permit has been released andfalse
otherwise
-
tryRelease
Releases permits by their ids, returning them to the semaphore.Releases
permits
permits, increasing the number of available permits by released amount. If any threads of Redisson client are trying to acquire a permit, then one is selected and given one of the permits that were just released.There is no requirement that a thread that releases permits must have acquired that permit by calling
acquire()
. Correct usage of a semaphore is established by programming convention in the application.- Parameters:
permitsIds
- - permits ids- Returns:
- amount of released permits
-
release
Releases a permit by its id, returning it to the semaphore.Releases a permit, increasing the number of available permits by one. If any threads of Redisson client are trying to acquire a permit, then one is selected and given the permit that was just released.
There is no requirement that a thread that releases a permit must have acquired that permit by calling
acquire()
. Correct usage of a semaphore is established by programming convention in the application.Throws an exception if permit id doesn't exist or has already been release
- Parameters:
permitId
- - permit id- Returns:
- void
-
release
Releases permits by their ids, returning them to the semaphore.Releases
permits
permits, increasing the number of available permits by released amount. If any threads of Redisson client are trying to acquire a permit, then one is selected and given the permit that were just released.There is no requirement that a thread that releases permits must have acquired that permit by calling
acquire()
. Correct usage of a semaphore is established by programming convention in the application.Throws an exception if permit id doesn't exist or has already been release
- Parameters:
permitsIds
- - permits ids- Returns:
- void
-
availablePermits
io.reactivex.rxjava3.core.Single<Integer> availablePermits()Returns the current number of available permits.- Returns:
- number of available permits
-
getPermits
io.reactivex.rxjava3.core.Single<Integer> getPermits()Returns the number of permits.- Returns:
- number of permits
-
acquiredPermits
io.reactivex.rxjava3.core.Single<Integer> acquiredPermits()Returns the number of acquired permits.- Returns:
- number of acquired permits
-
trySetPermits
Sets 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
io.reactivex.rxjava3.core.Completable addPermits(int permits) Increases or decreases the number of available permits by defined value.- Parameters:
permits
- - number of permits to add/remove- Returns:
- void
-
updateLeaseTime
io.reactivex.rxjava3.core.Single<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 of thetimeout
argument- Returns:
true
if permits has been updated successfully, otherwisefalse
.
-