Package org.pipecraft.infra.concurrent
Class FutureCompletionLogger
- java.lang.Object
-
- org.pipecraft.infra.concurrent.FutureCompletionHandler<Object>
-
- org.pipecraft.infra.concurrent.FutureCompletionLogger
-
- All Implemented Interfaces:
Runnable
public class FutureCompletionLogger extends FutureCompletionHandler<Object>
To be set as a listener onListenableFutures. 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 Summary
Constructors Modifier Constructor Description protectedFutureCompletionLogger(org.slf4j.Logger logger, org.slf4j.event.Level successLevel, org.slf4j.event.Level errLevel, String actionName, Future<?> future)Constructor
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> voidlistenTo(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 givenListenableFuture.static <T> voidlistenToError(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 givenListenableFuture.-
Methods inherited from class org.pipecraft.infra.concurrent.FutureCompletionHandler
listenTo, listenTo, listenToError, listenToError, listenToSuccess, listenToSuccess, run
-
-
-
-
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 tosuccessLevel- 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 actionfuture- 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 givenListenableFuture. The logging occurs in the producer thread.- Parameters:
future- The future to listen tologger- The logger to write tosuccessLevel- The logging level to use when logging successful completionerrLevel- The logging level to use when logging failed completionactionName- 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 givenListenableFuture. The logging occurs in the producer thread.- Parameters:
future- The future to listen tologger- The logger to write tolevel- The logging level to use when logging failed completionactionName- The name of the action
-
-