Package org.apache.flink.core.testutils
Class OneShotLatch
- java.lang.Object
-
- org.apache.flink.core.testutils.OneShotLatch
-
public final class OneShotLatch extends Object
-
-
Constructor Summary
Constructors Constructor Description OneShotLatch()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidawait()Waits untiltrigger()is called.voidawait(long timeout, TimeUnit timeUnit)Waits untiltrigger()is called.voidawaitQuietly()voidawaitQuietly(long timeout, TimeUnit timeUnit)Callsawait(long, TimeUnit)and transforms anyInterruptedExceptionorTimeoutExceptioninto aRuntimeException.intgetWaitersCount()booleanisTriggered()Checks if the latch was triggered.voidreset()Resets the latch so thatisTriggered()returns false.StringtoString()voidtrigger()Fires the latch.
-
-
-
Method Detail
-
trigger
public void trigger()
Fires the latch. Code that is blocked onawait()will now return.
-
await
public void await() throws InterruptedExceptionWaits untiltrigger()is called. Oncetrigger()has been called this call will always return immediately.- Throws:
InterruptedException- Thrown if the thread is interrupted while waiting.
-
awaitQuietly
public void awaitQuietly()
-
await
public void await(long timeout, TimeUnit timeUnit) throws InterruptedException, TimeoutExceptionWaits untiltrigger()is called. Once#trigger()has been called this call will always return immediately.If the latch is not triggered within the given timeout, a
TimeoutExceptionwill be thrown after the timeout.A timeout value of zero means infinite timeout and make this equivalent to
await().- Parameters:
timeout- The value of the timeout, a value of zero indicating infinite timeout.timeUnit- The unit of the timeout- Throws:
InterruptedException- Thrown if the thread is interrupted while waiting.TimeoutException- Thrown, if the latch is not triggered within the timeout time.
-
awaitQuietly
public void awaitQuietly(long timeout, TimeUnit timeUnit)Callsawait(long, TimeUnit)and transforms anyInterruptedExceptionorTimeoutExceptioninto aRuntimeException.
-
isTriggered
public boolean isTriggered()
Checks if the latch was triggered.- Returns:
- True, if the latch was triggered, false if not.
-
getWaitersCount
public int getWaitersCount()
-
reset
public void reset()
Resets the latch so thatisTriggered()returns false.
-
-