Class LoggingFuture<V>
- java.lang.Object
-
- de.aristaflow.adept2.util.threading.LoggingFuture<V>
-
- Type Parameters:
V
- The result type returned by this Future'sget
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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
LoggingFuture.IgnoredResultLogger
This clean-up task logs the result of a future which no one retrieved.
-
Field Summary
Fields Modifier and Type Field Description protected Cleanup<RuntimeException>
cleanup
TheCleanup
called as post-mortem action for this future.protected Logger
logger
The logger for logging unhandled results, Exception, RuntimeException or Error.protected boolean
resultRelevant
Whether the result of the future is relevant and therefore it should be logged if it is not retrieved.
-
Constructor Summary
Constructors Constructor Description LoggingFuture(RunnableFuture<V> future, boolean resultRelevant, Logger logger)
Creates a new future wrapping the designatedRunnableFuture
logging the outcome of the future if no one has retrieved it.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
cancel(boolean mayInterruptIfRunning)
boolean
equals(Object other)
V
get()
V
get(long timeout, TimeUnit unit)
protected RunnableFuture<V>
getWrappedFutureRunnable()
Gets the wrapped future runnable.int
hashCode()
boolean
isCancelled()
boolean
isDone()
void
run()
-
-
-
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 final Logger logger
The logger for logging unhandled results, Exception, RuntimeException or Error.
-
cleanup
protected final Cleanup<RuntimeException> cleanup
TheCleanup
called as post-mortem action for this future. This will log the (exceptional) result of this future in case the result has not been retrieved. For instance, this avoids loosing exceptions.
-
-
Constructor Detail
-
LoggingFuture
public LoggingFuture(RunnableFuture<V> future, boolean resultRelevant, Logger logger)
Creates a new future wrapping the designatedRunnableFuture
logging the outcome of the future if no one has retrieved it.- Parameters:
future
- TheRunnableFuture
which to wrap.resultRelevant
- Whether the result of the future is relevant and therefore it should be logged if it is not retrieved. Exceptional results will always be logged.logger
- The logger for logging unhandled results, Exception, RuntimeException or Error.
-
-
Method Detail
-
getWrappedFutureRunnable
protected RunnableFuture<V> getWrappedFutureRunnable()
Gets the wrapped future runnable. This is useful for subclasses requiring a more specific object.- Returns:
- The wrapped future runnable.
-
run
public void run()
- Specified by:
run
in interfaceRunnable
- Specified by:
run
in interfaceRunnableFuture<V>
-
cancel
public boolean cancel(boolean mayInterruptIfRunning)
-
isCancelled
public boolean isCancelled()
- Specified by:
isCancelled
in interfaceFuture<V>
-
get
public V get() throws InterruptedException, ExecutionException
- Specified by:
get
in interfaceFuture<V>
- Throws:
InterruptedException
ExecutionException
-
get
public V get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException
- Specified by:
get
in interfaceFuture<V>
- Throws:
InterruptedException
ExecutionException
TimeoutException
-
-