public class Boundary
extends java.lang.Object
Boundary is a blocking utility that allows the user to bind an arbitrary number of Consumers to it. Whenever bind(reactor.function.Consumer) is called, it returns a new Consumer
that
internally creates a CountDownLatch which calls the delegate Consumer, then counts down the latch.
Calling await() or await(long, java.util.concurrent.TimeUnit) on the Boundary will block
the calling thread until all bound latches are released.
The timeout value given is the total timeout value and not the per-latch timeout value. If a timeout of 5 seconds is
specified and there are 100 latches bound, then all 100 latches have a combined 5 seconds to be counted down, not 5
seconds per latch, which would equate to a little under 10 minutes.| Constructor and Description |
|---|
Boundary() |
| Modifier and Type | Method and Description |
|---|---|
boolean |
await()
Wait for all latches to be counted down (almost) indefinitely.
|
boolean |
await(long timeout,
java.util.concurrent.TimeUnit timeUnit)
Wait for all latches to be counted down within the given timeout window.
|
<T> Consumer<T> |
bind(Consumer<T> consumer)
|
<T> Consumer<T> |
bind(Consumer<T> consumer,
int expected)
|
public <T> Consumer<T> bind(Consumer<T> consumer)
Consumer to this Boundary by creating a CountDownLatch that will be counted
down the first time the given Consumer is invoked.T - The type of the value accepted by the Consumerconsumer - The delegate ConsumerConsumer which will count down the internal latch after invoking the delegate Consumerpublic <T> Consumer<T> bind(Consumer<T> consumer, int expected)
Consumer to this Boundary by creating a CountDownLatch of the given size
that will be counted down the every time the given Consumer is invoked.T - The type of the value accepted by the Consumerconsumer - The delegate ConsumerConsumer which will count down the internal latch after invoking the delegate Consumerpublic boolean await()
true if all latches were counted down within the timeout value, false otherwisepublic boolean await(long timeout,
java.util.concurrent.TimeUnit timeUnit)
timeout - The timeout value.timeUnit - The unit of time measured by the timeout value.true if all latches were counted down within the timeout value, false otherwise