public class RedissonSemaphore extends RedissonObject implements RSemaphore
Semaphore
.
Works in non-fair mode. Therefore order of acquiring is unpredictable.
codec
Constructor and Description |
---|
RedissonSemaphore(CommandAsyncExecutor commandExecutor,
String name,
SemaphorePubSub semaphorePubSub) |
Modifier and Type | Method and Description |
---|---|
void |
acquire()
Acquires a permit from this semaphore, blocking until one is
available, or the thread is interrupted.
|
void |
acquire(int permits)
Acquires the given number of permits from this semaphore,
blocking until all are available,
or the thread is interrupted.
|
RFuture<Void> |
acquireAsync()
Acquires a permit from this semaphore.
|
RFuture<Void> |
acquireAsync(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.
|
int |
availablePermits()
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.
|
int |
drainPermits()
Acquires and returns all permits that are immediately available.
|
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.
|
static String |
getChannelName(String name) |
void |
reducePermits(int permits)
Shrinks the number of available permits by the indicated
reduction.
|
RFuture<Void> |
reducePermitsAsync(int permits)
Shrinks the number of available permits by the indicated
reduction.
|
void |
release()
Releases a permit, returning it to the semaphore.
|
void |
release(int permits)
Releases the given number of permits, returning them to the semaphore.
|
RFuture<Void> |
releaseAsync()
Releases a permit, returning it to the semaphore.
|
RFuture<Void> |
releaseAsync(int permits)
Releases the given number of permits, returning them to the semaphore.
|
long |
remainTimeToLive()
Remaining time to live of Redisson object that has a timeout
|
RFuture<Long> |
remainTimeToLiveAsync()
Remaining time to live of Redisson object that has a timeout
|
boolean |
tryAcquire()
Acquires a permit only if one is available at the
time of invocation.
|
boolean |
tryAcquire(int permits)
Acquires the given number of permits only if all are available at the
time of invocation.
|
boolean |
tryAcquire(int permits,
long waitTime,
TimeUnit unit)
Acquires the given number of permits only if all are available
within the given waiting time and the current thread has not
been interrupted.
|
boolean |
tryAcquire(long time,
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> |
tryAcquireAsync()
Acquires a permit only if one is available at the
time of invocation.
|
RFuture<Boolean> |
tryAcquireAsync(int permits)
Acquires the given number of permits only if all are available at the
time of invocation.
|
RFuture<Boolean> |
tryAcquireAsync(int permits,
long waitTime,
TimeUnit unit)
Acquires the given number of permits only if all are available
within the given waiting time.
|
RFuture<Boolean> |
tryAcquireAsync(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. |
boolean |
trySetPermits(int permits)
Sets number of permits.
|
RFuture<Boolean> |
trySetPermitsAsync(int permits)
Sets number of permits.
|
await, copy, copyAsync, delete, deleteAsync, dump, dumpAsync, encode, encode, encode, encodeMapKey, encodeMapKeys, encodeMapValue, encodeMapValues, get, getCodec, getName, getName, isExists, isExistsAsync, migrate, migrateAsync, move, moveAsync, prefixName, rename, renameAsync, renamenx, renamenxAsync, restore, restore, restoreAndReplace, restoreAndReplace, restoreAndReplaceAsync, restoreAndReplaceAsync, restoreAsync, restoreAsync, sizeInMemory, sizeInMemoryAsync, sizeInMemoryAsync, suffixName, toSeconds, touch, touchAsync, unlink, unlinkAsync
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
clearExpire, expire, expireAt, expireAt, remainTimeToLive
copy, delete, dump, getCodec, getName, isExists, migrate, move, rename, renamenx, restore, restore, restoreAndReplace, restoreAndReplace, sizeInMemory, touch, unlink
clearExpireAsync, expireAsync, expireAtAsync, expireAtAsync, remainTimeToLiveAsync
copyAsync, deleteAsync, dumpAsync, isExistsAsync, migrateAsync, moveAsync, renameAsync, renamenxAsync, restoreAndReplaceAsync, restoreAndReplaceAsync, restoreAsync, restoreAsync, sizeInMemoryAsync, touchAsync, unlinkAsync
public RedissonSemaphore(CommandAsyncExecutor commandExecutor, String name, SemaphorePubSub semaphorePubSub)
public void acquire() throws InterruptedException
RSemaphore
Acquires a permit, if one is available and returns immediately, 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:
RSemaphore.release()
method for this
semaphore and the current thread is next to be assigned a permit; or
acquire
in interface RSemaphore
InterruptedException
- if the current thread is interruptedpublic void acquire(int permits) throws InterruptedException
RSemaphore
Acquires the given number of permits, if they are available, and returns immediately, reducing the number of available permits by the given amount.
If insufficient permits are available then the current thread becomes disabled for thread scheduling purposes and lies dormant until one of two things happens:
release
methods for this semaphore, the current thread is next to be assigned
permits and the number of available permits satisfies this request; or
acquire
in interface RSemaphore
permits
- the number of permits to acquireInterruptedException
- if the current thread is interruptedpublic RFuture<Void> acquireAsync()
RSemaphoreAsync
Acquires a permit, if one is available and returns immediately, reducing the number of available permits by one.
acquireAsync
in interface RSemaphoreAsync
public RFuture<Void> acquireAsync(int permits)
RSemaphoreAsync
acquireAsync
in interface RSemaphoreAsync
permits
- the number of permits to acquirepublic boolean tryAcquire()
RSemaphore
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
.
tryAcquire
in interface RSemaphore
true
if a permit was acquired and false
otherwisepublic boolean tryAcquire(int permits)
RSemaphore
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
.
tryAcquire
in interface RSemaphore
permits
- the number of permits to acquiretrue
if a permit was acquired and false
otherwisepublic RFuture<Boolean> tryAcquireAsync()
RSemaphoreAsync
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
.
tryAcquireAsync
in interface RSemaphoreAsync
true
if a permit was acquired and false
otherwisepublic RFuture<Boolean> tryAcquireAsync(int permits)
RSemaphoreAsync
Acquires a permits, if all are available and returns immediately,
with the value true
,
reducing the number of available permits by given number of permitss.
If no permits are available then this method will return
immediately with the value false
.
tryAcquireAsync
in interface RSemaphoreAsync
permits
- the number of permits to acquiretrue
if a permit was acquired and false
otherwisepublic RFuture<Boolean> tryAcquireAsync(long waitTime, TimeUnit unit)
RSemaphoreAsync
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.
tryAcquireAsync
in interface RSemaphoreAsync
waitTime
- the maximum time to wait for a permitunit
- the time unit of the timeout
argumenttrue
if a permit was acquired and false
if the waiting time elapsed before a permit was acquiredpublic boolean tryAcquire(int permits, long waitTime, TimeUnit unit) throws InterruptedException
RSemaphore
Acquires a permits, if all are available and returns immediately,
with the value true
,
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:
RSemaphore.release()
method for this
semaphore and the current thread is next to be assigned a permit; or
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.
tryAcquire
in interface RSemaphore
permits
- amountwaitTime
- the maximum time to wait for a permitunit
- the time unit of the timeout
argumenttrue
if a permit was acquired and false
if the waiting time elapsed before a permit was acquiredInterruptedException
- if the current thread is interruptedpublic RFuture<Boolean> tryAcquireAsync(int permits, long waitTime, TimeUnit unit)
RSemaphoreAsync
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.
tryAcquireAsync
in interface RSemaphoreAsync
permits
- amountwaitTime
- the maximum time to wait for a available permitsunit
- the time unit of the timeout
argumenttrue
if a permit was acquired and false
if the waiting time elapsed before a permit was acquiredpublic boolean tryAcquire(long time, TimeUnit unit) throws InterruptedException
RSemaphore
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 the current thread becomes disabled for thread scheduling purposes and lies dormant until one of three things happens:
RSemaphore.release()
method for this
semaphore and the current thread is next to be assigned a permit; or
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.
tryAcquire
in interface RSemaphore
time
- the maximum time to wait for a permitunit
- the time unit of the timeout
argumenttrue
if a permit was acquired and false
if the waiting time elapsed before a permit was acquiredInterruptedException
- if the current thread is interruptedpublic void release()
RSemaphore
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 RSemaphore.acquire()
.
Correct usage of a semaphore is established by programming convention
in the application.
release
in interface RSemaphore
public void release(int permits)
RSemaphore
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 RSemaphore.acquire()
.
Correct usage of a semaphore is established by programming convention
in the application.
release
in interface RSemaphore
permits
- amountpublic RFuture<Void> releaseAsync()
RSemaphoreAsync
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 RSemaphoreAsync.acquireAsync()
.
Correct usage of a semaphore is established by programming convention
in the application.
releaseAsync
in interface RSemaphoreAsync
public RFuture<Void> releaseAsync(int permits)
RSemaphoreAsync
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 RSemaphoreAsync.acquireAsync()
.
Correct usage of a semaphore is established by programming convention
in the application.
releaseAsync
in interface RSemaphoreAsync
permits
- amountpublic int drainPermits()
RSemaphore
drainPermits
in interface RSemaphore
public int availablePermits()
RSemaphore
availablePermits
in interface RSemaphore
public boolean trySetPermits(int permits)
RSemaphore
trySetPermits
in interface RSemaphore
permits
- - number of permitstrue
if permits has been set successfully, otherwise false
.public RFuture<Boolean> trySetPermitsAsync(int permits)
RSemaphoreAsync
trySetPermitsAsync
in interface RSemaphoreAsync
permits
- - number of permitstrue
if permits has been set successfully, otherwise false
.public void reducePermits(int permits)
RSemaphore
reducePermits
in interface RSemaphore
permits
- - reduction the number of permits to removepublic RFuture<Void> reducePermitsAsync(int permits)
RSemaphoreAsync
RSemaphoreAsync.acquireAsync()
in that it does not block
waiting for permits to become available.reducePermitsAsync
in interface RSemaphoreAsync
permits
- - reduction the number of permits to 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 milliseconds (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
Copyright © 2014–2019 The Redisson Project. All rights reserved.