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, encode, encode, encode, encodeMapKey, encodeMapKeys, encodeMapValue, encodeMapValues, get, getCodec, getName, getName, isExists, isExistsAsync, migrate, migrateAsync, move, moveAsync, prefixName, rename, renameAsync, renamenx, renamenxAsync, suffixName, toSeconds, touch, touchAsync, unlink, unlinkAsyncclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitclearExpire, expire, expireAt, expireAt, remainTimeToLivecopy, delete, getCodec, getName, isExists, migrate, move, rename, renamenx, touch, unlinkclearExpireAsync, expireAsync, expireAtAsync, expireAtAsync, remainTimeToLiveAsynccopyAsync, deleteAsync, isExistsAsync, migrateAsync, moveAsync, renameAsync, renamenxAsync, touchAsync, unlinkAsyncpublic RedissonSemaphore(CommandAsyncExecutor commandExecutor, String name, SemaphorePubSub semaphorePubSub)
public void acquire()
throws InterruptedException
RSemaphoreAcquires 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 RSemaphoreInterruptedException - if the current thread is interruptedpublic void acquire(int permits)
throws InterruptedException
RSemaphoreAcquires 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 RSemaphorepermits - the number of permits to acquireInterruptedException - if the current thread is interruptedpublic RFuture<Void> acquireAsync()
RSemaphoreAsyncAcquires a permit, if one is available and returns immediately, reducing the number of available permits by one.
acquireAsync in interface RSemaphoreAsyncpublic RFuture<Void> acquireAsync(int permits)
RSemaphoreAsyncacquireAsync in interface RSemaphoreAsyncpermits - the number of permits to acquirepublic boolean tryAcquire()
RSemaphoreAcquires 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 RSemaphoretrue if a permit was acquired and false
otherwisepublic boolean tryAcquire(int permits)
RSemaphoreAcquires 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 RSemaphorepermits - the number of permits to acquiretrue if a permit was acquired and false
otherwisepublic RFuture<Boolean> tryAcquireAsync()
RSemaphoreAsyncAcquires 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 RSemaphoreAsynctrue if a permit was acquired and false
otherwisepublic RFuture<Boolean> tryAcquireAsync(int permits)
RSemaphoreAsyncAcquires 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 RSemaphoreAsyncpermits - the number of permits to acquiretrue if a permit was acquired and false
otherwisepublic RFuture<Boolean> tryAcquireAsync(long waitTime, TimeUnit unit)
RSemaphoreAsyncAcquires 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 RSemaphoreAsyncwaitTime - 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
RSemaphoreAcquires 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 RSemaphorepermits - 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)
RSemaphoreAsyncAcquires 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 RSemaphoreAsyncpermits - 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
RSemaphoreAcquires 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 RSemaphoretime - 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()
RSemaphoreReleases 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 RSemaphorepublic void release(int permits)
RSemaphoreReleases 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 RSemaphorepermits - amountpublic RFuture<Void> releaseAsync()
RSemaphoreAsyncReleases 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 RSemaphoreAsyncpublic RFuture<Void> releaseAsync(int permits)
RSemaphoreAsyncReleases 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 RSemaphoreAsyncpermits - amountpublic int drainPermits()
RSemaphoredrainPermits in interface RSemaphorepublic int availablePermits()
RSemaphoreavailablePermits in interface RSemaphorepublic boolean trySetPermits(int permits)
RSemaphoretrySetPermits in interface RSemaphorepermits - - number of permitstrue if permits has been set successfully, otherwise false.public RFuture<Boolean> trySetPermitsAsync(int permits)
RSemaphoreAsynctrySetPermitsAsync in interface RSemaphoreAsyncpermits - - number of permitstrue if permits has been set successfully, otherwise false.public void reducePermits(int permits)
RSemaphorereducePermits in interface RSemaphorepermits - - reduction the number of permits to removepublic RFuture<Void> reducePermitsAsync(int permits)
RSemaphoreAsyncRSemaphoreAsync.acquireAsync() in that it does not block
waiting for permits to become available.reducePermitsAsync in interface RSemaphoreAsyncpermits - - reduction the number of permits to removepublic boolean expire(long timeToLive,
TimeUnit timeUnit)
RExpirableexpire in interface RExpirabletimeToLive - - 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)
RExpirableAsyncexpireAsync in interface RExpirableAsynctimeToLive - - timeout before object will be deletedtimeUnit - - timeout time unittrue if the timeout was set and false if notpublic boolean expireAt(long timestamp)
RExpirableexpireAt in interface RExpirabletimestamp - - expire date in milliseconds (Unix timestamp)true if the timeout was set and false if notpublic RFuture<Boolean> expireAtAsync(long timestamp)
RExpirableAsyncexpireAtAsync in interface RExpirableAsynctimestamp - - expire date in seconds (Unix timestamp)true if the timeout was set and false if notpublic boolean expireAt(Date timestamp)
RExpirableexpireAt in interface RExpirabletimestamp - - expire datetrue if the timeout was set and false if notpublic RFuture<Boolean> expireAtAsync(Date timestamp)
RExpirableAsyncexpireAtAsync in interface RExpirableAsynctimestamp - - expire datetrue if the timeout was set and false if notpublic boolean clearExpire()
RExpirableclearExpire in interface RExpirabletrue if timeout was removed
false if object does not exist or does not have an associated timeoutpublic RFuture<Boolean> clearExpireAsync()
RExpirableAsyncclearExpireAsync in interface RExpirableAsynctrue if the timeout was cleared and false if notpublic long remainTimeToLive()
RExpirableremainTimeToLive in interface RExpirablepublic RFuture<Long> remainTimeToLiveAsync()
RExpirableAsyncremainTimeToLiveAsync in interface RExpirableAsyncCopyright © 2014–2018 The Redisson Project. All rights reserved.