Interface RSemaphoreRx
-
- All Superinterfaces:
RExpirableRx
,RObjectRx
public interface RSemaphoreRx extends RExpirableRx
RxJava2 interface for Semaphore object- Author:
- Nikita Koksharov
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description io.reactivex.Flowable<Void>
acquire()
Acquires a permit from this semaphore.io.reactivex.Flowable<Void>
acquire(int permits)
Acquires the given number of permits, if they are available, and returns immediately, reducing the number of available permits by the given amount.io.reactivex.Flowable<Void>
reducePermits(int permits)
Shrinks the number of available permits by the indicated reduction.io.reactivex.Flowable<Void>
release()
Releases a permit, returning it to the semaphore.io.reactivex.Flowable<Void>
release(int permits)
Releases the given number of permits, returning them to the semaphore.io.reactivex.Flowable<Boolean>
tryAcquire()
Acquires a permit only if one is available at the time of invocation.io.reactivex.Flowable<Boolean>
tryAcquire(int permits)
Acquires the given number of permits only if all are available at the time of invocation.io.reactivex.Flowable<Boolean>
tryAcquire(int permits, long waitTime, TimeUnit unit)
Acquires the given number of permits only if all are available within the given waiting time.io.reactivex.Flowable<Boolean>
tryAcquire(long waitTime, TimeUnit unit)
Acquires a permit, if one is available and returns immediately, with the valuetrue
, reducing the number of available permits by one.io.reactivex.Flowable<Boolean>
trySetPermits(int permits)
Sets number of permits.-
Methods inherited from interface org.redisson.api.RExpirableRx
clearExpire, expire, expireAt, expireAt, remainTimeToLive
-
-
-
-
Method Detail
-
tryAcquire
io.reactivex.Flowable<Boolean> 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 value
true
, reducing the number of available permits by one.If no permit is available then this method will return immediately with the value
false
.- Returns:
true
if a permit was acquired andfalse
otherwise
-
tryAcquire
io.reactivex.Flowable<Boolean> tryAcquire(int permits)
Acquires the given number of permits only if all are available at the time of invocation.Acquires a permits, if all are available and returns immediately, with the value
true
, reducing the number of available permits by given number of permits.If no permits are available then this method will return immediately with the value
false
.- Parameters:
permits
- the number of permits to acquire- Returns:
true
if a permit was acquired andfalse
otherwise
-
acquire
io.reactivex.Flowable<Void> acquire()
Acquires a permit from this semaphore.Acquires a permit, if one is available and returns immediately, reducing the number of available permits by one.
- Returns:
- void
-
acquire
io.reactivex.Flowable<Void> acquire(int permits)
Acquires the given number of permits, if they are available, and returns immediately, reducing the number of available permits by the given amount.- Parameters:
permits
- the number of permits to acquire- Returns:
- void
- Throws:
IllegalArgumentException
- ifpermits
is negative
-
release
io.reactivex.Flowable<Void> release()
Releases a permit, 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.- Returns:
- void
-
release
io.reactivex.Flowable<Void> release(int permits)
Releases the given number of permits, returning them to the semaphore.Releases the given number of permits, increasing the number of available permits by the given number of permits. If any threads of Redisson client are trying to acquire a permits, then next threads is selected and tries to acquire the permits that was just released.
There is no requirement that a thread that releases a permits must have acquired that permit by calling
acquire()
. Correct usage of a semaphore is established by programming convention in the application.- Parameters:
permits
- amount- Returns:
- void
-
trySetPermits
io.reactivex.Flowable<Boolean> trySetPermits(int permits)
Sets number of permits.- Parameters:
permits
- - number of permits- Returns:
true
if permits has been set successfully, otherwisefalse
.
-
tryAcquire
io.reactivex.Flowable<Boolean> tryAcquire(long waitTime, TimeUnit unit)
Acquires a permit, if one is available and returns immediately, with the value
true
, reducing the number of available permits by one.If a permit is acquired then the value
true
is returned.If the specified waiting time elapses then the value
false
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:
true
if a permit was acquired andfalse
if the waiting time elapsed before a permit was acquired
-
tryAcquire
io.reactivex.Flowable<Boolean> tryAcquire(int permits, long waitTime, TimeUnit unit)
Acquires the given number of permits only if all are available within the given waiting time.Acquires a permits, if all are available and returns immediately, with the value
true
, reducing the number of available permits by one.If a permits is acquired then the value
true
is returned.If the specified waiting time elapses then the value
false
is returned. If the time is less than or equal to zero, the method will not wait at all.- Parameters:
permits
- amountwaitTime
- the maximum time to wait for a available permitsunit
- the time unit of thetimeout
argument- Returns:
true
if a permit was acquired andfalse
if the waiting time elapsed before a permit was acquired
-
reducePermits
io.reactivex.Flowable<Void> reducePermits(int permits)
Shrinks the number of available permits by the indicated reduction. This method can be useful in subclasses that use semaphores to track resources that become unavailable. This method differs fromacquire()
in that it does not block waiting for permits to become available.- Parameters:
permits
- - reduction the number of permits to remove- Returns:
- void
- Throws:
IllegalArgumentException
- ifreduction
is negative
-
-