Class FutureCompletionLogger

  • All Implemented Interfaces:
    Runnable

    public class FutureCompletionLogger
    extends FutureCompletionHandler<Object>
    To be set as a listener on ListenableFutures. This is useful in order to capture their termination results(either result object on success or exception in case of failure), and log accordingly. Specially useful for tracking success/failure on futures which no thread block on (fire and forget scenarios).
    Author:
    Eyal Schneider
    • Constructor Detail

      • FutureCompletionLogger

        protected FutureCompletionLogger​(org.slf4j.Logger logger,
                                         org.slf4j.event.Level successLevel,
                                         org.slf4j.event.Level errLevel,
                                         String actionName,
                                         Future<?> future)
        Constructor
        Parameters:
        logger - The logger to write to
        successLevel - The logging level to use when logging successful completion. Use null for no logging.
        errLevel - The logging level to use when logging failed completion. Use null for no logging.
        actionName - The name of the action
        future - The future object to test for errors.
    • Method Detail

      • listenTo

        public static <T> void listenTo​(com.google.common.util.concurrent.ListenableFuture<T> future,
                                        org.slf4j.Logger logger,
                                        org.slf4j.event.Level successLevel,
                                        org.slf4j.event.Level errLevel,
                                        String actionName)
        Adds a logging listener (SLF4J) to a given ListenableFuture. The logging occurs in the producer thread.
        Parameters:
        future - The future to listen to
        logger - The logger to write to
        successLevel - The logging level to use when logging successful completion
        errLevel - The logging level to use when logging failed completion
        actionName - The name of the action
      • listenToError

        public static <T> void listenToError​(com.google.common.util.concurrent.ListenableFuture<T> future,
                                             org.slf4j.Logger logger,
                                             org.slf4j.event.Level level,
                                             String actionName)
        Adds a logging listener (SLF4J) on error events to a given ListenableFuture. The logging occurs in the producer thread.
        Parameters:
        future - The future to listen to
        logger - The logger to write to
        level - The logging level to use when logging failed completion
        actionName - The name of the action