Interface RPermitExpirableSemaphoreAsync
-
- All Superinterfaces:
RExpirableAsync
,RObjectAsync
- All Known Subinterfaces:
RPermitExpirableSemaphore
- All Known Implementing Classes:
RedissonPermitExpirableSemaphore
public interface RPermitExpirableSemaphoreAsync extends RExpirableAsync
Semaphore object with support of lease time parameter 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
All Methods Instance Methods Abstract Methods Modifier and Type Method Description RFuture<String>
acquireAsync()
Acquires a permit from this semaphore, blocking until one is available, or the thread is interrupted.RFuture<String>
acquireAsync(long leaseTime, TimeUnit unit)
Acquires a permit with defined lease time from this semaphore, blocking until one is available, or the thread is interrupted.RFuture<Void>
addPermitsAsync(int permits)
Increases or decreases the number of available permits by defined value.RFuture<Integer>
availablePermitsAsync()
Returns the current number of available permits.RFuture<Void>
releaseAsync(String permitId)
Releases a permit by its id, returning it to the semaphore.RFuture<String>
tryAcquireAsync()
Acquires a permit only if one is available at the time of invocation.RFuture<String>
tryAcquireAsync(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.RFuture<String>
tryAcquireAsync(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.RFuture<Boolean>
tryReleaseAsync(String permitId)
Releases a permit by its id, returning it to the semaphore.RFuture<Boolean>
trySetPermitsAsync(int permits)
Sets number of permits.RFuture<Boolean>
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, expireAtAsync, expireAtAsync, remainTimeToLiveAsync
-
Methods inherited from interface org.redisson.api.RObjectAsync
copyAsync, deleteAsync, dumpAsync, isExistsAsync, migrateAsync, moveAsync, renameAsync, renamenxAsync, restoreAndReplaceAsync, restoreAndReplaceAsync, restoreAsync, restoreAsync, sizeInMemoryAsync, touchAsync, unlinkAsync
-
-
-
-
Method Detail
-
acquireAsync
RFuture<String> acquireAsync()
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
releaseAsync(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
-
acquireAsync
RFuture<String> acquireAsync(long leaseTime, TimeUnit unit)
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
releaseAsync(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
-
tryAcquireAsync
RFuture<String> tryAcquireAsync()
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
-
tryAcquireAsync
RFuture<String> tryAcquireAsync(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.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
releaseAsync(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
-
tryAcquireAsync
RFuture<String> tryAcquireAsync(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.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
releaseAsync(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 time, use -1 to make it permanentunit
- 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
-
tryReleaseAsync
RFuture<Boolean> tryReleaseAsync(String permitId)
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
acquireAsync()
. 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
-
releaseAsync
RFuture<Void> releaseAsync(String permitId)
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
acquireAsync()
. 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
-
availablePermitsAsync
RFuture<Integer> availablePermitsAsync()
Returns the current number of available permits.- Returns:
- number of available permits
-
trySetPermitsAsync
RFuture<Boolean> trySetPermitsAsync(int permits)
Sets number of permits.- Parameters:
permits
- - number of permits- Returns:
true
if permits has been set successfully, otherwisefalse
.
-
addPermitsAsync
RFuture<Void> addPermitsAsync(int permits)
Increases or decreases the number of available permits by defined value.- Parameters:
permits
- - number of permits to add/remove- Returns:
- void
-
updateLeaseTimeAsync
RFuture<Boolean> updateLeaseTimeAsync(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
.
-
-