Package org.redisson
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 inherited from class org.redisson.RedissonObject
codec, commandExecutor, name
-
-
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()
Waits until counter reach zero.boolean
await(long time, TimeUnit unit)
Waits until counter reach zero or up to definedtimeout
.RFuture<Void>
awaitAsync()
Waits until counter reach zero.RFuture<Boolean>
awaitAsync(long waitTime, TimeUnit unit)
Waits until counter reach zero or up to definedtimeout
.void
countDown()
Decrements the counter of the latch.RFuture<Void>
countDownAsync()
Decrements the counter of the latch.RFuture<Boolean>
deleteAsync()
Delete object in async modelong
getCount()
Returns value of current count.RFuture<Long>
getCountAsync()
Returns value of 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
addListener, addListener, addListenerAsync, addListenerAsync, copy, copyAsync, delete, deleteAsync, dump, dumpAsync, encode, encode, encode, encode, encodeMapKey, encodeMapKeys, encodeMapValue, encodeMapValues, get, getCodec, getIdleTime, getIdleTimeAsync, getLockByMapKey, getLockByValue, getName, getRawName, getRawName, isExists, isExistsAsync, 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, 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
addListener, copy, delete, dump, getCodec, getIdleTime, getName, isExists, migrate, move, removeListener, rename, renamenx, restore, restore, restoreAndReplace, restoreAndReplace, sizeInMemory, touch, unlink
-
Methods inherited from interface org.redisson.api.RObjectAsync
addListenerAsync, copyAsync, dumpAsync, getIdleTimeAsync, isExistsAsync, migrateAsync, moveAsync, removeListenerAsync, renameAsync, renamenxAsync, restoreAndReplaceAsync, restoreAndReplaceAsync, restoreAsync, restoreAsync, sizeInMemoryAsync, touchAsync, unlinkAsync
-
-
-
-
Constructor Detail
-
RedissonCountDownLatch
protected RedissonCountDownLatch(CommandAsyncExecutor commandExecutor, String name)
-
-
Method Detail
-
await
public void await() throws InterruptedException
Description copied from interface:RCountDownLatch
Waits until counter reach zero.- Specified by:
await
in interfaceRCountDownLatch
- Throws:
InterruptedException
- if the current thread was interrupted
-
awaitAsync
public RFuture<Void> awaitAsync()
Description copied from interface:RCountDownLatchAsync
Waits until counter reach zero.- Specified by:
awaitAsync
in interfaceRCountDownLatchAsync
- Returns:
- void
-
await
public boolean await(long time, TimeUnit unit) throws InterruptedException
Description copied from interface:RCountDownLatch
Waits until counter reach zero or up to definedtimeout
.- Specified by:
await
in interfaceRCountDownLatch
- Parameters:
time
- the maximum time to waitunit
- the time unit- Returns:
true
if the count reached zero andfalse
if timeout reached before the count reached zero- Throws:
InterruptedException
- if the current thread was interrupted
-
awaitAsync
public RFuture<Boolean> awaitAsync(long waitTime, TimeUnit unit)
Description copied from interface:RCountDownLatchAsync
Waits until counter reach zero or up to definedtimeout
.- Specified by:
awaitAsync
in interfaceRCountDownLatchAsync
- Parameters:
waitTime
- the maximum time to waitunit
- the time unit- Returns:
true
if the count reached zero andfalse
if timeout reached before the count reached zero
-
countDown
public void countDown()
Description copied from interface:RCountDownLatch
Decrements the counter of the latch. Notifies all waiting threads when count reaches zero.- Specified by:
countDown
in interfaceRCountDownLatch
-
countDownAsync
public RFuture<Void> countDownAsync()
Description copied from interface:RCountDownLatchAsync
Decrements the counter of the latch. Notifies all waiting threads when count reaches zero.- Specified by:
countDownAsync
in interfaceRCountDownLatchAsync
- Returns:
- void
-
getCount
public long getCount()
Description copied from interface:RCountDownLatch
Returns value of current count.- Specified by:
getCount
in interfaceRCountDownLatch
- Returns:
- current count
-
getCountAsync
public RFuture<Long> getCountAsync()
Description copied from interface:RCountDownLatchAsync
Returns value of current count.- 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
-
-