Package org.dataloader.impl
Interface PromisedValues<T>
-
- All Known Implementing Classes:
PromisedValuesImpl
public interface PromisedValues<T>
This allows multipleCompletionStage
s to be combined and completed as one and should something go wrong, instead of throwingCompletionException
s it captures the cause and returns null for that data value, otherwise it allows you to access them as a list of values.This class really encapsulate a list of promised values. It is considered finished when all the underlying futures are finished.
You can get that list of values via
toList()
. You can also compose aCompletableFuture
of that list of values viatoCompletableFuture()
()}
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description static <T> PromisedValues<T>
allOf(java.util.concurrent.CompletionStage<T> f1, java.util.concurrent.CompletionStage<T> f2)
Returns a newPromisedValues
that is completed when all the givenCompletionStage
s complete.static <T> PromisedValues<T>
allOf(java.util.concurrent.CompletionStage<T> f1, java.util.concurrent.CompletionStage<T> f2, java.util.concurrent.CompletionStage<T> f3)
Returns a newPromisedValues
that is completed when all the givenCompletionStage
s complete.static <T> PromisedValues<T>
allOf(java.util.concurrent.CompletionStage<T> f1, java.util.concurrent.CompletionStage<T> f2, java.util.concurrent.CompletionStage<T> f3, java.util.concurrent.CompletionStage<T> f4)
Returns a newPromisedValues
that is completed when all the givenCompletionStage
s complete.static <T> PromisedValues<T>
allOf(java.util.List<? extends java.util.concurrent.CompletionStage<T>> cfs)
Returns a newPromisedValues
that is completed when all the givenCompletionStage
s complete.static <T> PromisedValues<T>
allPromisedValues(java.util.List<PromisedValues<T>> cfs)
Returns a newPromisedValues
that is completed when all the givenPromisedValues
s complete.static <T> PromisedValues<T>
allPromisedValues(PromisedValues<T> pv1, PromisedValues<T> pv2)
Returns a newPromisedValues
that is completed when all the givenPromisedValues
s complete.static <T> PromisedValues<T>
allPromisedValues(PromisedValues<T> pv1, PromisedValues<T> pv2, PromisedValues<T> pv3)
Returns a newPromisedValues
that is completed when all the givenPromisedValues
s complete.static <T> PromisedValues<T>
allPromisedValues(PromisedValues<T> pv1, PromisedValues<T> pv2, PromisedValues<T> pv3, PromisedValues<T> pv4)
Returns a newPromisedValues
that is completed when all the givenPromisedValues
s complete.java.lang.Throwable
cause()
The exception cause or null if it didn't failjava.lang.Throwable
cause(int index)
The exception cause at the specified index or null if it didn't failboolean
failed()
T
get(int index)
The value at index or null if it failedboolean
isDone()
The true if the all the futures have completed (and hence thisPromisedValues
has completed)java.util.List<T>
join()
Waits for the underlying futures to complete.int
size()
boolean
succeeded()
boolean
succeeded(int index)
The true if theCompletionStage
at the specified index succeededPromisedValues<T>
thenAccept(java.util.function.Consumer<PromisedValues<T>> handler)
When the all the futures complete, this call back will be invoked with thisPromisedValues
as a parameterjava.util.concurrent.CompletableFuture<java.util.List<T>>
toCompletableFuture()
java.util.List<T>
toList()
Returns the underlying values as a list
-
-
-
Method Detail
-
allOf
static <T> PromisedValues<T> allOf(java.util.List<? extends java.util.concurrent.CompletionStage<T>> cfs)
Returns a newPromisedValues
that is completed when all the givenCompletionStage
s complete. If any of the givenCompletionStage
s complete exceptionally, then the returnedPromisedValues
also does so.- Type Parameters:
T
- the type of values- Parameters:
cfs
- theCompletionStage
s to combine- Returns:
- a new PromisedValues
-
allOf
static <T> PromisedValues<T> allOf(java.util.concurrent.CompletionStage<T> f1, java.util.concurrent.CompletionStage<T> f2)
Returns a newPromisedValues
that is completed when all the givenCompletionStage
s complete. If any of the givenCompletionStage
s complete exceptionally, then the returnedPromisedValues
also does so.- Type Parameters:
T
- the type of values- Parameters:
f1
- the 1st completable futuref2
- the 2nd completable future- Returns:
- a new PromisedValues
-
allOf
static <T> PromisedValues<T> allOf(java.util.concurrent.CompletionStage<T> f1, java.util.concurrent.CompletionStage<T> f2, java.util.concurrent.CompletionStage<T> f3)
Returns a newPromisedValues
that is completed when all the givenCompletionStage
s complete. If any of the givenCompletionStage
s complete exceptionally, then the returnedPromisedValues
also does so.- Type Parameters:
T
- the type of values- Parameters:
f1
- the 1st completable futuref2
- the 2nd completable futuref3
- the 3rd completable future- Returns:
- a new PromisedValues
-
allOf
static <T> PromisedValues<T> allOf(java.util.concurrent.CompletionStage<T> f1, java.util.concurrent.CompletionStage<T> f2, java.util.concurrent.CompletionStage<T> f3, java.util.concurrent.CompletionStage<T> f4)
Returns a newPromisedValues
that is completed when all the givenCompletionStage
s complete. If any of the givenCompletionStage
s complete exceptionally, then the returnedPromisedValues
also does so.- Type Parameters:
T
- the type of values- Parameters:
f1
- the 1st completable futuref2
- the 2nd completable futuref3
- the 3rd completable futuref4
- the 4th completable future- Returns:
- a new PromisedValues
-
allPromisedValues
static <T> PromisedValues<T> allPromisedValues(java.util.List<PromisedValues<T>> cfs)
Returns a newPromisedValues
that is completed when all the givenPromisedValues
s complete. If any of the givenPromisedValues
s complete exceptionally, then the returnedPromisedValues
also does so.- Type Parameters:
T
- the type of values- Parameters:
cfs
- the list to combine- Returns:
- a new PromisedValues
-
allPromisedValues
static <T> PromisedValues<T> allPromisedValues(PromisedValues<T> pv1, PromisedValues<T> pv2)
Returns a newPromisedValues
that is completed when all the givenPromisedValues
s complete. If any of the givenPromisedValues
s complete exceptionally, then the returnedPromisedValues
also does so.- Type Parameters:
T
- the type of values- Parameters:
pv1
- the 1st promised valuepv2
- the 2nd promised value- Returns:
- a new PromisedValues
-
allPromisedValues
static <T> PromisedValues<T> allPromisedValues(PromisedValues<T> pv1, PromisedValues<T> pv2, PromisedValues<T> pv3)
Returns a newPromisedValues
that is completed when all the givenPromisedValues
s complete. If any of the givenPromisedValues
s complete exceptionally, then the returnedPromisedValues
also does so.- Type Parameters:
T
- the type of values- Parameters:
pv1
- the 1st promised valuepv2
- the 2nd promised valuepv3
- the 3rd promised value- Returns:
- a new PromisedValues
-
allPromisedValues
static <T> PromisedValues<T> allPromisedValues(PromisedValues<T> pv1, PromisedValues<T> pv2, PromisedValues<T> pv3, PromisedValues<T> pv4)
Returns a newPromisedValues
that is completed when all the givenPromisedValues
s complete. If any of the givenPromisedValues
s complete exceptionally, then the returnedPromisedValues
also does so.- Type Parameters:
T
- the type of values- Parameters:
pv1
- the 1st promised valuepv2
- the 2nd promised valuepv3
- the 3rd promised valuepv4
- the 4th promised value- Returns:
- a new PromisedValues
-
thenAccept
PromisedValues<T> thenAccept(java.util.function.Consumer<PromisedValues<T>> handler)
When the all the futures complete, this call back will be invoked with thisPromisedValues
as a parameter- Parameters:
handler
- the call back which will be given this object- Returns:
- a new
PromisedValues
which you can compose more computations with
-
succeeded
boolean succeeded()
- Returns:
- true if all the futures completed successfully
-
failed
boolean failed()
- Returns:
- true if any of the futures completed unsuccessfully
-
isDone
boolean isDone()
The true if the all the futures have completed (and hence thisPromisedValues
has completed)- Returns:
- true if all the futures have completed
-
cause
java.lang.Throwable cause()
The exception cause or null if it didn't fail- Returns:
- an exception or null if the future did not fail
-
succeeded
boolean succeeded(int index)
The true if theCompletionStage
at the specified index succeeded- Parameters:
index
- the index of theCompletionStage
- Returns:
- true if the future at the specified index succeeded
-
cause
java.lang.Throwable cause(int index)
The exception cause at the specified index or null if it didn't fail- Parameters:
index
- the index of theCompletionStage
- Returns:
- an exception or null if the future did not fail
-
get
T get(int index)
The value at index or null if it failed- Parameters:
index
- the index of the future- Returns:
- the value of the future
-
toList
java.util.List<T> toList()
Returns the underlying values as a list- Returns:
- the list of underlying values
-
size
int size()
- Returns:
- the number of
CompletionStage
s under the covers
-
join
java.util.List<T> join()
Waits for the underlying futures to complete. To better conform with the use of common functional forms, if a computation involved in the completion of this CompletableFuture threw an exception, this method throws an (unchecked)CompletionException
with the underlying exception as its cause.- Returns:
- the list of completed values similar to
toList()
- Throws:
java.util.concurrent.CancellationException
- if the computation was cancelledjava.util.concurrent.CompletionException
- if this future completed exceptionally or a completion computation threw an exception
-
toCompletableFuture
java.util.concurrent.CompletableFuture<java.util.List<T>> toCompletableFuture()
- Returns:
- this as a
CompletableFuture
that returns the list of underlying values
-
-