com.hazelcast.util

## Class FutureUtil

- java.lang.Object
- - com.hazelcast.util.FutureUtil

-     public final class FutureUtil
      extends Object

  This utility class contains convenience methods to work with multiple futures at the same time, e.g. `waitWithDeadline(java.util.Collection, long, java.util.concurrent.TimeUnit, long, java.util.concurrent.TimeUnit)`

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static interface` | `FutureUtil.ExceptionHandler` Internally used interface to define behavior of the FutureUtil methods when exceptions arise

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static FutureUtil.ExceptionHandler` | `IGNORE_ALL_EXCEPT_LOG_MEMBER_LEFT` Ignores all exceptions but still logs `MemberLeftException` per future and just tries to finish all of the given ones.
    `static FutureUtil.ExceptionHandler` | `IGNORE_ALL_EXCEPTIONS` Ignores all exceptions
    `static FutureUtil.ExceptionHandler` | `RETHROW_ALL_EXCEPT_MEMBER_LEFT` This ExceptionHandler rethrows `ExecutionException`s and logs `MemberLeftException`s to the log.
    `static FutureUtil.ExceptionHandler` | `RETHROW_EVERYTHING` Just rethrows all exceptions
    `static FutureUtil.ExceptionHandler` | `RETHROW_EXECUTION_EXCEPTION` This ExceptionHandler rethrows `ExecutionException`s and logs `MemberLeftException`s to the log.
    `static FutureUtil.ExceptionHandler` | `RETHROW_TRANSACTION_EXCEPTION` Handler for transaction specific rethrown of exceptions.

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static boolean` | `allDone(Collection<Future> futures)` Check if all futures are done
    `static void` | `checkAllDone(Collection<Future> futures)` Rethrow exeception of the fist future that completed with an exception
    `static List<Future>` | `getAllDone(Collection<Future> futures)` Get all futures that are done
    `static FutureUtil.ExceptionHandler` | `logAllExceptions(ILogger logger, Level level)` This ExceptionHandler rethrows `ExecutionException`s and logs `MemberLeftException`s to the log.
    `static FutureUtil.ExceptionHandler` | `logAllExceptions(ILogger logger, String message, Level level)` This ExceptionHandler rethrows `ExecutionException`s and logs `MemberLeftException`s to the log.
    `static FutureUtil.ExceptionHandler` | `logAllExceptions(Level level)` This ExceptionHandler rethrows `ExecutionException`s and logs `MemberLeftException`s to the log.
    `static FutureUtil.ExceptionHandler` | `logAllExceptions(String message, Level level)` This ExceptionHandler rethrows `ExecutionException`s and logs `MemberLeftException`s to the log.
    `static <V> Collection<V>` | `returnWithDeadline(Collection<Future<V>> futures, long timeout, TimeUnit timeUnit)`
    `static <V> Collection<V>` | `returnWithDeadline(Collection<Future<V>> futures, long timeout, TimeUnit timeUnit, FutureUtil.ExceptionHandler exceptionHandler)`
    `static <V> Collection<V>` | `returnWithDeadline(Collection<Future<V>> futures, long overallTimeout, TimeUnit overallTimeUnit, long perFutureTimeout, TimeUnit perFutureTimeUnit)`
    `static <V> Collection<V>` | `returnWithDeadline(Collection<Future<V>> futures, long overallTimeout, TimeUnit overallTimeUnit, long perFutureTimeout, TimeUnit perFutureTimeUnit, FutureUtil.ExceptionHandler exceptionHandler)`
    `static void` | `waitForever(Collection<? extends Future> futures)`
    `static void` | `waitForever(Collection<? extends Future> futuresToWaitFor, FutureUtil.ExceptionHandler exceptionHandler)`
    `static void` | `waitUntilAllRespondedWithDeadline(Collection<? extends Future> futures, long timeout, TimeUnit timeUnit, FutureUtil.ExceptionHandler exceptionHandler)`
    `static void` | `waitWithDeadline(Collection<? extends Future> futures, long timeout, TimeUnit timeUnit)`
    `static void` | `waitWithDeadline(Collection<? extends Future> futures, long timeout, TimeUnit timeUnit, FutureUtil.ExceptionHandler exceptionHandler)`
    `static void` | `waitWithDeadline(Collection<? extends Future> futures, long overallTimeout, TimeUnit overallTimeUnit, long perFutureTimeout, TimeUnit perFutureTimeUnit)`
    `static void` | `waitWithDeadline(Collection<? extends Future> futures, long overallTimeout, TimeUnit overallTimeUnit, long perFutureTimeout, TimeUnit perFutureTimeUnit, FutureUtil.ExceptionHandler exceptionHandler)`

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

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

- - ### Field Detail

    - #### RETHROW_EVERYTHING

          public static final FutureUtil.ExceptionHandler RETHROW_EVERYTHING

      Just rethrows all exceptions

    - #### IGNORE_ALL_EXCEPTIONS

          public static final FutureUtil.ExceptionHandler IGNORE_ALL_EXCEPTIONS

      Ignores all exceptions

    - #### IGNORE_ALL_EXCEPT_LOG_MEMBER_LEFT

          public static final FutureUtil.ExceptionHandler IGNORE_ALL_EXCEPT_LOG_MEMBER_LEFT

      Ignores all exceptions but still logs `MemberLeftException` per future and just tries to finish all of the given ones. This is the default behavior if nothing else is given.

    - #### RETHROW_EXECUTION_EXCEPTION

          public static final FutureUtil.ExceptionHandler RETHROW_EXECUTION_EXCEPTION

      This ExceptionHandler rethrows `ExecutionException`s and logs `MemberLeftException`s to the log.

    - #### RETHROW_ALL_EXCEPT_MEMBER_LEFT

          public static final FutureUtil.ExceptionHandler RETHROW_ALL_EXCEPT_MEMBER_LEFT

      This ExceptionHandler rethrows `ExecutionException`s and logs `MemberLeftException`s to the log.

    - #### RETHROW_TRANSACTION_EXCEPTION

          public static final FutureUtil.ExceptionHandler RETHROW_TRANSACTION_EXCEPTION

      Handler for transaction specific rethrown of exceptions.

  - ### Method Detail

    - #### logAllExceptions

          @PrivateApi
          public static FutureUtil.ExceptionHandler logAllExceptions(ILogger logger,
                                                                                 String message,
                                                                                 Level level)

      This ExceptionHandler rethrows `ExecutionException`s and logs `MemberLeftException`s to the log.
      Parameters:
        `logger` - the ILogger instance to be used for logging
        `message` - the log message to appear in the logs before the stacktrace
        `level` - the log level to be used for logging

    - #### logAllExceptions

          @PrivateApi
          public static FutureUtil.ExceptionHandler logAllExceptions(String message,
                                                                                 Level level)

      This ExceptionHandler rethrows `ExecutionException`s and logs `MemberLeftException`s to the log.
      Parameters:
        `message` - the log message to appear in the logs before the stacktrace
        `level` - the log level to be used for logging

    - #### logAllExceptions

          @PrivateApi
          public static FutureUtil.ExceptionHandler logAllExceptions(ILogger logger,
                                                                                 Level level)

      This ExceptionHandler rethrows `ExecutionException`s and logs `MemberLeftException`s to the log.
      Parameters:
        `logger` - the ILogger instance to be used for logging
        `level` - the log level to be used for logging

    - #### logAllExceptions

          @PrivateApi
          public static FutureUtil.ExceptionHandler logAllExceptions(Level level)

      This ExceptionHandler rethrows `ExecutionException`s and logs `MemberLeftException`s to the log.
      Parameters:
        `level` - the log level to be used for logging

    - #### returnWithDeadline

          @PrivateApi
          public static <V> Collection<V> returnWithDeadline(Collection<Future<V>> futures,
                                                                         long timeout,
                                                                         TimeUnit timeUnit)

    - #### returnWithDeadline

          @PrivateApi
          public static <V> Collection<V> returnWithDeadline(Collection<Future<V>> futures,
                                                                         long timeout,
                                                                         TimeUnit timeUnit,
                                                                         FutureUtil.ExceptionHandler exceptionHandler)

    - #### returnWithDeadline

          @PrivateApi
          public static <V> Collection<V> returnWithDeadline(Collection<Future<V>> futures,
                                                                         long overallTimeout,
                                                                         TimeUnit overallTimeUnit,
                                                                         long perFutureTimeout,
                                                                         TimeUnit perFutureTimeUnit)

    - #### returnWithDeadline

          @PrivateApi
          public static <V> Collection<V> returnWithDeadline(Collection<Future<V>> futures,
                                                                         long overallTimeout,
                                                                         TimeUnit overallTimeUnit,
                                                                         long perFutureTimeout,
                                                                         TimeUnit perFutureTimeUnit,
                                                                         FutureUtil.ExceptionHandler exceptionHandler)

    - #### waitForever

          @PrivateApi
          public static void waitForever(Collection<? extends Future> futuresToWaitFor,
                                                     FutureUtil.ExceptionHandler exceptionHandler)

    - #### waitForever

          @PrivateApi
          public static void waitForever(Collection<? extends Future> futures)

    - #### waitWithDeadline

          @PrivateApi
          public static void waitWithDeadline(Collection<? extends Future> futures,
                                                          long timeout,
                                                          TimeUnit timeUnit)

    - #### waitUntilAllRespondedWithDeadline

          @PrivateApi
          public static void waitUntilAllRespondedWithDeadline(Collection<? extends Future> futures,
                                                                           long timeout,
                                                                           TimeUnit timeUnit,
                                                                           FutureUtil.ExceptionHandler exceptionHandler)

    - #### waitWithDeadline

          @PrivateApi
          public static void waitWithDeadline(Collection<? extends Future> futures,
                                                          long timeout,
                                                          TimeUnit timeUnit,
                                                          FutureUtil.ExceptionHandler exceptionHandler)

    - #### waitWithDeadline

          @PrivateApi
          public static void waitWithDeadline(Collection<? extends Future> futures,
                                                          long overallTimeout,
                                                          TimeUnit overallTimeUnit,
                                                          long perFutureTimeout,
                                                          TimeUnit perFutureTimeUnit)

    - #### waitWithDeadline

          @PrivateApi
          public static void waitWithDeadline(Collection<? extends Future> futures,
                                                          long overallTimeout,
                                                          TimeUnit overallTimeUnit,
                                                          long perFutureTimeout,
                                                          TimeUnit perFutureTimeUnit,
                                                          FutureUtil.ExceptionHandler exceptionHandler)

    - #### allDone

          public static boolean allDone(Collection<Future> futures)

      Check if all futures are done
      Parameters:
        `futures` - the list of futures
      Returns:
        `true` if all futures are done

    - #### checkAllDone

          public static void checkAllDone(Collection<Future> futures)
                                   throws Exception

      Rethrow exeception of the fist future that completed with an exception
      Parameters:
        `futures` -
      Throws:
        `Exception`

    - #### getAllDone

          public static List<Future> getAllDone(Collection<Future> futures)

      Get all futures that are done
      Parameters:
        `futures` -
      Returns:
        list of completed futures

Copyright © 2018. All rights reserved.