Class ApiFutures
- java.lang.Object
-
- com.google.api.core.ApiFutures
-
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static <V> void
addCallback(ApiFuture<V> future, ApiFutureCallback<? super V> callback)
Deprecated.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.static <V> ApiFuture<List<V>>
allAsList(Iterable<? extends ApiFuture<? extends V>> futures)
Creates a newApiFuture
whose value is a list containing the values of all its input futures, if all succeed.static <V,X extends Throwable>
ApiFuture<V>catching(ApiFuture<? extends V> input, Class<X> exceptionType, ApiFunction<? super X,? extends V> callback)
Deprecated.static <V,X extends Throwable>
ApiFuture<V>catching(ApiFuture<? extends V> input, Class<X> exceptionType, ApiFunction<? super X,? extends V> callback, Executor executor)
Returns anApiFuture
whose 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,X extends Throwable>
ApiFuture<V>catchingAsync(ApiFuture<V> input, Class<X> exceptionType, ApiAsyncFunction<? super X,V> callback, Executor executor)
Returns aApiFuture
whose 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>
immediateCancelledFuture()
Creates aApiFuture
which is cancelled immediately upon construction, so thatisCancelled()
always returnstrue
.static <V> ApiFuture<V>
immediateFailedFuture(Throwable throwable)
Returns aApiFuture
which has an exception set immediately upon construction.static <V> ApiFuture<V>
immediateFuture(V value)
Creates aApiFuture
which has its value set immediately upon construction.static <V> ApiFuture<List<V>>
successfulAsList(Iterable<? extends ApiFuture<? extends V>> futures)
Creates a newApiFuture
whose 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 newApiFuture
whose 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 newApiFuture
whose result is asynchronously derived from the result of the givenApiFuture
.
-
-
-
Method Detail
-
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 anApiFuture
whose 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 inputApiFuture
exceptionType
- The exception type that triggers use offallback
callback
- TheApiFunction
to be called if input fails with the expected exception type- Returns:
- A future whose result is taken either from the given
input
or 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 anApiFuture
whose 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 inputApiFuture
exceptionType
- The exception type that triggers use offallback
callback
- TheApiFunction
to be called if input fails with the expected exception typeexecutor
- The executor that runsfallback
ifinput
fails- Returns:
- A future whose result is taken either from the given
input
or by thecallback
- See Also:
Futures.catching(ListenableFuture, Class, Function, Executor)
-
catchingAsync
@BetaApi public static <V,X extends Throwable> ApiFuture<V> catchingAsync(ApiFuture<V> input, Class<X> exceptionType, ApiAsyncFunction<? super X,V> callback, Executor executor)
Returns aApiFuture
whose 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 inputApiFuture
exceptionType
- The exception type that triggers use offallback
.callback
- TheApiAsyncFunction
to be called ifinput
fails with the expected * exception type.executor
- The executor that runsfallback
ifinput
fails- Returns:
- A future whose result is taken either from the given
input
or by thecallback
- See Also:
Futures.catchingAsync(ListenableFuture, Class, AsyncFunction, Executor)
-
immediateFuture
public static <V> ApiFuture<V> immediateFuture(V value)
Creates aApiFuture
which has its value set immediately upon construction.Note that this method is a delegate of
Futures.immediateFuture(Object)
.- Parameters:
value
- The value set to theApiFuture
upon construction- Returns:
- A future that holds
value
- See Also:
Futures.immediateFuture(Object)
-
immediateFailedFuture
public static <V> ApiFuture<V> immediateFailedFuture(Throwable throwable)
Returns aApiFuture
which has an exception set immediately upon construction.Note that this method is a delegate of
Futures.immediateFailedFuture(Throwable)
.- Parameters:
throwable
- The exception set to theApiFuture
upon construction- Returns:
- A future that holds an exception
- See Also:
Futures.immediateFailedFuture(Throwable)
-
immediateCancelledFuture
public static <V> ApiFuture<V> immediateCancelledFuture()
Creates aApiFuture
which 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 newApiFuture
whose 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 newApiFuture
whose 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
public static <V> ApiFuture<List<V>> allAsList(Iterable<? extends ApiFuture<? extends V>> futures)
Creates a newApiFuture
whose 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 newApiFuture
whose 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 newApiFuture
whose result is asynchronously derived from the result of the givenApiFuture
. If the givenFuture
fails, the returnedApiFuture
fails 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 newApiFuture
whose result is asynchronously derived from the result of the givenApiFuture
. If the givenFuture
fails, the returnedApiFuture
fails 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)
-
-