public interface FutureStream<U> extends org.jooq.lambda.Seq<U>, ConfigurableStream<U>, LazyStream<U>, BlockingStream<U>, SimpleReactStream<U>, ToQueue<U>
exceptionSoftener| Modifier and Type | Method and Description |
|---|---|
default boolean |
allMatch(java.util.function.Predicate<? super U> predicate) |
default <T,R> FutureStream<R> |
allOf(java.util.stream.Collector collector,
java.util.function.Function<T,R> fn) |
default <T,R> FutureStream<R> |
allOf(java.util.function.Function<java.util.List<T>,R> fn)
React and allOf
allOf is a non-blocking equivalent of block.
|
default boolean |
anyMatch(java.util.function.Predicate<? super U> predicate) |
default FutureStream<U> |
capture(java.util.function.Consumer<? extends java.lang.Throwable> errorHandler)
React capture
While onFail is used for disaster recovery (when it is possible to
recover) - capture is used to capture those occasions where the full
pipeline has failed and is unrecoverable.
|
default <U> FutureStream<U> |
cast(java.lang.Class<U> type) |
static <T,U> FutureStream<U> |
cast(FutureStream<T> stream,
java.lang.Class<U> type)
Cast all elements in a stream to a given type, possibly throwing a
ClassCastException. |
default void |
close() |
default <R> R |
collect(java.util.function.Supplier<R> supplier,
java.util.function.BiConsumer<R,? super U> accumulator,
java.util.function.BiConsumer<R,R> combiner) |
default long |
count() |
default FutureStream<U> |
filter(java.util.function.Predicate<? super U> p)
Removes elements that do not match the supplied predicate from the
dataflow
|
default java.util.Optional<U> |
findAny() |
default java.util.Optional<U> |
findFirst() |
default <R> FutureStream<R> |
flatMap(java.util.function.Function<? super U,? extends java.util.stream.Stream<? extends R>> flatFn)
Allows aggregate values in a Stream to be flatten into a single Stream.
|
default java.util.stream.DoubleStream |
flatMapToDouble(java.util.function.Function<? super U,? extends java.util.stream.DoubleStream> mapper) |
default java.util.stream.IntStream |
flatMapToInt(java.util.function.Function<? super U,? extends java.util.stream.IntStream> mapper) |
default java.util.stream.LongStream |
flatMapToLong(java.util.function.Function<? super U,? extends java.util.stream.LongStream> mapper) |
default void |
forEach(java.util.function.Consumer<? super U> action)
Stream supporting methods
|
default void |
forEachOrdered(java.util.function.Consumer<? super U> action) |
default <R> FutureStream<R> |
fromStream(java.util.stream.Stream<R> stream) |
default <R> FutureStream<R> |
fromStreamCompletableFuture(java.util.stream.Stream<java.util.concurrent.CompletableFuture<R>> stream)
Construct a SimpleReactStream from provided Stream of CompletableFutures
|
static <T> FutureStream<T> |
intersperse(FutureStream<T> stream,
T value)
Returns a stream with a given value interspersed between any two values of this stream.
|
default FutureStream<U> |
intersperse(U value)
Returns a stream with a given value interspersed between any two values of this stream.
|
default boolean |
isParallel() |
default java.util.Iterator<U> |
iterator() |
default <R> FutureStream<R> |
map(java.util.function.Function<? super U,? extends R> mapper) |
default java.util.stream.DoubleStream |
mapToDouble(java.util.function.ToDoubleFunction<? super U> mapper) |
default java.util.stream.IntStream |
mapToInt(java.util.function.ToIntFunction<? super U> mapper) |
default java.util.stream.LongStream |
mapToLong(java.util.function.ToLongFunction<? super U> mapper) |
default java.util.Optional<U> |
max(java.util.Comparator<? super U> comparator) |
static <R> FutureStream<R> |
merge(FutureStream s1,
FutureStream s2)
Merge this reactive dataflow with another - recommended for merging
different types.
|
default FutureStream<U> |
merge(SimpleReactStream<U> s)
Merge this reactive dataflow with another of the same type.
|
default java.util.Optional<U> |
min(java.util.Comparator<? super U> comparator) |
default boolean |
noneMatch(java.util.function.Predicate<? super U> predicate) |
default <U> FutureStream<U> |
ofType(java.lang.Class<U> type) |
static <T,U> FutureStream<U> |
ofType(FutureStream<T> stream,
java.lang.Class<U> type)
Keep only those elements in a stream that are of a given type.
|
default org.jooq.lambda.Seq<U> |
onClose(java.lang.Runnable closeHandler) |
default <U> FutureStream<U> |
onFail(java.util.function.Function<? extends SimpleReactFailedStageException,U> fn)
React onFail
Define a function that can be used to recover from exceptions during the
preceeding stage of the dataflow.
|
default FutureStream<U> |
parallel() |
default FutureStream<U> |
peek(java.util.function.Consumer<? super U> consumer)
Peek asynchronously at the results in the current stage.
|
default java.util.Optional<U> |
reduce(java.util.function.BinaryOperator<U> accumulator) |
default <R> R |
reduce(R identity,
java.util.function.BiFunction<R,? super U,R> accumulator,
java.util.function.BinaryOperator<R> combiner) |
default U |
reduce(U identity,
java.util.function.BinaryOperator<U> accumulator) |
default <R> FutureStream<R> |
retry(java.util.function.Function<U,R> fn)
Will execute this phase on the RetryExecutor (default or user supplied).
|
default FutureStream<U> |
self(java.util.function.Consumer<FutureStream<U>> consumer)
Give a function access to the current stage of a SimpleReact Stream
|
default org.jooq.lambda.Seq<U> |
sequential() |
static <T> org.jooq.lambda.Seq<T> |
slice(FutureStream<T> stream,
long from,
long to)
Returns a limited interval from a given Stream.
|
default org.jooq.lambda.Seq<U> |
slice(long from,
long to)
Returns a limited interval from a given Stream.
|
default org.jooq.lambda.Seq<U> |
sorted() |
default org.jooq.lambda.Seq<U> |
sorted(java.util.Comparator<? super U> comparator) |
default java.util.Spliterator<U> |
spliterator() |
default java.util.stream.Stream<U> |
stream() |
default <R> FutureStream<R> |
then(java.util.function.Function<U,R> fn)
React then
Unlike 'with' this method is fluent, and returns another Stage Builder
that can represent the next stage in the dataflow.
|
default java.lang.Object[] |
toArray() |
default <A> A[] |
toArray(java.util.function.IntFunction<A[]> generator) |
default FutureStream<U> |
unordered() |
cast, concat, concat, concat, concat, cycle, cycle, distinct, duplicate, duplicate, empty, foldLeft, foldLeft, foldRight, foldRight, generate, generate, generate, groupBy, groupBy, groupBy, groupBy, groupBy, groupBy, intersperse, iterate, join, join, join, join, join, join, limit, limit, limitUntil, limitUntil, limitWhile, limitWhile, maxBy, maxBy, minBy, minBy, of, of, ofType, partition, partition, reverse, reverse, scanLeft, scanLeft, scanRight, scanRight, seq, seq, seq, seq, seq, shuffle, shuffle, shuffle, shuffle, skip, skip, skipUntil, skipUntil, skipWhile, skipWhile, slice, splitAt, splitAt, splitAtHead, splitAtHead, toCollection, toCollection, toList, toList, toMap, toMap, toMap, toSet, toSet, toString, toString, toString, unfold, unzip, unzip, unzip, unzip, zip, zip, zip, zip, zipWithIndex, zipWithIndexassureSimpleReactException, empty, futureStream, futureStream, futureStream, futureStream, handleExceptions, lastActiveArray, merge, of, of, parallelBuilder, parallelBuilder, parallelCommonBuilder, parallelOf, sequentialBuilder, sequentialCommonBuilder, simple, simple, simple, streamCompletableFutures, withgetLastActive, getLazyCollector, getWaitStrategy, run, run, run, run, runOnCurrentaggregateResults, block, block, block, block, block, blockAndExtract, blockAndExtract, capture, collectResults, first, getSafe, last, submitAndBlockgetErrorHandler, getLastActive, getRetrier, getSimpleReact, getTaskExecutor, isEager, withEager, withErrorHandler, withLastActive, withLazyCollector, withQueueFactory, withRetrier, withTaskExecutor, withWaitStrategyisEager, toQueuegetQueueFactorygetQueueFactorydefault <R> FutureStream<R> retry(java.util.function.Function<U,R> fn)
SimpleReactStreamretry in interface SimpleReactStream<U>fn - Function that will be executed and retried on failuredefault <T,R> FutureStream<R> allOf(java.util.stream.Collector collector, java.util.function.Function<T,R> fn)
allOf in interface EagerToQueue<U>allOf in interface LazyToQueue<U>allOf in interface SimpleReactStream<U>collector - to perform aggregation / reduction operation on the results
from active stage (e.g. to Collect into a List or String)fn - Function that receives the results of all currently active
tasks as inputdefault <R> FutureStream<R> fromStreamCompletableFuture(java.util.stream.Stream<java.util.concurrent.CompletableFuture<R>> stream)
SimpleReactStreamfromStreamCompletableFuture in interface SimpleReactStream<U>stream - JDK Stream to construct new SimpleReactStream fromdefault <R> FutureStream<R> then(java.util.function.Function<U,R> fn)
SimpleReactStream
new SimpleReact().<Integer, Integer> react(() -> 1, () -> 2, () -> 3)
.then((it) -> it * 100)
.then((it) -> "*" + it)
React then allows event reactors to be chained. Unlike React with, which
returns a collection of Future references, React then is a fluent
interface that returns the React builder - allowing further reactors to
be added to the chain.
React then does not block.
React with can be called after React then which gives access to the full
CompleteableFuture api. CompleteableFutures can be passed back into
SimpleReact via SimpleReact.react(streamOfCompleteableFutures);
See this blog post for examples of what can be achieved via
CompleteableFuture :- http://www.nurkiewicz.com/2013/12/promises-and-completablefuture.htm
l then in interface EagerToQueue<U>then in interface LazyToQueue<U>then in interface SimpleReactStream<U>fn - Function to be applied to the results of the currently active
event tasksdefault <R> FutureStream<R> fromStream(java.util.stream.Stream<R> stream)
fromStream in interface SimpleReactStream<U>default <R> FutureStream<R> flatMap(java.util.function.Function<? super U,? extends java.util.stream.Stream<? extends R>> flatFn)
SimpleReactStreamflatMap in interface org.jooq.lambda.Seq<U>flatMap in interface SimpleReactStream<U>flatMap in interface java.util.stream.Stream<U>flatFn - Function that coverts a value (e.g. a Collection) into a Streamdefault FutureStream<U> merge(SimpleReactStream<U> s)
SimpleReactStreammerge in interface SimpleReactStream<U>s - Reactive stage builder to merge withdefault <U> FutureStream<U> onFail(java.util.function.Function<? extends SimpleReactFailedStageException,U> fn)
SimpleReactStream
List<String> strings = new SimpleReact().<Integer, Integer> react(() -> 100, () -> 2, () -> 3)
.then(it -> {
if (it == 100)
throw new RuntimeException("boo!");
return it;
})
.onFail(e -> 1)
.then(it -> "*" + it)
.block();
In this example onFail recovers from the RuntimeException thrown when the
input to the first 'then' stage is 100.onFail in interface SimpleReactStream<U>fn - Recovery function, the exception is input, and the recovery
value is outputdefault FutureStream<U> capture(java.util.function.Consumer<? extends java.lang.Throwable> errorHandler)
SimpleReactStream
List<String> strings = new SimpleReact().<Integer, Integer> react(() -> 1, () -> 2, () -> 3)
.then(it -> it * 100)
.then(it -> {
if (it == 100)
throw new RuntimeException("boo!");
return it;
})
.onFail(e -> 1)
.then(it -> "*" + it)
.then(it -> {
if ("*200".equals(it))
throw new RuntimeException("boo!");
return it;
})
.capture(e -> logger.error(e.getMessage(),e))
.block();
In this case, strings will only contain the two successful results (for
()->1 and ()->3), an exception for the chain starting from Supplier
()->2 will be logged by capture. Capture will not capture the
exception thrown when an Integer value of 100 is found, but will catch
the exception when the String value "*200" is passed along the chain.capture in interface SimpleReactStream<U>errorHandler - A consumer that recieves and deals with an unrecoverable error
in the dataflowdefault <T,R> FutureStream<R> allOf(java.util.function.Function<java.util.List<T>,R> fn)
SimpleReactStream
boolean blocked[] = {false};
new SimpleReact().<Integer, Integer> react(() -> 1, () -> 2, () -> 3)
.then(it -> {
try {
Thread.sleep(50000);
} catch (Exception e) {
}
blocked[0] =true;
return 10;
})
.allOf( it -> it.size());
assertThat(blocked[0],is(false));
In this example, the current thread will continue and assert that it is
not blocked, allOf could continue and be executed in a separate thread.allOf in interface SimpleReactStream<U>fn - Function that recieves the results of all currently active
tasks as inputdefault FutureStream<U> peek(java.util.function.Consumer<? super U> consumer)
SimpleReactStreampeek in interface org.jooq.lambda.Seq<U>peek in interface SimpleReactStream<U>peek in interface java.util.stream.Stream<U>consumer - That will recieve current resultsdefault FutureStream<U> filter(java.util.function.Predicate<? super U> p)
SimpleReactStreamfilter in interface org.jooq.lambda.Seq<U>filter in interface SimpleReactStream<U>filter in interface java.util.stream.Stream<U>p - Predicate that will be used to filter elements from the
dataflowdefault void forEach(java.util.function.Consumer<? super U> action)
default void forEachOrdered(java.util.function.Consumer<? super U> action)
forEachOrdered in interface java.util.stream.Stream<U>default java.lang.Object[] toArray()
toArray in interface java.util.stream.Stream<U>default <A> A[] toArray(java.util.function.IntFunction<A[]> generator)
toArray in interface java.util.stream.Stream<U>default U reduce(U identity, java.util.function.BinaryOperator<U> accumulator)
reduce in interface java.util.stream.Stream<U>default java.util.Optional<U> reduce(java.util.function.BinaryOperator<U> accumulator)
reduce in interface java.util.stream.Stream<U>default <R> R collect(java.util.function.Supplier<R> supplier,
java.util.function.BiConsumer<R,? super U> accumulator,
java.util.function.BiConsumer<R,R> combiner)
collect in interface java.util.stream.Stream<U>default java.util.Optional<U> min(java.util.Comparator<? super U> comparator)
min in interface java.util.stream.Stream<U>default java.util.Optional<U> max(java.util.Comparator<? super U> comparator)
max in interface java.util.stream.Stream<U>default long count()
count in interface java.util.stream.Stream<U>default boolean anyMatch(java.util.function.Predicate<? super U> predicate)
anyMatch in interface java.util.stream.Stream<U>default boolean allMatch(java.util.function.Predicate<? super U> predicate)
allMatch in interface java.util.stream.Stream<U>default boolean noneMatch(java.util.function.Predicate<? super U> predicate)
noneMatch in interface java.util.stream.Stream<U>default java.util.Optional<U> findFirst()
findFirst in interface java.util.stream.Stream<U>default java.util.Optional<U> findAny()
findAny in interface java.util.stream.Stream<U>default <R> R reduce(R identity,
java.util.function.BiFunction<R,? super U,R> accumulator,
java.util.function.BinaryOperator<R> combiner)
reduce in interface java.util.stream.Stream<U>default java.util.Iterator<U> iterator()
default java.util.Spliterator<U> spliterator()
default boolean isParallel()
default org.jooq.lambda.Seq<U> sequential()
default FutureStream<U> parallel()
default java.util.stream.Stream<U> stream()
stream in interface org.jooq.lambda.Seq<U>default FutureStream<U> intersperse(U value)
intersperse in interface org.jooq.lambda.Seq<U>Seq.intersperse(Stream, Object)default <U> FutureStream<U> cast(java.lang.Class<U> type)
cast in interface org.jooq.lambda.Seq<U>default <U> FutureStream<U> ofType(java.lang.Class<U> type)
ofType in interface org.jooq.lambda.Seq<U>static <T,U> FutureStream<U> ofType(FutureStream<T> stream, java.lang.Class<U> type)
static <T,U> FutureStream<U> cast(FutureStream<T> stream, java.lang.Class<U> type)
ClassCastException.
// ClassCastException
LazyFutureStream.of(1, "a", 2, "b", 3).cast(Integer.class)static <T> FutureStream<T> intersperse(FutureStream<T> stream, T value)
default FutureStream<U> unordered()
default org.jooq.lambda.Seq<U> onClose(java.lang.Runnable closeHandler)
default void close()
default <R> FutureStream<R> map(java.util.function.Function<? super U,? extends R> mapper)
default java.util.stream.IntStream mapToInt(java.util.function.ToIntFunction<? super U> mapper)
default java.util.stream.LongStream mapToLong(java.util.function.ToLongFunction<? super U> mapper)
default java.util.stream.DoubleStream mapToDouble(java.util.function.ToDoubleFunction<? super U> mapper)
default java.util.stream.IntStream flatMapToInt(java.util.function.Function<? super U,? extends java.util.stream.IntStream> mapper)
default java.util.stream.LongStream flatMapToLong(java.util.function.Function<? super U,? extends java.util.stream.LongStream> mapper)
default java.util.stream.DoubleStream flatMapToDouble(java.util.function.Function<? super U,? extends java.util.stream.DoubleStream> mapper)
default org.jooq.lambda.Seq<U> sorted()
default FutureStream<U> self(java.util.function.Consumer<FutureStream<U>> consumer)
consumer - Consumer that will recieve current stagedefault org.jooq.lambda.Seq<U> slice(long from, long to)
slice in interface org.jooq.lambda.Seq<U>Seq.slice(Stream, long, long)static <T> org.jooq.lambda.Seq<T> slice(FutureStream<T> stream, long from, long to)
static <R> FutureStream<R> merge(FutureStream s1, FutureStream s2)
s1 - Reactive stage builder to merges2 - Reactive stage builder to merge