public static class ClosingFuture.Combiner
extends java.lang.Object
ClosingFuture step that is derived from more than one input step.
See ClosingFuture.whenAllComplete(Iterable) and ClosingFuture.whenAllSucceed(Iterable) for how to
instantiate this class.
Example:
final ClosingFuture<BufferedReader> file1ReaderFuture = ...;
final ClosingFuture<BufferedReader> file2ReaderFuture = ...;
ListenableFuture<Integer> numberOfDifferentLines =
ClosingFuture.whenAllSucceed(file1ReaderFuture, file2ReaderFuture)
.call(
(closer, peeker) -> {
BufferedReader file1Reader = peeker.getDone(file1ReaderFuture);
BufferedReader file2Reader = peeker.getDone(file2ReaderFuture);
return countDifferentLines(file1Reader, file2Reader);
},
executor)
.closing(executor);
| Modifier and Type | Class and Description |
|---|---|
static interface |
ClosingFuture.Combiner.AsyncCombiningCallable<V>
An operation that returns a
ClosingFuture result and may throw an exception. |
static interface |
ClosingFuture.Combiner.CombiningCallable<V>
An operation that returns a result and may throw an exception.
|
| Modifier and Type | Field and Description |
|---|---|
private boolean |
allMustSucceed |
private ClosingFuture.CloseableList |
closeables |
private static Function<ClosingFuture<?>,FluentFuture<?>> |
INNER_FUTURE |
protected ImmutableList<ClosingFuture<?>> |
inputs |
| Modifier | Constructor and Description |
|---|---|
private |
Combiner(boolean allMustSucceed,
java.lang.Iterable<? extends ClosingFuture<?>> inputs) |
| Modifier and Type | Method and Description |
|---|---|
<V> ClosingFuture<V> |
call(ClosingFuture.Combiner.CombiningCallable<V> combiningCallable,
java.util.concurrent.Executor executor)
Returns a new
ClosingFuture pipeline step derived from the inputs by applying a
combining function to their values. |
<V> ClosingFuture<V> |
callAsync(ClosingFuture.Combiner.AsyncCombiningCallable<V> combiningCallable,
java.util.concurrent.Executor executor)
Returns a new
ClosingFuture pipeline step derived from the inputs by applying a
ClosingFuture-returning function to their values. |
private Futures.FutureCombiner<java.lang.Object> |
futureCombiner() |
private ImmutableList<FluentFuture<?>> |
inputFutures() |
private final ClosingFuture.CloseableList closeables
private final boolean allMustSucceed
protected final ImmutableList<ClosingFuture<?>> inputs
private static final Function<ClosingFuture<?>,FluentFuture<?>> INNER_FUTURE
private Combiner(boolean allMustSucceed,
java.lang.Iterable<? extends ClosingFuture<?>> inputs)
public <V> ClosingFuture<V> call(ClosingFuture.Combiner.CombiningCallable<V> combiningCallable, java.util.concurrent.Executor executor)
ClosingFuture pipeline step derived from the inputs by applying a
combining function to their values. The function can use a ClosingFuture.DeferredCloser to capture
objects to be closed when the pipeline is done.
If this combiner was returned by a ClosingFuture.whenAllSucceed(java.lang.Iterable<? extends com.google.common.util.concurrent.ClosingFuture<?>>) method and any of the inputs
fail, so will the returned step.
If the combiningCallable throws a CancellationException, the pipeline will be
cancelled.
If the combiningCallable throws an ExecutionException, the cause of the thrown
ExecutionException will be extracted and used as the failure of the derived step.
public <V> ClosingFuture<V> callAsync(ClosingFuture.Combiner.AsyncCombiningCallable<V> combiningCallable, java.util.concurrent.Executor executor)
ClosingFuture pipeline step derived from the inputs by applying a
ClosingFuture-returning function to their values. The function can use a ClosingFuture.DeferredCloser to capture objects to be closed when the pipeline is done (other than those
captured by the returned ClosingFuture).
If this combiner was returned by a ClosingFuture.whenAllSucceed(java.lang.Iterable<? extends com.google.common.util.concurrent.ClosingFuture<?>>) method and any of the inputs
fail, so will the returned step.
If the combiningCallable throws a CancellationException, the pipeline will be
cancelled.
If the combiningCallable throws an ExecutionException, the cause of the thrown
ExecutionException will be extracted and used as the failure of the derived step.
If the combiningCallable throws any other exception, it will be used as the failure of the derived step.
If an exception is thrown after the combiningCallable creates a ClosingFuture,
then none of the closeable objects in that ClosingFuture will be closed.
Usage guidelines for this method:
ListenableFuture or a
ClosingFuture. If possible, prefer calling call(CombiningCallable,
Executor) instead, with a function that returns the next value directly.
closer.eventuallyClose() for every closeable object this step creates in order to
capture it for later closing.
ClosingFuture. To turn a ListenableFuture into a ClosingFuture call ClosingFuture.from(ListenableFuture).
The same warnings about doing heavyweight operations within ClosingFuture.transformAsync(AsyncClosingFunction, Executor) apply here.
private Futures.FutureCombiner<java.lang.Object> futureCombiner()
private ImmutableList<FluentFuture<?>> inputFutures()