Package org.redisson.api
Interface RSemaphore
- All Superinterfaces:
RExpirable,RExpirableAsync,RObject,RObjectAsync,RSemaphoreAsync
- All Known Implementing Classes:
RedissonQueueSemaphore,RedissonSemaphore
Redis based implementation of
Semaphore.
Works in non-fair mode. Therefore order of acquiring is unpredictable.
- Author:
- Nikita Koksharov
-
Method Summary
Modifier and TypeMethodDescriptionvoidacquire()Acquires a permit.voidacquire(int permits) Acquires defined amount ofpermits.voidaddPermits(int permits) Increases or decreases the number of available permits by defined value.intReturns amount of available permits.intAcquires and returns all permits that are immediately available.voidrelease()Releases a permit.voidrelease(int permits) Releases defined amount ofpermits.booleanTries to acquire currently available permit.booleantryAcquire(int permits) Tries to acquire defined amount of currently availablepermits.booleantryAcquire(int permits, long waitTime, TimeUnit unit) Deprecated.booleantryAcquire(int permits, Duration waitTime) Tries to acquire defined amount of currently availablepermits.booleantryAcquire(long waitTime, TimeUnit unit) Deprecated.booleantryAcquire(Duration waitTime) Tries to acquire currently available permit.booleantrySetPermits(int permits) Tries to set number of permits.booleantrySetPermits(int permits, Duration timeToLive) Tries to set number of permits with defined time to live.Methods 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, copy, copy, copyAndReplace, copyAndReplace, 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, copyAndReplaceAsync, copyAndReplaceAsync, copyAsync, copyAsync, copyAsync, deleteAsync, dumpAsync, getIdleTimeAsync, isExistsAsync, migrateAsync, moveAsync, removeListenerAsync, renameAsync, renamenxAsync, restoreAndReplaceAsync, restoreAndReplaceAsync, restoreAsync, restoreAsync, sizeInMemoryAsync, touchAsync, unlinkAsyncMethods inherited from interface org.redisson.api.RSemaphoreAsync
acquireAsync, acquireAsync, addPermitsAsync, availablePermitsAsync, drainPermitsAsync, releaseAsync, releaseAsync, tryAcquireAsync, tryAcquireAsync, tryAcquireAsync, tryAcquireAsync, tryAcquireAsync, tryAcquireAsync, trySetPermitsAsync, trySetPermitsAsync
-
Method Details
-
acquire
Acquires a permit. Waits if necessary until a permit became available.- Throws:
InterruptedException- if the current thread was interrupted
-
acquire
Acquires defined amount ofpermits. Waits if necessary until all permits became available.- Parameters:
permits- the number of permits to acquire- Throws:
InterruptedException- if the current thread is interruptedIllegalArgumentException- ifpermitsis negative
-
tryAcquire
boolean tryAcquire()Tries to acquire currently available permit.- Returns:
trueif a permit was acquired andfalseotherwise
-
tryAcquire
boolean tryAcquire(int permits) Tries to acquire defined amount of currently availablepermits.- Parameters:
permits- the number of permits to acquire- Returns:
trueif permits were acquired andfalseotherwise
-
tryAcquire
Tries to acquire currently available permit. Waits up to definedwaitTimeif necessary until a permit became available.- Parameters:
waitTime- the maximum time to wait- Returns:
trueif a permit was acquired andfalseotherwise- Throws:
InterruptedException- if the current thread was interrupted
-
tryAcquire
Deprecated.UsetryAcquire(Duration)instead- Parameters:
waitTime- the maximum time to waitunit- the time unit- Returns:
trueif a permit was acquired andfalseotherwise- Throws:
InterruptedException- if the current thread was interrupted
-
tryAcquire
@Deprecated boolean tryAcquire(int permits, long waitTime, TimeUnit unit) throws InterruptedException Deprecated.UsetryAcquire(int, Duration)instead- 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
-
tryAcquire
Tries to acquire defined amount of currently availablepermits. Waits up to definedwaitTimeif necessary until all permits became available.- Parameters:
permits- amount of permitswaitTime- the maximum time to wait- Returns:
trueif permits were acquired andfalseotherwise- Throws:
InterruptedException- if the current thread was interrupted
-
release
void release()Releases a permit. Increases the number of available permits. -
release
void release(int permits) Releases defined amount ofpermits. Increases the number of available permits bypermitsamount.- Parameters:
permits- amount of permits
-
availablePermits
int availablePermits()Returns amount of available permits.- Returns:
- number of permits
-
drainPermits
int drainPermits()Acquires and returns all permits that are immediately available.- Returns:
- number of permits
-
trySetPermits
boolean trySetPermits(int permits) Tries to set number of permits.- Parameters:
permits- number of permits- Returns:
trueif permits has been set successfully, otherwisefalseif permits were already set.
-
trySetPermits
Tries to set number of permits with defined time to live.- Parameters:
permits- number of permitstimeToLive- time to live- Returns:
trueif permits has been set successfully, otherwisefalseif permits were already set.
-
addPermits
void addPermits(int permits) Increases or decreases the number of available permits by defined value.- Parameters:
permits- amount of permits to add/remove
-