Class ApiFutures
ApiFuture interface.-
Method Summary
Modifier and TypeMethodDescriptionstatic <V> voidaddCallback(ApiFuture<V> future, ApiFutureCallback<? super V> callback) Deprecated.Use the overload that requires an executor.static <V> voidaddCallback(ApiFuture<V> future, ApiFutureCallback<? super V> callback, Executor executor) Registers a callback to be run when theApiFuture's computation is complete or, if the computation is already complete, immediately.Creates a newApiFuturewhose value is a list containing the values of all its input futures, if all succeed.catching(ApiFuture<? extends V> input, Class<X> exceptionType, ApiFunction<? super X, ? extends V> callback) Deprecated.catching(ApiFuture<? extends V> input, Class<X> exceptionType, ApiFunction<? super X, ? extends V> callback, Executor executor) Returns anApiFuturewhose result is taken from the given primary input or, if the primary input fails with the given exceptionType, from the result provided by the callback.catchingAsync(ApiFuture<V> input, Class<X> exceptionType, ApiAsyncFunction<? super X, V> callback, Executor executor) Returns aApiFuturewhose result is taken from the given primary input or, if the primary input fails with the given exceptionType, from the result provided by the callback.static <V> ApiFuture<V>Creates aApiFuturewhich is cancelled immediately upon construction, so thatisCancelled()always returnstrue.static <V> ApiFuture<V>immediateFailedFuture(Throwable throwable) Returns aApiFuturewhich has an exception set immediately upon construction.static <V> ApiFuture<V>immediateFuture(V value) Creates aApiFuturewhich has its value set immediately upon construction.successfulAsList(Iterable<? extends ApiFuture<? extends V>> futures) Creates a newApiFuturewhose value is a list containing the values of all its successful input futures.static <V,X> ApiFuture<X> transform(ApiFuture<? extends V> input, ApiFunction<? super V, ? extends X> function) Deprecated.static <V,X> ApiFuture<X> transform(ApiFuture<? extends V> input, ApiFunction<? super V, ? extends X> function, Executor executor) Returns a newApiFuturewhose result is derived from the result of the givenApiFuture.static <I,O> ApiFuture<O> transformAsync(ApiFuture<I> input, ApiAsyncFunction<I, O> function) Deprecated.Use transformAsync(ApiFuture, ApiAsyncFunction, Executor), the overload that requires an executor.static <I,O> ApiFuture<O> transformAsync(ApiFuture<I> input, ApiAsyncFunction<I, O> function, Executor executor) Returns a newApiFuturewhose result is asynchronously derived from the result of the givenApiFuture.
-
Method Details
-
addCallback
@Deprecated public static <V> void addCallback(ApiFuture<V> future, ApiFutureCallback<? super V> callback) Deprecated.Use the overload that requires an executor. For identical behavior, passMoreExecutors.directExecutor(), but consider whether another executor would be safer.Registers a callback to be run when theApiFuture's computation is complete or, if the computation is already complete, immediately.- Parameters:
future- The future attach the callback tocallback- The callback to invoke when future is completed
-
addCallback
public static <V> void addCallback(ApiFuture<V> future, ApiFutureCallback<? super V> callback, Executor executor) Registers a callback to be run when theApiFuture's computation is complete or, if the computation is already complete, immediately.Note that this method is a delegate of
Futures.addCallback(ListenableFuture, FutureCallback, Executor).- Parameters:
future- The future attach the callback tocallback- The callback to invoke when future is completedexecutor- The executor to run callback when the future completes- See Also:
-
Futures.addCallback(ListenableFuture, FutureCallback, Executor)
-
catching
@Deprecated public static <V,X extends Throwable> ApiFuture<V> catching(ApiFuture<? extends V> input, Class<X> exceptionType, ApiFunction<? super X, ? extends V> callback) Deprecated.Use the overload that requires an executor. For identical behavior, passMoreExecutors.directExecutor(), but consider whether another executor would be safer.Returns anApiFuturewhose result is taken from the given primary input or, if the primary input fails with the given exceptionType, from the result provided by the callback.- Parameters:
input- The primary inputApiFutureexceptionType- The exception type that triggers use offallbackcallback- TheApiFunctionto be called if input fails with the expected exception type- Returns:
- A future whose result is taken either from the given
inputor by thecallback
-
catching
public static <V,X extends Throwable> ApiFuture<V> catching(ApiFuture<? extends V> input, Class<X> exceptionType, ApiFunction<? super X, ? extends V> callback, Executor executor) Returns anApiFuturewhose result is taken from the given primary input or, if the primary input fails with the given exceptionType, from the result provided by the callback.Note that this method is a delegate of
Futures.catching(ListenableFuture, Class, Function, Executor).- Parameters:
input- The primary inputApiFutureexceptionType- The exception type that triggers use offallbackcallback- TheApiFunctionto be called if input fails with the expected exception typeexecutor- The executor that runsfallbackifinputfails- Returns:
- A future whose result is taken either from the given
inputor by thecallback - See Also:
-
Futures.catching(ListenableFuture, Class, Function, Executor)
-
catchingAsync
public static <V,X extends Throwable> ApiFuture<V> catchingAsync(ApiFuture<V> input, Class<X> exceptionType, ApiAsyncFunction<? super X, V> callback, Executor executor) Returns aApiFuturewhose result is taken from the given primary input or, if the primary input fails with the given exceptionType, from the result provided by the callback.Note that this method is a delegate of
Futures.catchingAsync(ListenableFuture, Class, AsyncFunction, Executor)- Parameters:
input- The primary inputApiFutureexceptionType- The exception type that triggers use offallback.callback- TheApiAsyncFunctionto be called ifinputfails with the expected * exception type.executor- The executor that runsfallbackifinputfails- Returns:
- A future whose result is taken either from the given
inputor by thecallback - See Also:
-
Futures.catchingAsync(ListenableFuture, Class, AsyncFunction, Executor)
-
immediateFuture
Creates aApiFuturewhich has its value set immediately upon construction.Note that this method is a delegate of
Futures.immediateFuture(Object).- Parameters:
value- The value set to theApiFutureupon construction- Returns:
- A future that holds
value - See Also:
-
Futures.immediateFuture(Object)
-
immediateFailedFuture
Returns aApiFuturewhich has an exception set immediately upon construction.Note that this method is a delegate of
Futures.immediateFailedFuture(Throwable).- Parameters:
throwable- The exception set to theApiFutureupon construction- Returns:
- A future that holds an exception
- See Also:
-
Futures.immediateFailedFuture(Throwable)
-
immediateCancelledFuture
Creates aApiFuturewhich is cancelled immediately upon construction, so thatisCancelled()always returnstrue.Note that this method is a delegate of
Futures.immediateCancelledFuture().- Returns:
- A cancelled future
- See Also:
-
Futures.immediateCancelledFuture()
-
transform
@Deprecated public static <V,X> ApiFuture<X> transform(ApiFuture<? extends V> input, ApiFunction<? super V, ? extends X> function) Deprecated.Use the overload that requires an executor. For identical behavior, passMoreExecutors.directExecutor(), but consider whether another executor would be safer.Returns a newApiFuturewhose result is derived from the result of the givenApiFuture.- Parameters:
input- The future to transformfunction- A Function to transform the results of the provided future to the results of the returned future- Returns:
- A future that holds result of the transformation
-
transform
public static <V,X> ApiFuture<X> transform(ApiFuture<? extends V> input, ApiFunction<? super V, ? extends X> function, Executor executor) Returns a newApiFuturewhose result is derived from the result of the givenApiFuture.Note that this method is a delegate of
Futures.transform(ListenableFuture, Function, Executor).- Parameters:
input- The future to transformfunction- A Function to transform the results of the provided future to the results of the returned future.executor- Executor to run the function in.- Returns:
- A future that holds result of the transformation
- See Also:
-
Futures.transform(ListenableFuture, Function, Executor)
-
allAsList
Creates a newApiFuturewhose value is a list containing the values of all its input futures, if all succeed.The list of results is in the same order as the input list.
Note that this method is a delegate of
Futures.allAsList(Iterable).- Parameters:
futures- Futures to combine- Returns:
- A future that provides a list of the results of the component futures
- See Also:
-
Futures.allAsList(Iterable)
-
successfulAsList
@BetaApi public static <V> ApiFuture<List<V>> successfulAsList(Iterable<? extends ApiFuture<? extends V>> futures) Creates a newApiFuturewhose value is a list containing the values of all its successful input futures. The list of results is in the same order as the input list, and if any of the provided futures fails or is canceled, its corresponding position will containnull(which is indistinguishable from the future having a successful value ofnull).The list of results is in the same order as the input list.
Note that this method is a delegate of
Futures.successfulAsList(Iterable).- Parameters:
futures- Futures to combine- Returns:
- A future that provides a list of the results of the component futures
- See Also:
-
Futures.successfulAsList(Iterable)
-
transformAsync
@Deprecated public static <I,O> ApiFuture<O> transformAsync(ApiFuture<I> input, ApiAsyncFunction<I, O> function) Deprecated.Use transformAsync(ApiFuture, ApiAsyncFunction, Executor), the overload that requires an executor. For identical behavior, passMoreExecutors.directExecutor(), but consider whether another executor would be safer.Returns a newApiFuturewhose result is asynchronously derived from the result of the givenApiFuture. If the givenFuturefails, the returnedApiFuturefails with the same exception (and the function is not invoked).- Parameters:
input- The future to transformfunction- A function to transform the result of the input future to the result of the output future- Returns:
- A future that holds result of the function (if the input succeeded) or the original input's failure (if not)
-
transformAsync
public static <I,O> ApiFuture<O> transformAsync(ApiFuture<I> input, ApiAsyncFunction<I, O> function, Executor executor) Returns a newApiFuturewhose result is asynchronously derived from the result of the givenApiFuture. If the givenFuturefails, the returnedApiFuturefails with the same exception (and the function is not invoked).Note that this method is a delegate of
Futures.transformAsync(ListenableFuture, AsyncFunction, Executor).- Parameters:
input- The future to transformfunction- A function to transform the result of the input future to the result of the output futureexecutor- Executor to run the function in.- Returns:
- A future that holds result of the function (if the input succeeded) or the original input's failure (if not)
- See Also:
-
Futures.transformAsync(ListenableFuture, AsyncFunction, Executor)
-