public interface RPermitExpirableSemaphore extends RExpirable, RPermitExpirableSemaphoreAsync
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.
Modifier and Type | Method and Description |
---|---|
String |
acquire()
Acquires a permit from this semaphore, blocking until one is
available, or the thread is interrupted.
|
String |
acquire(long leaseTime,
TimeUnit unit)
Acquires a permit with defined lease time from this semaphore,
blocking until one is available,
or the thread is interrupted.
|
void |
addPermits(int permits)
Increases or decreases the number of available permits by defined value.
|
int |
availablePermits()
Returns the current number of available permits.
|
void |
release(String permitId)
Releases a permit by its id, returning it to the semaphore.
|
String |
tryAcquire()
Acquires a permit only if one is available at the
time of invocation.
|
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.
|
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.
|
boolean |
tryRelease(String permitId)
Releases a permit by its id, returning it to the semaphore.
|
boolean |
trySetPermits(int permits)
Sets number of permits.
|
clearExpire, expire, expireAt, expireAt, remainTimeToLive
copy, delete, getCodec, getName, isExists, migrate, move, rename, renamenx, touch, unlink
acquireAsync, acquireAsync, addPermitsAsync, availablePermitsAsync, releaseAsync, tryAcquireAsync, tryAcquireAsync, tryAcquireAsync, tryReleaseAsync, trySetPermitsAsync
clearExpireAsync, expireAsync, expireAtAsync, expireAtAsync, remainTimeToLiveAsync
copyAsync, deleteAsync, isExistsAsync, migrateAsync, moveAsync, renameAsync, renamenxAsync, touchAsync, unlinkAsync
String acquire() throws InterruptedException
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:
release(java.lang.String)
method for this
semaphore and the current thread is next to be assigned a permit; or
InterruptedException
- if the current thread is interruptedString acquire(long leaseTime, TimeUnit unit) throws InterruptedException
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:
release(java.lang.String)
method for this
semaphore and the current thread is next to be assigned a permit; or
leaseTime
- - permit lease timeunit
- - time unitInterruptedException
- if the current thread is interruptedString tryAcquire()
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
.
null
otherwiseString tryAcquire(long waitTime, TimeUnit unit) throws InterruptedException
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:
release(java.lang.String)
method for this
semaphore and the current thread is next to be assigned a permit; or
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.
waitTime
- the maximum time to wait for a permitunit
- the time unit of the timeout
argumentnull
if the waiting time elapsed before a permit was acquiredInterruptedException
- if the current thread is interruptedString tryAcquire(long waitTime, long leaseTime, TimeUnit unit) throws InterruptedException
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:
release(java.lang.String)
method for this
semaphore and the current thread is next to be assigned a permit; or
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.
waitTime
- the maximum time to wait for a permitleaseTime
- permit lease timeunit
- the time unit of the timeout
argumentnull
if the waiting time elapsed before a permit was acquiredInterruptedException
- if the current thread is interruptedboolean tryRelease(String permitId)
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.
permitId
- - permit idtrue
if a permit has been released and false
otherwisevoid release(String permitId)
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
permitId
- - permit idint availablePermits()
boolean trySetPermits(int permits)
permits
- - number of permitstrue
if permits has been set successfully, otherwise false
.void addPermits(int permits)
permits
- - number of permits to add/removeCopyright © 2014–2018 The Redisson Project. All rights reserved.