com.h3c.of.lib.msg

## Class MessageFutureBag

- java.lang.Object
- - com.h3c.of.lib.msg.MessageFutureBag

-     public class MessageFutureBag
      extends Object

  A message future aggregate, allowing the consumer to wait for completion of a number of message futures.

  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.

  See Also:
    `MessageFuture`

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `MessageFutureBag.BagResult` Denotes the different states that a message future bag can be in.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `MessageFutureBag(MessageFuture... futures)` Constructs a message future bag, initializing it with the given futures to track.

  - ### Method Summary

    Methods
    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()`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### MessageFutureBag

          public MessageFutureBag(MessageFuture... futures)

      Constructs a message future bag, initializing it with the given futures to track.
      Parameters:
        `futures` - the initial futures to track

  - ### Method Detail

    - #### add

          public void add(MessageFuture... futures)

      Adds more futures to the bag for tracking.
      Parameters:
        `futures` - additional futures to track
      Throws:
        `IllegalStateException` - if await() has already been invoked

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

    - #### result

          public MessageFutureBag.BagResult result()

      Returns the result of this bag.
      Returns:
        the result

    - #### size

          public int size()

      Returns the number of futures in this bag.
      Returns:
        the number of futures

    - #### futures

          public Set<MessageFuture> futures()

      Returns an unmodifiable view of the futures in this bag.
      Returns:
        the futures

    - #### await

          public MessageFutureBag await()
                                 throws InterruptedException

      Waits for all the futures in this bag to be satisfied, at which point the aggregate result is set.
      Returns:
        self (for method chaining)
      Throws:
        `IllegalStateException` - if there are no futures in the bag
        `InterruptedException` - if the current thread was interrupted

    - #### awaitUninterruptibly

          public MessageFutureBag awaitUninterruptibly()

      Waits for all the futures in this bag to be satisfied, at which point the aggregate result is set.
      Returns:
        self (for method chaining)
      Throws:
        `IllegalStateException` - if there are no futures in the bag

    - #### awaitUninterruptibly

          public boolean awaitUninterruptibly(long eachTimeoutMs)

      Waits for all the futures in this bag to be satisfied, at which point the aggregate result is set.
      Parameters:
        `eachTimeoutMs` - number of milliseconds to wait for each future to timeout
      Returns:
        self (for method chaining)
      Throws:
        `IllegalStateException` - if there are no futures in the bag

Copyright © 2014. All Rights Reserved.