public class RedissonPermitExpirableSemaphore extends RedissonObject implements RPermitExpirableSemaphore
codec
Modifier | Constructor and Description |
---|---|
protected |
RedissonPermitExpirableSemaphore(CommandExecutor commandExecutor,
String name,
SemaphorePubSub semaphorePubSub) |
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 timeUnit)
Acquires a permit with defined lease time from this semaphore,
blocking until one is available,
or the thread is interrupted.
|
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 timeUnit)
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.
|
RFuture<Void> |
addPermitsAsync(int permits)
Increases or decreases the number of available permits by defined value.
|
int |
availablePermits()
Returns the current number of available permits.
|
RFuture<Integer> |
availablePermitsAsync()
Returns the current number of available permits.
|
boolean |
clearExpire()
Clear an expire timeout or expire date for object.
|
RFuture<Boolean> |
clearExpireAsync()
Clear an expire timeout or expire date for object in async mode.
|
RFuture<Boolean> |
deleteAsync()
Delete object in async mode
|
boolean |
expire(long timeToLive,
TimeUnit timeUnit)
Set a timeout for object.
|
RFuture<Boolean> |
expireAsync(long timeToLive,
TimeUnit timeUnit)
Set a timeout for object in async mode.
|
boolean |
expireAt(Date timestamp)
Set an expire date for object.
|
boolean |
expireAt(long timestamp)
Set an expire date for object.
|
RFuture<Boolean> |
expireAtAsync(Date timestamp)
Set an expire date for object in async mode.
|
RFuture<Boolean> |
expireAtAsync(long timestamp)
Set an expire date for object in async mode.
|
protected String |
generateId() |
static String |
getChannelName(String name) |
void |
release(String permitId)
Releases a permit by its id, returning it to the semaphore.
|
RFuture<Void> |
releaseAsync(String permitId)
Releases a permit by its id, returning it to the semaphore.
|
long |
remainTimeToLive()
Remaining time to live of Redisson object that has a timeout
|
RFuture<Long> |
remainTimeToLiveAsync()
Get remaining time to live of object in seconds.
|
String |
tryAcquire()
Acquires a permit only if one is available at the
time of invocation.
|
String |
tryAcquire(long waitTime,
long ttl,
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.
|
RFuture<String> |
tryAcquireAsync()
Acquires a permit only if one is available at the
time of invocation.
|
RFuture<String> |
tryAcquireAsync(int permits,
long timeoutDate) |
RFuture<String> |
tryAcquireAsync(long waitTime,
long ttl,
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.
|
boolean |
tryRelease(String permitId)
Releases a permit by its id, returning it to the semaphore.
|
RFuture<Boolean> |
tryReleaseAsync(String permitId)
Releases a permit by its id, returning it to the semaphore.
|
boolean |
trySetPermits(int permits)
Sets number of permits.
|
RFuture<Boolean> |
trySetPermitsAsync(int permits)
Sets number of permits.
|
await, delete, encode, encode, encode, encodeMapKey, encodeMapKeys, encodeMapValue, encodeMapValues, get, getCodec, getName, getName, isExists, isExistsAsync, migrate, migrateAsync, move, moveAsync, prefixName, rename, renameAsync, renamenx, renamenxAsync, suffixName, touch, touchAsync, unlink, unlinkAsync
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
clearExpire, expire, expireAt, expireAt, remainTimeToLive
delete, getCodec, getName, isExists, migrate, move, rename, renamenx, touch, unlink
clearExpireAsync, expireAsync, expireAtAsync, expireAtAsync, remainTimeToLiveAsync
isExistsAsync, migrateAsync, moveAsync, renameAsync, renamenxAsync, touchAsync, unlinkAsync
protected RedissonPermitExpirableSemaphore(CommandExecutor commandExecutor, String name, SemaphorePubSub semaphorePubSub)
public String acquire() throws InterruptedException
RPermitExpirableSemaphore
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:
RPermitExpirableSemaphore.release(java.lang.String)
method for this
semaphore and the current thread is next to be assigned a permit; or
acquire
in interface RPermitExpirableSemaphore
InterruptedException
- if the current thread is interruptedpublic String acquire(long leaseTime, TimeUnit timeUnit) throws InterruptedException
RPermitExpirableSemaphore
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:
RPermitExpirableSemaphore.release(java.lang.String)
method for this
semaphore and the current thread is next to be assigned a permit; or
acquire
in interface RPermitExpirableSemaphore
leaseTime
- - permit lease timetimeUnit
- - time unitInterruptedException
- if the current thread is interruptedpublic RFuture<String> acquireAsync(long leaseTime, TimeUnit timeUnit)
RPermitExpirableSemaphoreAsync
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:
RPermitExpirableSemaphoreAsync.releaseAsync(java.lang.String)
method for this
semaphore and the current thread is next to be assigned a permit; or
acquireAsync
in interface RPermitExpirableSemaphoreAsync
leaseTime
- - permit lease timetimeUnit
- - time unitpublic RFuture<String> acquireAsync()
RPermitExpirableSemaphoreAsync
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:
RPermitExpirableSemaphoreAsync.releaseAsync(String)
method for this
semaphore and the current thread is next to be assigned a permit; or
acquireAsync
in interface RPermitExpirableSemaphoreAsync
public String tryAcquire()
RPermitExpirableSemaphore
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
.
tryAcquire
in interface RPermitExpirableSemaphore
null
otherwisepublic RFuture<String> tryAcquireAsync()
RPermitExpirableSemaphoreAsync
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
.
tryAcquireAsync
in interface RPermitExpirableSemaphoreAsync
null
otherwiseprotected String generateId()
public RFuture<String> tryAcquireAsync(long waitTime, TimeUnit unit)
RPermitExpirableSemaphoreAsync
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:
RPermitExpirableSemaphoreAsync.releaseAsync(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.
tryAcquireAsync
in interface RPermitExpirableSemaphoreAsync
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 acquiredpublic String tryAcquire(long waitTime, long ttl, TimeUnit unit) throws InterruptedException
RPermitExpirableSemaphore
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:
RPermitExpirableSemaphore.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.
tryAcquire
in interface RPermitExpirableSemaphore
waitTime
- the maximum time to wait for a permitttl
- 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 interruptedpublic RFuture<String> tryAcquireAsync(long waitTime, long ttl, TimeUnit unit)
RPermitExpirableSemaphoreAsync
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:
RPermitExpirableSemaphoreAsync.releaseAsync(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.
tryAcquireAsync
in interface RPermitExpirableSemaphoreAsync
waitTime
- the maximum time to wait for a permitttl
- permit lease timeunit
- the time unit of the timeout
argumentnull
if the waiting time elapsed before a permit was acquiredpublic String tryAcquire(long waitTime, TimeUnit unit) throws InterruptedException
RPermitExpirableSemaphore
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:
RPermitExpirableSemaphore.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.
tryAcquire
in interface RPermitExpirableSemaphore
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 interruptedpublic void release(String permitId)
RPermitExpirableSemaphore
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 RPermitExpirableSemaphore.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
release
in interface RPermitExpirableSemaphore
permitId
- - permit idpublic boolean tryRelease(String permitId)
RPermitExpirableSemaphore
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 RPermitExpirableSemaphore.acquire()
.
Correct usage of a semaphore is established by programming convention
in the application.
tryRelease
in interface RPermitExpirableSemaphore
permitId
- - permit idtrue
if a permit has been released and false
otherwisepublic RFuture<Boolean> tryReleaseAsync(String permitId)
RPermitExpirableSemaphoreAsync
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 RPermitExpirableSemaphoreAsync.acquireAsync()
.
Correct usage of a semaphore is established by programming convention
in the application.
tryReleaseAsync
in interface RPermitExpirableSemaphoreAsync
permitId
- - permit idtrue
if a permit has been released and false
otherwisepublic RFuture<Boolean> deleteAsync()
RObjectAsync
deleteAsync
in interface RObjectAsync
deleteAsync
in class RedissonObject
true
if object was deleted false
if notpublic RFuture<Void> releaseAsync(String permitId)
RPermitExpirableSemaphoreAsync
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 RPermitExpirableSemaphoreAsync.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
releaseAsync
in interface RPermitExpirableSemaphoreAsync
permitId
- - permit idpublic int availablePermits()
RPermitExpirableSemaphore
availablePermits
in interface RPermitExpirableSemaphore
public RFuture<Integer> availablePermitsAsync()
RPermitExpirableSemaphoreAsync
availablePermitsAsync
in interface RPermitExpirableSemaphoreAsync
public boolean trySetPermits(int permits)
RPermitExpirableSemaphore
trySetPermits
in interface RPermitExpirableSemaphore
permits
- - number of permitstrue
if permits has been set successfully, otherwise false
.public RFuture<Boolean> trySetPermitsAsync(int permits)
RPermitExpirableSemaphoreAsync
trySetPermitsAsync
in interface RPermitExpirableSemaphoreAsync
permits
- - number of permitstrue
if permits has been set successfully, otherwise false
.public void addPermits(int permits)
RPermitExpirableSemaphore
addPermits
in interface RPermitExpirableSemaphore
permits
- - number of permits to add/removepublic RFuture<Void> addPermitsAsync(int permits)
RPermitExpirableSemaphoreAsync
addPermitsAsync
in interface RPermitExpirableSemaphoreAsync
permits
- - number of permits to add/removepublic boolean expire(long timeToLive, TimeUnit timeUnit)
RExpirable
expire
in interface RExpirable
timeToLive
- - timeout before object will be deletedtimeUnit
- - timeout time unittrue
if the timeout was set and false
if notpublic RFuture<Boolean> expireAsync(long timeToLive, TimeUnit timeUnit)
RExpirableAsync
expireAsync
in interface RExpirableAsync
timeToLive
- - timeout before object will be deletedtimeUnit
- - timeout time unittrue
if the timeout was set and false
if notpublic boolean expireAt(long timestamp)
RExpirable
expireAt
in interface RExpirable
timestamp
- - expire date in milliseconds (Unix timestamp)true
if the timeout was set and false
if notpublic RFuture<Boolean> expireAtAsync(long timestamp)
RExpirableAsync
expireAtAsync
in interface RExpirableAsync
timestamp
- - expire date in seconds (Unix timestamp)true
if the timeout was set and false
if notpublic boolean expireAt(Date timestamp)
RExpirable
expireAt
in interface RExpirable
timestamp
- - expire datetrue
if the timeout was set and false
if notpublic RFuture<Boolean> expireAtAsync(Date timestamp)
RExpirableAsync
expireAtAsync
in interface RExpirableAsync
timestamp
- - expire datetrue
if the timeout was set and false
if notpublic boolean clearExpire()
RExpirable
clearExpire
in interface RExpirable
true
if timeout was removed
false
if object does not exist or does not have an associated timeoutpublic RFuture<Boolean> clearExpireAsync()
RExpirableAsync
clearExpireAsync
in interface RExpirableAsync
true
if the timeout was cleared and false
if notpublic long remainTimeToLive()
RExpirable
remainTimeToLive
in interface RExpirable
public RFuture<Long> remainTimeToLiveAsync()
RExpirableAsync
remainTimeToLiveAsync
in interface RExpirableAsync
-1
if object does not exist or time in secondsCopyright © 2014–2018 The Redisson Project. All rights reserved.