Class LoggingFutures


  • @Beta
    public final class LoggingFutures
    extends Object
    Utility methods to add completion/failure logging to various kinds of Futures.
    Author:
    Michael Vorburger.ch - Initial author, Robert Varga - moved here from JdkFutures & ListenableFutures
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <V> com.google.common.util.concurrent.FluentFuture<V> addErrorLogging​(com.google.common.util.concurrent.FluentFuture<V> future, org.slf4j.Logger logger, String message)
      Adds a callback to a ListenableFuture which logs any failures.
      static <V> com.google.common.util.concurrent.FluentFuture<V> addErrorLogging​(com.google.common.util.concurrent.FluentFuture<V> future, org.slf4j.Logger logger, String format, Object arg)
      Adds a callback to a ListenableFuture which logs any failures.
      static <V> com.google.common.util.concurrent.FluentFuture<V> addErrorLogging​(com.google.common.util.concurrent.FluentFuture<V> future, org.slf4j.Logger logger, String format, Object... args)
      Adds a callback to a FluentFuture which logs any failures.
      static <V> com.google.common.util.concurrent.ListenableFuture<V> addErrorLogging​(com.google.common.util.concurrent.ListenableFuture<V> future, org.slf4j.Logger logger, String message)
      Adds a callback to a ListenableFuture which logs any failures.
      static <V> com.google.common.util.concurrent.ListenableFuture<V> addErrorLogging​(com.google.common.util.concurrent.ListenableFuture<V> future, org.slf4j.Logger logger, String format, Object arg)
      Adds a callback to a ListenableFuture which logs any failures.
      static <V> com.google.common.util.concurrent.ListenableFuture<V> addErrorLogging​(com.google.common.util.concurrent.ListenableFuture<V> future, org.slf4j.Logger logger, String format, Object... args)
      Adds a callback to a ListenableFuture which logs any failures.
      static <V> com.google.common.util.concurrent.ListenableFuture<V> addErrorLogging​(Future<V> future, org.slf4j.Logger logger, String message)
      Adds a callback to a Future which logs any failures.
      static <V> com.google.common.util.concurrent.ListenableFuture<V> addErrorLogging​(Future<V> future, org.slf4j.Logger logger, String format, Object arg)
      Adds a callback to a Future which logs any failures.
      static <V> com.google.common.util.concurrent.ListenableFuture<V> addErrorLogging​(Future<V> future, org.slf4j.Logger logger, String format, Object... args)
      Adds a callback to a ListenableFuture which logs any failures.
    • Method Detail

      • addErrorLogging

        public static <V> com.google.common.util.concurrent.ListenableFuture<V> addErrorLogging​(Future<V> future,
                                                                                                org.slf4j.Logger logger,
                                                                                                String message)
        Adds a callback to a Future which logs any failures.
        Parameters:
        future - the future to add logging to
        logger - logger to use
        message - message to log
        Returns:
        ListenableFuture backed by the supplied future
        Throws:
        NullPointerException - if any of the arguments is null
      • addErrorLogging

        public static <V> com.google.common.util.concurrent.ListenableFuture<V> addErrorLogging​(Future<V> future,
                                                                                                org.slf4j.Logger logger,
                                                                                                String format,
                                                                                                Object arg)
        Adds a callback to a Future which logs any failures.
        Parameters:
        future - the future to add logging to
        logger - logger to use
        format - format string conforming to String.format(String, Object...)
        arg - single format argument
        Returns:
        ListenableFuture backed by the supplied future
        Throws:
        NullPointerException - if any of the arguments is null
      • addErrorLogging

        public static <V> com.google.common.util.concurrent.ListenableFuture<V> addErrorLogging​(Future<V> future,
                                                                                                org.slf4j.Logger logger,
                                                                                                String format,
                                                                                                Object... args)
        Adds a callback to a ListenableFuture which logs any failures.

        Instead of using this helper, you should consider directly using Futures.addCallback(ListenableFuture, FutureCallback, java.util.concurrent.Executor) to add a callback which does real error recovery in case of a failure instead of just logging an error, if you can.

        Parameters:
        future - the future to add logging to
        logger - logger to use
        format - format string conforming to String.format(String, Object...)
        args - format arguments
        Returns:
        ListenableFuture backed by the supplied future
        Throws:
        NullPointerException - if any of the arguments is null
      • addErrorLogging

        public static <V> com.google.common.util.concurrent.ListenableFuture<V> addErrorLogging​(com.google.common.util.concurrent.ListenableFuture<V> future,
                                                                                                org.slf4j.Logger logger,
                                                                                                String message)
        Adds a callback to a ListenableFuture which logs any failures.

        Instead of using this helper, you should consider directly using Futures.addCallback(ListenableFuture, FutureCallback, java.util.concurrent.Executor) to add a callback which does real error recovery in case of a failure instead of just logging an error, if you can.

        Parameters:
        future - the future to add logging to
        logger - logger to use
        message - message to log
        Returns:
        The future
        Throws:
        NullPointerException - if any of the arguments is null
      • addErrorLogging

        public static <V> com.google.common.util.concurrent.ListenableFuture<V> addErrorLogging​(com.google.common.util.concurrent.ListenableFuture<V> future,
                                                                                                org.slf4j.Logger logger,
                                                                                                String format,
                                                                                                Object arg)
        Adds a callback to a ListenableFuture which logs any failures.

        Instead of using this helper, you should consider directly using Futures.addCallback(ListenableFuture, FutureCallback, java.util.concurrent.Executor) to add a callback which does real error recovery in case of a failure instead of just logging an error, if you can.

        Parameters:
        future - the future to add logging to
        logger - logger to use
        format - format string conforming to String.format(String, Object...)
        arg - single format argument
        Returns:
        The future
        Throws:
        NullPointerException - if any of the arguments is null
      • addErrorLogging

        public static <V> com.google.common.util.concurrent.ListenableFuture<V> addErrorLogging​(com.google.common.util.concurrent.ListenableFuture<V> future,
                                                                                                org.slf4j.Logger logger,
                                                                                                String format,
                                                                                                Object... args)
        Adds a callback to a ListenableFuture which logs any failures.

        Instead of using this helper, you should consider directly using Futures.addCallback(ListenableFuture, FutureCallback, java.util.concurrent.Executor) to add a callback which does real error recovery in case of a failure instead of just logging an error, if you can.

        Parameters:
        future - the future to add logging to
        logger - logger to use
        format - format string conforming to String.format(String, Object...)
        args - format arguments
        Returns:
        The future
        Throws:
        NullPointerException - if any of the arguments is null
      • addErrorLogging

        public static <V> com.google.common.util.concurrent.FluentFuture<V> addErrorLogging​(com.google.common.util.concurrent.FluentFuture<V> future,
                                                                                            org.slf4j.Logger logger,
                                                                                            String message)
        Adds a callback to a ListenableFuture which logs any failures.

        Instead of using this helper, you should consider directly using Futures.addCallback(ListenableFuture, FutureCallback, java.util.concurrent.Executor) to add a callback which does real error recovery in case of a failure instead of just logging an error, if you can.

        Parameters:
        future - the future to add logging to
        logger - logger to use
        message - message to log
        Returns:
        The future
        Throws:
        NullPointerException - if any of the arguments is null
      • addErrorLogging

        public static <V> com.google.common.util.concurrent.FluentFuture<V> addErrorLogging​(com.google.common.util.concurrent.FluentFuture<V> future,
                                                                                            org.slf4j.Logger logger,
                                                                                            String format,
                                                                                            Object arg)
        Adds a callback to a ListenableFuture which logs any failures.

        Instead of using this helper, you should consider directly using Futures.addCallback(ListenableFuture, FutureCallback, java.util.concurrent.Executor) to add a callback which does real error recovery in case of a failure instead of just logging an error, if you can.

        Parameters:
        future - the future to add logging to
        logger - logger to use
        format - format string conforming to String.format(String, Object...)
        arg - single format argument
        Returns:
        The future
        Throws:
        NullPointerException - if any of the arguments is null
      • addErrorLogging

        public static <V> com.google.common.util.concurrent.FluentFuture<V> addErrorLogging​(com.google.common.util.concurrent.FluentFuture<V> future,
                                                                                            org.slf4j.Logger logger,
                                                                                            String format,
                                                                                            Object... args)
        Adds a callback to a FluentFuture which logs any failures.

        Instead of using this helper, you should consider directly using Futures.addCallback(ListenableFuture, FutureCallback, java.util.concurrent.Executor) to add a callback which does real error recovery in case of a failure instead of just logging an error, if you can.

        Parameters:
        future - the future to add logging to
        logger - logger to use
        format - format string conforming to String.format(String, Object...)
        args - format arguments
        Returns:
        The future
        Throws:
        NullPointerException - if any of the arguments is null