public class MessageFutureBag extends Object
This class is not thread-safe; it is expected that only a single consumer will create one, populate it with futures, and then wait for the futures to be satisfied.
MessageFuture
Modifier and Type | Class and Description |
---|---|
static class |
MessageFutureBag.BagResult
Denotes the different states that a message future bag can be in.
|
Constructor and Description |
---|
MessageFutureBag(MessageFuture... futures)
Constructs a message future bag, initializing it with the given futures
to track.
|
Modifier and Type | Method and Description |
---|---|
void |
add(MessageFuture... futures)
Adds more futures to the bag for tracking.
|
MessageFutureBag |
await()
Waits for all the futures in this bag to be satisfied, at which point
the aggregate result is set.
|
MessageFutureBag |
awaitUninterruptibly()
Waits for all the futures in this bag to be satisfied, at which point
the aggregate result is set.
|
boolean |
awaitUninterruptibly(long eachTimeoutMs)
Waits for all the futures in this bag to be satisfied, at which point
the aggregate result is set.
|
Set<MessageFuture> |
futures()
Returns an unmodifiable view of the futures in this bag.
|
MessageFutureBag.BagResult |
result()
Returns the result of this bag.
|
int |
size()
Returns the number of futures in this bag.
|
String |
toString() |
public MessageFutureBag(MessageFuture... futures)
futures
- the initial futures to trackpublic void add(MessageFuture... futures)
futures
- additional futures to trackIllegalStateException
- if await() has already been invokedpublic MessageFutureBag.BagResult result()
public int size()
public Set<MessageFuture> futures()
public MessageFutureBag await() throws InterruptedException
IllegalStateException
- if there are no futures in the bagInterruptedException
- if the current thread was interruptedpublic MessageFutureBag awaitUninterruptibly()
IllegalStateException
- if there are no futures in the bagpublic boolean awaitUninterruptibly(long eachTimeoutMs)
eachTimeoutMs
- number of milliseconds to wait for each future to
timeouttrue
if every future was completed within the specified
time limit; false
otherwiseIllegalStateException
- if there are no futures in the bagCopyright © 2015. All Rights Reserved.