public class RedissonPermitExpirableSemaphore extends Object implements RPermitExpirableSemaphore
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.
|
protected boolean |
await(RFuture<?> future,
long timeout,
TimeUnit timeoutUnit) |
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.
|
boolean |
delete()
Deletes the object
|
RFuture<Boolean> |
deleteAsync()
Delete object in async mode
|
protected byte[] |
encode(Object value) |
protected byte[] |
encodeMapKey(Object value) |
protected byte[] |
encodeMapValue(Object value) |
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() |
protected <V> V |
get(RFuture<V> future) |
static String |
getChannelName(String name) |
Codec |
getCodec()
Returns the underlying Codec used by this RObject
|
String |
getName()
Returns name of object
|
boolean |
isExists()
Check object existence
|
RFuture<Boolean> |
isExistsAsync()
Check object existence in async mode.
|
void |
migrate(String host,
int port,
int database)
Transfer an object from source Redis instance to destination Redis instance
|
RFuture<Void> |
migrateAsync(String host,
int port,
int database)
Transfer an object from source Redis instance to destination Redis instance
in async mode
|
boolean |
move(int database)
Move object to another database
|
RFuture<Boolean> |
moveAsync(int database)
Move object to another database in async mode
|
protected <V> RPromise<V> |
newPromise() |
protected <V> RFuture<V> |
newSucceededFuture(V result) |
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.
|
void |
rename(String newName)
Rename current object key to
newName |
RFuture<Void> |
renameAsync(String newName)
Rename current object key to
newName
in async mode |
boolean |
renamenx(String newName)
Rename current object key to
newName
only if new key is not exists |
RFuture<Boolean> |
renamenxAsync(String newName)
Rename current object key to
newName
in async mode only if new key is not exists |
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.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
clearExpire, expire, expireAt, expireAt, remainTimeToLive
delete, getCodec, getName, isExists, migrate, move, rename, renamenx
clearExpireAsync, expireAsync, expireAtAsync, expireAtAsync, remainTimeToLiveAsync
isExistsAsync, migrateAsync, moveAsync, renameAsync, renamenxAsync
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
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 secondsprotected boolean await(RFuture<?> future, long timeout, TimeUnit timeoutUnit) throws InterruptedException
InterruptedException
protected <V> V get(RFuture<V> future)
protected <V> RPromise<V> newPromise()
protected <V> RFuture<V> newSucceededFuture(V result)
public void rename(String newName)
RObject
newName
public RFuture<Void> renameAsync(String newName)
RObjectAsync
newName
in async moderenameAsync
in interface RObjectAsync
newName
- - new name of objectpublic void migrate(String host, int port, int database)
RObject
public RFuture<Void> migrateAsync(String host, int port, int database)
RObjectAsync
migrateAsync
in interface RObjectAsync
host
- - destination hostport
- - destination portdatabase
- - destination databasepublic boolean move(int database)
RObject
public RFuture<Boolean> moveAsync(int database)
RObjectAsync
moveAsync
in interface RObjectAsync
database
- - number of Redis databasetrue
if key was moved false
if notpublic boolean renamenx(String newName)
RObject
newName
only if new key is not existspublic RFuture<Boolean> renamenxAsync(String newName)
RObjectAsync
newName
in async mode only if new key is not existsrenamenxAsync
in interface RObjectAsync
newName
- - new name of objecttrue
if object has been renamed successfully and false
otherwisepublic boolean delete()
RObject
public boolean isExists()
RObject
public RFuture<Boolean> isExistsAsync()
RObjectAsync
isExistsAsync
in interface RObjectAsync
true
if object exists and false
otherwisepublic Codec getCodec()
RObject
protected byte[] encode(Object value)
protected byte[] encodeMapKey(Object value)
protected byte[] encodeMapValue(Object value)
Copyright © 2014–2016 The Redisson Project. All rights reserved.