Class LoggingFuture<V>

  • Type Parameters:
    V - The result type returned by this Future's get method.
    All Implemented Interfaces:
    Runnable, Future<V>, RunnableFuture<V>
    Direct Known Subclasses:
    LoggingScheduledFuture

    public class LoggingFuture<V>
    extends Object
    implements RunnableFuture<V>
    A future that wraps another future and logs all occurred exceptions and the result for information purpose if no one was interested in it. This is especially useful when using an executor service and ignoring the returned future. If the result (or the exception) of the future is retrieved, no additional logging will take place.
    Author:
    Ulrich Kreher
    • Field Detail

      • resultRelevant

        protected final boolean resultRelevant
        Whether the result of the future is relevant and therefore it should be logged if it is not retrieved. Runnables do not have a return value and therefore the result is irrelevant and need not be logged.
      • logger

        protected Logger logger
        The logger for logging unhandled results, Exception, RuntimeException or Error.
    • Constructor Detail

      • LoggingFuture

        public LoggingFuture​(RunnableFuture<V> future,
                             boolean resultRelevant,
                             Logger logger)
        Creates a new future wrapping the designated RunnableFuture logging the outcome of the future if no one has retrieved it.
        Parameters:
        future - The RunnableFuture which to wrap.
        resultRelevant - Whether the result of the future is relevant and therefore it should be logged if it is not retrieved.
        logger - The logger for logging unhandled results, Exception, RuntimeException or Error.