public class LatchEventHandler extends java.lang.Object implements EventCollector.EventHandler<java.lang.Object>
Implementation of the EventCollector.EventHandler backed by an instance of the CountDownLatch.
Handler returns true from the test(Object) method for any argument for as long a latch has positive count.
When eventCollected(Object) is called with any argument - latch gets counted down.
await(long, TimeUnit),
awaitSeconds(int),
awaitMillis(long),
isOpen(),
close()| Constructor and Description |
|---|
LatchEventHandler(java.util.concurrent.CountDownLatch latch) |
| Modifier and Type | Method and Description |
|---|---|
boolean |
await(long timeout,
java.util.concurrent.TimeUnit unit)
If this latch is open equal to calling
CountDownLatch.await(long, TimeUnit) on the underlying latch |
boolean |
awaitAndClose(long timeout,
java.util.concurrent.TimeUnit unit) |
boolean |
awaitMillis(long millis)
Equal to
await(long, TimeUnit) with specified timeout and TimeUnit.MILLISECONDS |
boolean |
awaitSeconds(int second)
Equal to
await(long, TimeUnit) with specified timeout and TimeUnit.SECONDS |
boolean |
awaitSecondsAndClose(int seconds) |
void |
close()
This latch is closed.
|
void |
eventCollected(java.lang.Object event)
If this latch is open this method counts underlying latch down for any argument
|
java.util.concurrent.CountDownLatch |
getLatch() |
boolean |
isOpen()
Returns
true if this latch is open and underlying latch has positive count |
boolean |
test(java.lang.Object t)
This method calls
isOpen() for any argument |
public LatchEventHandler(java.util.concurrent.CountDownLatch latch)
public boolean isOpen()
true if this latch is open and underlying latch has positive countpublic java.util.concurrent.CountDownLatch getLatch()
public void close()
public boolean awaitSeconds(int second)
await(long, TimeUnit) with specified timeout and TimeUnit.SECONDSpublic boolean awaitMillis(long millis)
await(long, TimeUnit) with specified timeout and TimeUnit.MILLISECONDSpublic boolean await(long timeout,
java.util.concurrent.TimeUnit unit)
CountDownLatch.await(long, TimeUnit) on the underlying latchpublic boolean awaitSecondsAndClose(int seconds)
public boolean awaitAndClose(long timeout,
java.util.concurrent.TimeUnit unit)
public boolean test(java.lang.Object t)
isOpen() for any argumenttest in interface java.util.function.Predicate<java.lang.Object>public void eventCollected(java.lang.Object event)
eventCollected in interface EventCollector.EventHandler<java.lang.Object>