Package io.pravega.common.util
Class ReusableLatch
- java.lang.Object
-
- io.pravega.common.util.ReusableLatch
-
public class ReusableLatch extends java.lang.ObjectThis class is similar to CountDownLatch and Semaphore. Many threads can await() the the call of release() (blocking until it is invoked.) After this all calls to await() will not block until reset is called.
-
-
Constructor Summary
Constructors Constructor Description ReusableLatch()ReusableLatch(boolean startReleased)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidawait()Block until another thread calls release, or the thread is interrupted.voidawait(long timeoutMillis)Block until another thread calls release, or the thread is interrupted.voidawaitUninterruptibly()Block until release is called by another thread.intgetQueueLength()Gets the number of threads waiting.booleanisReleased()Returns whether or not release has been called and threads can call await without blocking.voidrelease()Allow all waiting threads to go through, and all future threads to proceed without blocking.voidreset()Resets the latch to an un-release state.java.lang.StringtoString()
-
-
-
Method Detail
-
await
public void await() throws java.lang.InterruptedExceptionBlock until another thread calls release, or the thread is interrupted.- Throws:
java.lang.InterruptedException- If the operation was interrupted while waiting.
-
await
public void await(long timeoutMillis) throws java.lang.InterruptedException, java.util.concurrent.TimeoutExceptionBlock until another thread calls release, or the thread is interrupted.- Parameters:
timeoutMillis- Timeout, in milliseconds, to wait for the release.- Throws:
java.lang.InterruptedException- If the operation was interrupted while waiting.java.util.concurrent.TimeoutException- If the timeout expired prior to being able to await the release.
-
awaitUninterruptibly
public void awaitUninterruptibly()
Block until release is called by another thread.
-
release
public void release()
Allow all waiting threads to go through, and all future threads to proceed without blocking.
-
isReleased
public boolean isReleased()
Returns whether or not release has been called and threads can call await without blocking.- Returns:
- True if the latch is set to release state.
-
reset
public void reset()
Resets the latch to an un-release state.
-
getQueueLength
public int getQueueLength()
Gets the number of threads waiting.- Returns:
- The number of threads waiting.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-