Interface CheckedFuture<V,X extends java.lang.Exception>
-
- All Superinterfaces:
java.util.concurrent.Future<V>,ListenableFuture<V>
- All Known Implementing Classes:
AbstractCheckedFuture,ForwardingCheckedFuture,ForwardingCheckedFuture.SimpleForwardingCheckedFuture
@Beta @Deprecated @GwtCompatible public interface CheckedFuture<V,X extends java.lang.Exception> extends ListenableFuture<V>
Deprecated.CheckedFuturecannot properly support the chained operations that are the primary goal ofListenableFuture.CheckedFuturealso encourages users to rethrow exceptions from one thread in another thread, producing misleading stack traces. Additionally, it has a surprising policy about which exceptions to map and which to leave untouched. Guava users who want aCheckedFuturecan fork the classes for their own use, possibly specializing them to the particular exception type they use. We recommend that most people useListenableFutureand perform any exception wrapping themselves. This class is scheduled for removal from Guava in February 2018.ACheckedFutureis aListenableFuturethat includes versions of thegetmethods that can throw a checked exception. This makes it easier to create a future that executes logic which can throw an exception.Warning: We recommend against using
CheckedFuturein new projects.CheckedFutureis difficult to build libraries atop.CheckedFutureports of methods likeFutures.transformAsync(com.google.common.util.concurrent.ListenableFuture<I>, com.google.common.util.concurrent.AsyncFunction<? super I, ? extends O>)have historically had bugs, and some of these bugs are necessary, unavoidable consequences of theCheckedFutureAPI. Additionally,CheckedFutureencourages users to take exceptions from one thread and rethrow them in another, producing confusing stack traces.A common implementation is
Futures.immediateCheckedFuture(V).Implementations of this interface must adapt the exceptions thrown by
Future#get():CancellationException,ExecutionExceptionandInterruptedExceptioninto the type specified by theXtype parameter.This interface also extends the ListenableFuture interface to allow listeners to be added. This allows the future to be used as a normal
Futureor as an asynchronous callback mechanism as needed. This allows multiple callbacks to be registered for a particular task, and the future will guarantee execution of all listeners when the task completes.For a simpler alternative to CheckedFuture, consider accessing Future values with
Futures.getChecked().- Since:
- 1.0
- Author:
- Sven Mawson
-
-
Method Summary
All Methods Instance Methods Abstract Methods Deprecated Methods Modifier and Type Method Description VcheckedGet()Deprecated.Exception checking version ofFuture.get()that will translateInterruptedException,CancellationExceptionandExecutionExceptioninto application-specific exceptions.VcheckedGet(long timeout, java.util.concurrent.TimeUnit unit)Deprecated.Exception checking version ofFuture.get(long, TimeUnit)that will translateInterruptedException,CancellationExceptionandExecutionExceptioninto application-specific exceptions.-
Methods inherited from interface com.google.common.util.concurrent.ListenableFuture
addListener
-
-
-
-
Method Detail
-
checkedGet
V checkedGet() throws X extends java.lang.Exception
Deprecated.Exception checking version ofFuture.get()that will translateInterruptedException,CancellationExceptionandExecutionExceptioninto application-specific exceptions.
-
checkedGet
V checkedGet(long timeout, java.util.concurrent.TimeUnit unit) throws java.util.concurrent.TimeoutException, X extends java.lang.Exception
Deprecated.Exception checking version ofFuture.get(long, TimeUnit)that will translateInterruptedException,CancellationExceptionandExecutionExceptioninto application-specific exceptions. On timeout this method throws a normalTimeoutException.
-
-