Class RedissonCountDownLatch
- java.lang.Object
-
- org.redisson.RedissonObject
-
- org.redisson.RedissonCountDownLatch
-
- All Implemented Interfaces:
RCountDownLatch
,RCountDownLatchAsync
,RObject
,RObjectAsync
public class RedissonCountDownLatch extends RedissonObject implements RCountDownLatch
Distributed alternative to theCountDownLatch
It has a advantage overCountDownLatch
-- count can be reset viatrySetCount(long)
.- Author:
- Nikita Koksharov
-
-
Field Summary
Fields Modifier and Type Field Description static Long
newCountMessage
static Long
zeroCountMessage
-
Fields inherited from class org.redisson.RedissonObject
codec, commandExecutor
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
RedissonCountDownLatch(CommandAsyncExecutor commandExecutor, String name)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
await()
Causes the current thread to wait until the latch has counted down to zero, unless the thread is interrupted.boolean
await(long time, TimeUnit unit)
Causes the current thread to wait until the latch has counted down to zero, unless the thread is interrupted, or the specified waiting time elapses.void
countDown()
Decrements the count of the latch, releasing all waiting threads if the count reaches zero.RFuture<Void>
countDownAsync()
Decrements the count of the latch, releasing all waiting threads if the count reaches zero.RFuture<Boolean>
deleteAsync()
Delete object in async modelong
getCount()
Returns the current count.RFuture<Long>
getCountAsync()
Returns the current count.boolean
trySetCount(long count)
Sets new count value only if previous count already has reached zero or is not set at all.RFuture<Boolean>
trySetCountAsync(long count)
Sets new count value only if previous count already has reached zero or is not set at all.-
Methods inherited from class org.redisson.RedissonObject
await, copy, copyAsync, delete, 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, suffixName, toSeconds, touch, touchAsync, unlink, unlinkAsync
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.redisson.api.RObject
copy, delete, dump, getCodec, getName, isExists, migrate, move, rename, renamenx, restore, restore, restoreAndReplace, restoreAndReplace, touch, unlink
-
Methods inherited from interface org.redisson.api.RObjectAsync
copyAsync, dumpAsync, isExistsAsync, migrateAsync, moveAsync, renameAsync, renamenxAsync, restoreAndReplaceAsync, restoreAndReplaceAsync, restoreAsync, restoreAsync, touchAsync, unlinkAsync
-
-
-
-
Constructor Detail
-
RedissonCountDownLatch
protected RedissonCountDownLatch(CommandAsyncExecutor commandExecutor, String name)
-
-
Method Detail
-
await
public void await() throws InterruptedException
Description copied from interface:RCountDownLatch
Causes the current thread to wait until the latch has counted down to zero, unless the thread is interrupted.If the current count is zero then this method returns immediately.
If the current count is greater than zero then the current thread becomes disabled for thread scheduling purposes and lies dormant until one of two things happen:
- The count reaches zero due to invocations of the
RCountDownLatch.countDown()
method; or - Some other thread interrupts the current thread.
If the current thread:
- has its interrupted status set on entry to this method; or
- is interrupted while waiting,
InterruptedException
is thrown and the current thread's interrupted status is cleared.- Specified by:
await
in interfaceRCountDownLatch
- Throws:
InterruptedException
- if the current thread is interrupted while waiting
- The count reaches zero due to invocations of the
-
await
public boolean await(long time, TimeUnit unit) throws InterruptedException
Description copied from interface:RCountDownLatch
Causes the current thread to wait until the latch has counted down to zero, unless the thread is interrupted, or the specified waiting time elapses.If the current count is zero then this method returns immediately with the value
true
.If the current count is greater than zero then the current thread becomes disabled for thread scheduling purposes and lies dormant until one of three things happen:
- The count reaches zero due to invocations of the
RCountDownLatch.countDown()
method; or - Some other thread interrupts the current thread; or
- The specified waiting time elapses.
If the count reaches zero then the method returns with the value
true
.If the current thread:
- has its interrupted status set on entry to this method; or
- is interrupted while waiting,
InterruptedException
is thrown and the current thread's interrupted status is cleared.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.- Specified by:
await
in interfaceRCountDownLatch
- Parameters:
time
- the maximum time to waitunit
- the time unit of thetimeout
argument- Returns:
true
if the count reached zero andfalse
if the waiting time elapsed before the count reached zero- Throws:
InterruptedException
- if the current thread is interrupted while waiting
- The count reaches zero due to invocations of the
-
countDown
public void countDown()
Description copied from interface:RCountDownLatch
Decrements the count of the latch, releasing all waiting threads if the count reaches zero.If the current count is greater than zero then it is decremented. If the new count is zero then all waiting threads are re-enabled for thread scheduling purposes.
If the current count equals zero then nothing happens.
- Specified by:
countDown
in interfaceRCountDownLatch
-
countDownAsync
public RFuture<Void> countDownAsync()
Description copied from interface:RCountDownLatchAsync
Decrements the count of the latch, releasing all waiting threads if the count reaches zero.If the current count is greater than zero then it is decremented. If the new count is zero then all waiting threads are re-enabled for thread scheduling purposes.
If the current count equals zero then nothing happens.
- Specified by:
countDownAsync
in interfaceRCountDownLatchAsync
- Returns:
- void
-
getCount
public long getCount()
Description copied from interface:RCountDownLatch
Returns the current count.This method is typically used for debugging and testing purposes.
- Specified by:
getCount
in interfaceRCountDownLatch
- Returns:
- the current count
-
getCountAsync
public RFuture<Long> getCountAsync()
Description copied from interface:RCountDownLatchAsync
Returns the current count.This method is typically used for debugging and testing purposes.
- Specified by:
getCountAsync
in interfaceRCountDownLatchAsync
- Returns:
- the current count
-
trySetCount
public boolean trySetCount(long count)
Description copied from interface:RCountDownLatch
Sets new count value only if previous count already has reached zero or is not set at all.- Specified by:
trySetCount
in interfaceRCountDownLatch
- Parameters:
count
- - number of timesRCountDownLatch.countDown()
must be invoked before threads can pass throughRCountDownLatch.await()
- Returns:
true
if new count settedfalse
if previous count has not reached zero
-
trySetCountAsync
public RFuture<Boolean> trySetCountAsync(long count)
Description copied from interface:RCountDownLatchAsync
Sets new count value only if previous count already has reached zero or is not set at all.- Specified by:
trySetCountAsync
in interfaceRCountDownLatchAsync
- Parameters:
count
- - number of timescountDown
must be invoked before threads can pass throughawait
- Returns:
true
if new count settedfalse
if previous count has not reached zero
-
deleteAsync
public RFuture<Boolean> deleteAsync()
Description copied from interface:RObjectAsync
Delete object in async mode- Specified by:
deleteAsync
in interfaceRObjectAsync
- Overrides:
deleteAsync
in classRedissonObject
- Returns:
true
if object was deletedfalse
if not
-
-