Package org.redisson
Class RedissonSemaphore
java.lang.Object
org.redisson.RedissonObject
org.redisson.RedissonSemaphore
- All Implemented Interfaces:
RExpirable,RExpirableAsync,RObject,RObjectAsync,RSemaphore,RSemaphoreAsync
- Direct Known Subclasses:
RedissonQueueSemaphore
Distributed and concurrent implementation of
Semaphore.
Works in non-fair mode. Therefore order of acquiring is unpredictable.
- Author:
- Nikita Koksharov
-
Field Summary
Fields inherited from class org.redisson.RedissonObject
codec, commandExecutor, name -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidacquire()Acquires a permit.voidacquire(int permits) Acquires defined amount ofpermits.Acquires a permit.acquireAsync(int permits) Acquires defined amount ofpermits.voidaddPermits(int permits) Increases or decreases the number of available permits by defined value.addPermitsAsync(int permits) Increases or decreases the number of available permits by defined value.intReturns amount of available permits.Returns amount of available permits.booleanClear an expire timeout or expire date for object.Clear an expire timeout or expire date for object in async mode.clearExpireAsync(String... keys) intAcquires and returns all permits that are immediately available.Acquires and returns all permits that are immediately available.booleanUseRExpirable.expire(Duration)insteadbooleanSets a timeout for this object.booleanSets an expiration date for this object.expireAsync(long timeToLive, TimeUnit timeUnit) UseRExpirableAsync.expireAsync(Duration)insteadexpireAsync(long timeToLive, TimeUnit timeUnit, String param, String... keys) expireAsync(Duration duration) Set a timeout for object.expireAsync(Instant instant) Set an expire date for object.booleanexpireAt(long timestamp) UseRExpirable.expire(Instant)insteadbooleanUseRExpirable.expire(Instant)insteadexpireAtAsync(long timestamp) UseRExpirableAsync.expireAsync(Instant)insteadexpireAtAsync(long timestamp, String param, String... keys) expireAtAsync(Date timestamp) UseRExpirableAsync.expireAsync(Instant)insteadbooleanexpireIfGreater(Duration duration) Sets a timeout for this object only if it's greater than timeout set before.booleanexpireIfGreater(Instant time) Sets an expiration date for this object only if it's greater than expiration date set before.expireIfGreaterAsync(Duration duration) Sets a timeout for this object only if it's greater than timeout set before.expireIfGreaterAsync(Instant time) Sets an expiration date for this object only if it's greater than expiration date set before.booleanexpireIfLess(Duration duration) Sets a timeout for this object only if it's less than timeout set before.booleanexpireIfLess(Instant time) Sets an expiration date for this object only if it's less than expiration date set before.expireIfLessAsync(Duration duration) Sets a timeout for this object only if it's less than timeout set before.expireIfLessAsync(Instant time) Sets an expiration date for this object only if it's less than expiration date set before.booleanexpireIfNotSet(Duration duration) Sets a timeout for this object only if it hasn't been set before.booleanexpireIfNotSet(Instant time) Sets an expiration date for this object only if it hasn't been set before.expireIfNotSetAsync(Duration duration) Sets a timeout for this object only if it hasn't been set before.expireIfNotSetAsync(Instant time) Sets an expiration date for this object only if it hasn't been set before.booleanexpireIfSet(Duration duration) Sets a timeout for this object only if it has been already set.booleanexpireIfSet(Instant time) Sets an expiration date for this object only if it has been already set.expireIfSetAsync(Duration duration) Sets a timeout for this object only if it has been already set.expireIfSetAsync(Instant time) Sets an expiration date for this object only if it has been already set.static StringgetChannelName(String name) longExpiration time of Redisson object that has a timeoutExpiration time of Redisson object that has a timeoutvoidrelease()Releases a permit.voidrelease(int permits) Releases defined amount ofpermits.Releases a permit.releaseAsync(int permits) Releases defined amount ofpermits.longRemaining time to live of Redisson object that has a timeoutRemaining time to live of Redisson object that has a timeoutbooleanTries to acquire currently available permit.booleantryAcquire(int permits) Tries to acquire defined amount of currently availablepermits.booleantryAcquire(int permits, long waitTime, TimeUnit unit) Tries to acquire defined amount of currently availablepermits.booleantryAcquire(long time, TimeUnit unit) Tries to acquire currently available permit.Acquires a permit.tryAcquireAsync(int permits) Tries to acquire defined amount of currently availablepermits.tryAcquireAsync(int permits, long waitTime, TimeUnit unit) Tries to acquire defined amount of currently availablepermits.tryAcquireAsync(long waitTime, TimeUnit unit) Tries to acquire currently available permit.booleantrySetPermits(int permits) Tries to set number of permits.trySetPermitsAsync(int permits) Tries to set number of permits.Methods inherited from class org.redisson.RedissonObject
addListener, addListener, addListenerAsync, addListenerAsync, copy, copyAsync, delete, deleteAsync, deleteAsync, dump, dumpAsync, encode, encode, encode, encode, encodeMapKey, encodeMapKey, encodeMapKeys, encodeMapValue, encodeMapValues, get, getCodec, getIdleTime, getIdleTimeAsync, getLockByMapKey, getLockByValue, getName, getRawName, getRawName, getServiceManager, getSubscribeService, isExists, isExistsAsync, map, migrate, migrateAsync, move, moveAsync, prefixName, removeListener, removeListenerAsync, rename, renameAsync, renamenx, renamenxAsync, restore, restore, restoreAndReplace, restoreAndReplace, restoreAndReplaceAsync, restoreAndReplaceAsync, restoreAsync, restoreAsync, setName, sizeInMemory, sizeInMemoryAsync, sizeInMemoryAsync, sizeInMemoryAsync, suffixName, toSeconds, toStream, touch, touchAsync, unlink, unlinkAsyncMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.redisson.api.RExpirable
clearExpire, expire, expire, expire, expireAt, expireAt, expireIfGreater, expireIfGreater, expireIfLess, expireIfLess, expireIfNotSet, expireIfNotSet, expireIfSet, expireIfSet, getExpireTime, remainTimeToLiveMethods inherited from interface org.redisson.api.RExpirableAsync
clearExpireAsync, expireAsync, expireAsync, expireAsync, expireAtAsync, expireAtAsync, expireIfGreaterAsync, expireIfGreaterAsync, expireIfLessAsync, expireIfLessAsync, expireIfNotSetAsync, expireIfNotSetAsync, expireIfSetAsync, expireIfSetAsync, getExpireTimeAsync, remainTimeToLiveAsyncMethods inherited from interface org.redisson.api.RObject
addListener, copy, delete, dump, getCodec, getIdleTime, getName, isExists, migrate, move, removeListener, rename, renamenx, restore, restore, restoreAndReplace, restoreAndReplace, sizeInMemory, touch, unlinkMethods inherited from interface org.redisson.api.RObjectAsync
addListenerAsync, copyAsync, deleteAsync, dumpAsync, getIdleTimeAsync, isExistsAsync, migrateAsync, moveAsync, removeListenerAsync, renameAsync, renamenxAsync, restoreAndReplaceAsync, restoreAndReplaceAsync, restoreAsync, restoreAsync, sizeInMemoryAsync, touchAsync, unlinkAsync
-
Constructor Details
-
RedissonSemaphore
-
-
Method Details
-
getChannelName
-
acquire
Description copied from interface:RSemaphoreAcquires a permit. Waits if necessary until a permit became available.- Specified by:
acquirein interfaceRSemaphore- Throws:
InterruptedException- if the current thread was interrupted
-
acquire
Description copied from interface:RSemaphoreAcquires defined amount ofpermits. Waits if necessary until all permits became available.- Specified by:
acquirein interfaceRSemaphore- Parameters:
permits- the number of permits to acquire- Throws:
InterruptedException- if the current thread is interrupted
-
acquireAsync
Description copied from interface:RSemaphoreAsyncAcquires a permit. Waits if necessary until a permit became available.- Specified by:
acquireAsyncin interfaceRSemaphoreAsync- Returns:
- void
-
acquireAsync
Description copied from interface:RSemaphoreAsyncAcquires defined amount ofpermits. Waits if necessary until all permits became available.- Specified by:
acquireAsyncin interfaceRSemaphoreAsync- Parameters:
permits- the number of permits to acquire- Returns:
- void
-
tryAcquire
public boolean tryAcquire()Description copied from interface:RSemaphoreTries to acquire currently available permit.- Specified by:
tryAcquirein interfaceRSemaphore- Returns:
trueif a permit was acquired andfalseotherwise
-
tryAcquire
public boolean tryAcquire(int permits) Description copied from interface:RSemaphoreTries to acquire defined amount of currently availablepermits.- Specified by:
tryAcquirein interfaceRSemaphore- Parameters:
permits- the number of permits to acquire- Returns:
trueif permits were acquired andfalseotherwise
-
tryAcquireAsync
Description copied from interface:RSemaphoreAsyncAcquires a permit. Waits if necessary until a permit became available.- Specified by:
tryAcquireAsyncin interfaceRSemaphoreAsync- Returns:
trueif a permit was acquired andfalseotherwise
-
tryAcquireAsync
Description copied from interface:RSemaphoreAsyncTries to acquire defined amount of currently availablepermits.- Specified by:
tryAcquireAsyncin interfaceRSemaphoreAsync- Parameters:
permits- the number of permits to acquire- Returns:
trueif permits were acquired andfalseotherwise
-
tryAcquireAsync
Description copied from interface:RSemaphoreAsyncTries to acquire currently available permit. Waits up to definedwaitTimeif necessary until a permit became available.- Specified by:
tryAcquireAsyncin interfaceRSemaphoreAsync- Parameters:
waitTime- the maximum time to waitunit- the time unit- Returns:
trueif a permit was acquired andfalseotherwise
-
tryAcquire
Description copied from interface:RSemaphoreTries to acquire defined amount of currently availablepermits. Waits up to definedwaitTimeif necessary until all permits became available.- Specified by:
tryAcquirein interfaceRSemaphore- Parameters:
permits- amount of permitswaitTime- the maximum time to waitunit- the time unit- Returns:
trueif permits were acquired andfalseotherwise- Throws:
InterruptedException- if the current thread was interrupted
-
tryAcquireAsync
Description copied from interface:RSemaphoreAsyncTries to acquire defined amount of currently availablepermits. Waits up to definedwaitTimeif necessary until all permits became available.- Specified by:
tryAcquireAsyncin interfaceRSemaphoreAsync- Parameters:
permits- amount of permitswaitTime- the maximum time to waitunit- the time unit- Returns:
trueif permits were acquired andfalseotherwise
-
tryAcquire
Description copied from interface:RSemaphoreTries to acquire currently available permit. Waits up to definedwaitTimeif necessary until a permit became available.- Specified by:
tryAcquirein interfaceRSemaphore- Parameters:
time- the maximum time to waitunit- the time unit- Returns:
trueif a permit was acquired andfalseotherwise- Throws:
InterruptedException- if the current thread was interrupted
-
release
public void release()Description copied from interface:RSemaphoreReleases a permit. Increases the number of available permits.- Specified by:
releasein interfaceRSemaphore
-
release
public void release(int permits) Description copied from interface:RSemaphoreReleases defined amount ofpermits. Increases the number of available permits bypermitsamount.- Specified by:
releasein interfaceRSemaphore- Parameters:
permits- amount of permits
-
releaseAsync
Description copied from interface:RSemaphoreAsyncReleases a permit.- Specified by:
releaseAsyncin interfaceRSemaphoreAsync- Returns:
- void
-
releaseAsync
Description copied from interface:RSemaphoreAsyncReleases defined amount ofpermits.- Specified by:
releaseAsyncin interfaceRSemaphoreAsync- Parameters:
permits- amount- Returns:
- void
-
drainPermits
public int drainPermits()Description copied from interface:RSemaphoreAcquires and returns all permits that are immediately available.- Specified by:
drainPermitsin interfaceRSemaphore- Returns:
- number of permits
-
drainPermitsAsync
Description copied from interface:RSemaphoreAsyncAcquires and returns all permits that are immediately available.- Specified by:
drainPermitsAsyncin interfaceRSemaphoreAsync- Returns:
- number of permits
-
availablePermits
public int availablePermits()Description copied from interface:RSemaphoreReturns amount of available permits.- Specified by:
availablePermitsin interfaceRSemaphore- Returns:
- number of permits
-
availablePermitsAsync
Description copied from interface:RSemaphoreAsyncReturns amount of available permits.- Specified by:
availablePermitsAsyncin interfaceRSemaphoreAsync- Returns:
- number of permits
-
trySetPermits
public boolean trySetPermits(int permits) Description copied from interface:RSemaphoreTries to set number of permits.- Specified by:
trySetPermitsin interfaceRSemaphore- Parameters:
permits- - number of permits- Returns:
trueif permits has been set successfully, otherwisefalseif permits were already set.
-
trySetPermitsAsync
Description copied from interface:RSemaphoreAsyncTries to set number of permits.- Specified by:
trySetPermitsAsyncin interfaceRSemaphoreAsync- Parameters:
permits- - number of permits- Returns:
trueif permits has been set successfully, otherwisefalse.
-
addPermits
public void addPermits(int permits) Description copied from interface:RSemaphoreIncreases or decreases the number of available permits by defined value.- Specified by:
addPermitsin interfaceRSemaphore- Parameters:
permits- amount of permits to add/remove
-
addPermitsAsync
Description copied from interface:RSemaphoreAsyncIncreases or decreases the number of available permits by defined value.- Specified by:
addPermitsAsyncin interfaceRSemaphoreAsync- Parameters:
permits- amount of permits to add/remove
-
expire
Description copied from interface:RExpirableUseRExpirable.expire(Duration)instead- Specified by:
expirein interfaceRExpirable- Parameters:
timeToLive- - timeout before object will be deletedtimeUnit- - timeout time unit- Returns:
trueif the timeout was set andfalseif not
-
expireAsync
Description copied from interface:RExpirableAsyncUseRExpirableAsync.expireAsync(Duration)instead- Specified by:
expireAsyncin interfaceRExpirableAsync- Parameters:
timeToLive- - timeout before object will be deletedtimeUnit- - timeout time unit- Returns:
trueif the timeout was set andfalseif not
-
expireAt
public boolean expireAt(long timestamp) Description copied from interface:RExpirableUseRExpirable.expire(Instant)instead- Specified by:
expireAtin interfaceRExpirable- Parameters:
timestamp- - expire date in milliseconds (Unix timestamp)- Returns:
trueif the timeout was set andfalseif not
-
expireAtAsync
Description copied from interface:RExpirableAsyncUseRExpirableAsync.expireAsync(Instant)instead- Specified by:
expireAtAsyncin interfaceRExpirableAsync- Parameters:
timestamp- - expire date in milliseconds (Unix timestamp)- Returns:
trueif the timeout was set andfalseif not
-
expire
Description copied from interface:RExpirableSets an expiration date for this object. When expire date comes the key will automatically be deleted.- Specified by:
expirein interfaceRExpirable- Parameters:
instant- expire date- Returns:
trueif the timeout was set andfalseif not
-
expireIfSet
Description copied from interface:RExpirableSets an expiration date for this object only if it has been already set. When expire date comes the object will automatically be deleted.Requires Redis 7.0.0 and higher.
- Specified by:
expireIfSetin interfaceRExpirable- Parameters:
time- expire date- Returns:
trueif the timeout was set andfalseif not
-
expireIfSetAsync
Description copied from interface:RExpirableAsyncSets an expiration date for this object only if it has been already set. When expire date comes the object will automatically be deleted.Requires Redis 7.0.0 and higher.
- Specified by:
expireIfSetAsyncin interfaceRExpirableAsync- Parameters:
time- expire date- Returns:
trueif the timeout was set andfalseif not
-
expireIfNotSet
Description copied from interface:RExpirableSets an expiration date for this object only if it hasn't been set before. When expire date comes the object will automatically be deleted.Requires Redis 7.0.0 and higher.
- Specified by:
expireIfNotSetin interfaceRExpirable- Parameters:
time- expire date- Returns:
trueif the timeout was set andfalseif not
-
expireIfNotSetAsync
Description copied from interface:RExpirableAsyncSets an expiration date for this object only if it hasn't been set before. When expire date comes the object will automatically be deleted.Requires Redis 7.0.0 and higher.
- Specified by:
expireIfNotSetAsyncin interfaceRExpirableAsync- Parameters:
time- expire date- Returns:
trueif the timeout was set andfalseif not
-
expireIfGreater
Description copied from interface:RExpirableSets an expiration date for this object only if it's greater than expiration date set before. When expire date comes the object will automatically be deleted.Requires Redis 7.0.0 and higher.
- Specified by:
expireIfGreaterin interfaceRExpirable- Parameters:
time- expire date- Returns:
trueif the timeout was set andfalseif not
-
expireIfGreaterAsync
Description copied from interface:RExpirableAsyncSets an expiration date for this object only if it's greater than expiration date set before. When expire date comes the object will automatically be deleted.Requires Redis 7.0.0 and higher.
- Specified by:
expireIfGreaterAsyncin interfaceRExpirableAsync- Parameters:
time- expire date- Returns:
trueif the timeout was set andfalseif not
-
expireIfLess
Description copied from interface:RExpirableSets an expiration date for this object only if it's less than expiration date set before. When expire date comes the object will automatically be deleted.Requires Redis 7.0.0 and higher.
- Specified by:
expireIfLessin interfaceRExpirable- Parameters:
time- expire date- Returns:
trueif the timeout was set andfalseif not
-
expireIfLessAsync
Description copied from interface:RExpirableAsyncSets an expiration date for this object only if it's less than expiration date set before. When expire date comes the object will automatically be deleted.Requires Redis 7.0.0 and higher.
- Specified by:
expireIfLessAsyncin interfaceRExpirableAsync- Parameters:
time- expire date- Returns:
trueif the timeout was set andfalseif not
-
expireAsync
Description copied from interface:RExpirableAsyncSet an expire date for object. When expire date comes the key will automatically be deleted.- Specified by:
expireAsyncin interfaceRExpirableAsync- Parameters:
instant- - expire date- Returns:
trueif the timeout was set andfalseif not
-
expire
Description copied from interface:RExpirableSets a timeout for this object. After the timeout has expired, the key will automatically be deleted.- Specified by:
expirein interfaceRExpirable- Parameters:
duration- timeout before object will be deleted- Returns:
trueif the timeout was set andfalseif not
-
expireAsync
Description copied from interface:RExpirableAsyncSet a timeout for object. After the timeout has expired, the key will automatically be deleted.- Specified by:
expireAsyncin interfaceRExpirableAsync- Parameters:
duration- timeout before object will be deleted- Returns:
trueif the timeout was set andfalseif not
-
expireAt
Description copied from interface:RExpirableUseRExpirable.expire(Instant)instead- Specified by:
expireAtin interfaceRExpirable- Parameters:
timestamp- - expire date- Returns:
trueif the timeout was set andfalseif not
-
expireAtAsync
Description copied from interface:RExpirableAsyncUseRExpirableAsync.expireAsync(Instant)instead- Specified by:
expireAtAsyncin interfaceRExpirableAsync- Parameters:
timestamp- - expire date- Returns:
trueif the timeout was set andfalseif not
-
expireIfSet
Description copied from interface:RExpirableSets a timeout for this object only if it has been already set. After the timeout has expired, the key will automatically be deleted.Requires Redis 7.0.0 and higher.
- Specified by:
expireIfSetin interfaceRExpirable- Parameters:
duration- timeout before object will be deleted- Returns:
trueif the timeout was set andfalseif not
-
expireIfSetAsync
Description copied from interface:RExpirableAsyncSets a timeout for this object only if it has been already set. After the timeout has expired, the key will automatically be deleted.Requires Redis 7.0.0 and higher.
- Specified by:
expireIfSetAsyncin interfaceRExpirableAsync- Parameters:
duration- timeout before object will be deleted- Returns:
trueif the timeout was set andfalseif not
-
expireIfNotSet
Description copied from interface:RExpirableSets a timeout for this object only if it hasn't been set before. After the timeout has expired, the key will automatically be deleted.Requires Redis 7.0.0 and higher.
- Specified by:
expireIfNotSetin interfaceRExpirable- Parameters:
duration- timeout before object will be deleted- Returns:
trueif the timeout was set andfalseif not
-
expireIfNotSetAsync
Description copied from interface:RExpirableAsyncSets a timeout for this object only if it hasn't been set before. After the timeout has expired, the key will automatically be deleted.Requires Redis 7.0.0 and higher.
- Specified by:
expireIfNotSetAsyncin interfaceRExpirableAsync- Parameters:
duration- timeout before object will be deleted- Returns:
trueif the timeout was set andfalseif not
-
expireIfGreater
Description copied from interface:RExpirableSets a timeout for this object only if it's greater than timeout set before. After the timeout has expired, the key will automatically be deleted.Requires Redis 7.0.0 and higher.
- Specified by:
expireIfGreaterin interfaceRExpirable- Parameters:
duration- timeout before object will be deleted- Returns:
trueif the timeout was set andfalseif not
-
expireIfGreaterAsync
Description copied from interface:RExpirableAsyncSets a timeout for this object only if it's greater than timeout set before. After the timeout has expired, the key will automatically be deleted.Requires Redis 7.0.0 and higher.
- Specified by:
expireIfGreaterAsyncin interfaceRExpirableAsync- Parameters:
duration- timeout before object will be deleted- Returns:
trueif the timeout was set andfalseif not
-
expireIfLess
Description copied from interface:RExpirableSets a timeout for this object only if it's less than timeout set before. After the timeout has expired, the key will automatically be deleted.Requires Redis 7.0.0 and higher.
- Specified by:
expireIfLessin interfaceRExpirable- Parameters:
duration- timeout before object will be deleted- Returns:
trueif the timeout was set andfalseif not
-
expireIfLessAsync
Description copied from interface:RExpirableAsyncSets a timeout for this object only if it's less than timeout set before. After the timeout has expired, the key will automatically be deleted.Requires Redis 7.0.0 and higher.
- Specified by:
expireIfLessAsyncin interfaceRExpirableAsync- Parameters:
duration- timeout before object will be deleted- Returns:
trueif the timeout was set andfalseif not
-
clearExpire
public boolean clearExpire()Description copied from interface:RExpirableClear an expire timeout or expire date for object.- Specified by:
clearExpirein interfaceRExpirable- Returns:
trueif timeout was removedfalseif object does not exist or does not have an associated timeout
-
clearExpireAsync
Description copied from interface:RExpirableAsyncClear an expire timeout or expire date for object in async mode. Object will not be deleted.- Specified by:
clearExpireAsyncin interfaceRExpirableAsync- Returns:
trueif the timeout was cleared andfalseif not
-
remainTimeToLive
public long remainTimeToLive()Description copied from interface:RExpirableRemaining time to live of Redisson object that has a timeout- Specified by:
remainTimeToLivein interfaceRExpirable- Returns:
- time in milliseconds -2 if the key does not exist. -1 if the key exists but has no associated expire.
-
remainTimeToLiveAsync
Description copied from interface:RExpirableAsyncRemaining time to live of Redisson object that has a timeout- Specified by:
remainTimeToLiveAsyncin interfaceRExpirableAsync- Returns:
- time in milliseconds -2 if the key does not exist. -1 if the key exists but has no associated expire.
-
getExpireTime
public long getExpireTime()Description copied from interface:RExpirableExpiration time of Redisson object that has a timeoutRequires Redis 7.0.0 and higher.
- Specified by:
getExpireTimein interfaceRExpirable- Returns:
- expiration time
-
getExpireTimeAsync
Description copied from interface:RExpirableAsyncExpiration time of Redisson object that has a timeoutRequires Redis 7.0.0 and higher.
- Specified by:
getExpireTimeAsyncin interfaceRExpirableAsync- Returns:
- expiration time
-
expireAsync
-
expireAtAsync
-
clearExpireAsync
-