U - Return parameter for this stagepublic class Stage<U>
extends java.lang.Object
implements org.jooq.lambda.Seq<U>
| Modifier and Type | Method and Description |
|---|---|
boolean |
allMatch(java.util.function.Predicate<? super U> predicate) |
<T,R> Stage<R> |
allOf(java.util.stream.Collector collector,
java.util.function.Function<T,R> fn) |
<T,R> Stage<R> |
allOf(java.util.function.Function<java.util.List<T>,R> fn)
React and allOf
allOf is a non-blocking equivalent of block.
|
boolean |
anyMatch(java.util.function.Predicate<? super U> predicate) |
java.util.List<U> |
block()
React and block
List<String> strings = new SimpleReact().<Integer, Integer> react(() -> 1, () -> 2, () -> 3)
.then((it) -> it * 100)
.then((it) -> "*" + it)
.block();
In this example, once the current thread of execution meets the React
block method, it will block until all tasks have been completed. |
<R> R |
block(java.util.stream.Collector collector) |
<R> R |
block(java.util.stream.Collector collector,
java.util.function.Predicate<Status> breakout) |
java.util.List<U> |
block(java.util.function.Predicate<Status> breakout)
React and block with breakout
Sometimes you may not need to block until all the work is complete, one
result or a subset may be enough.
|
<R> R |
blockAndExtract(Extractor extractor)
Block until tasks complete and return a value determined by the extractor
supplied.
|
<R> R |
blockAndExtract(Extractor extractor,
java.util.function.Predicate<Status> breakout)
Block until tasks complete, or breakout conditions met and return a value
determined by the extractor supplied.
|
Stage<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.
|
void |
close() |
<R,A> R |
collect(java.util.stream.Collector<? super U,A,R> collector) |
<R> R |
collect(java.util.function.Supplier<R> supplier,
java.util.function.BiConsumer<R,? super U> accumulator,
java.util.function.BiConsumer<R,R> combiner) |
ReactCollector<U> |
collectResults()
This provides a mechanism to collect all of the results of active tasks
inside a dataflow stage.
|
long |
count() |
org.jooq.lambda.Seq<U> |
distinct() |
Stage<U> |
filter(java.util.function.Predicate<? super U> p)
Removes elements that do not match the supplied predicate from the
dataflow
|
java.util.Optional<U> |
findAny() |
java.util.Optional<U> |
findFirst() |
U |
first()
Block until first result received
|
<R> Stage<R> |
flatMap(java.util.function.Function<? super U,? extends java.util.stream.Stream<? extends R>> flatFn) |
java.util.stream.DoubleStream |
flatMapToDouble(java.util.function.Function<? super U,? extends java.util.stream.DoubleStream> mapper) |
java.util.stream.IntStream |
flatMapToInt(java.util.function.Function<? super U,? extends java.util.stream.IntStream> mapper) |
java.util.stream.LongStream |
flatMapToLong(java.util.function.Function<? super U,? extends java.util.stream.LongStream> mapper) |
void |
forEach(java.util.function.Consumer<? super U> action) |
void |
forEachOrdered(java.util.function.Consumer<? super U> action) |
boolean |
isParallel() |
java.util.Iterator<U> |
iterator()
Stream and Seq supporting methods
|
U |
last()
Block until all results received.
|
org.jooq.lambda.Seq<U> |
limit(long maxSize) |
<R> Stage<R> |
map(java.util.function.Function<? super U,? extends R> mapper) |
java.util.stream.DoubleStream |
mapToDouble(java.util.function.ToDoubleFunction<? super U> mapper) |
java.util.stream.IntStream |
mapToInt(java.util.function.ToIntFunction<? super U> mapper) |
java.util.stream.LongStream |
mapToLong(java.util.function.ToLongFunction<? super U> mapper) |
java.util.Optional<U> |
max(java.util.Comparator<? super U> comparator) |
Stage<U> |
merge(Stage<U> s)
Merge this reactive dataflow with another of the same type.
|
static <R> Stage<R> |
merge(Stage s1,
Stage s2)
Merge this reactive dataflow with another - recommended for merging
different types.
|
java.util.Optional<U> |
min(java.util.Comparator<? super U> comparator) |
boolean |
noneMatch(java.util.function.Predicate<? super U> predicate) |
org.jooq.lambda.Seq<U> |
onClose(java.lang.Runnable closeHandler) |
Stage<U> |
onFail(java.util.function.Function<? extends java.lang.Throwable,U> fn)
React onFail
Define a function that can be used to recover from exceptions during the
preceeding stage of the dataflow.
|
Stage<U> |
parallel() |
Stage<U> |
peek(java.util.function.Consumer<? super U> consumer)
Peek asynchronously at the results in the current stage.
|
java.util.Optional<U> |
reduce(java.util.function.BinaryOperator<U> accumulator) |
<R> R |
reduce(R identity,
java.util.function.BiFunction<R,? super U,R> accumulator,
java.util.function.BinaryOperator<R> combiner) |
U |
reduce(U identity,
java.util.function.BinaryOperator<U> accumulator) |
<R> Stage<R> |
retry(java.util.function.Function<U,R> fn)
Will execute this phase on the RetryExecutor (default or user supplied).
|
void |
run()
Trigger a lazy stream
|
void |
run(java.util.concurrent.ExecutorService e)
Trigger a lazy stream as a task on the provided ExecutorService
|
void |
run(java.util.concurrent.ExecutorService e,
java.lang.Runnable r) |
<C extends java.util.Collection<U>> |
run(java.util.function.Supplier<C> collector)
Trigger a lazy stream and return the results in the Collection created by
the collector
|
Stage<U> |
self(java.util.function.Consumer<Stage<U>> consumer)
Give a function access to the current stage of a SimpleReact Stream
|
org.jooq.lambda.Seq<U> |
sequential() |
org.jooq.lambda.Seq<U> |
skip(long n) |
org.jooq.lambda.Seq<U> |
sorted() |
org.jooq.lambda.Seq<U> |
sorted(java.util.Comparator<? super U> comparator) |
java.util.Spliterator<U> |
spliterator() |
java.util.stream.Stream<U> |
stream() |
<T> java.util.stream.Stream<java.util.concurrent.CompletableFuture<T>> |
streamCompletableFutures() |
<R> R |
submitAndBlock(java.util.function.Function<java.util.List<U>,R> fn)
This method allows the SimpleReact ExecutorService to be reused by JDK
parallel streams.
|
<R> Stage<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.
|
java.lang.Object[] |
toArray() |
<A> A[] |
toArray(java.util.function.IntFunction<A[]> generator) |
Queue<U> |
toQueue()
Convert the current Stream to a SimpleReact Queue
|
Stage<U> |
unordered() |
<R> java.util.List<java.util.concurrent.CompletableFuture<R>> |
with(java.util.function.Function<U,R> fn)
React with
Asynchronously apply the function supplied to the currently active event
tasks in the dataflow.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitcast, cast, concat, concat, concat, concat, cycle, cycle, duplicate, duplicate, empty, foldLeft, foldLeft, foldRight, foldRight, generate, generate, generate, groupBy, groupBy, groupBy, groupBy, groupBy, groupBy, intersperse, intersperse, iterate, join, join, join, join, join, join, limit, limitUntil, limitUntil, limitWhile, limitWhile, maxBy, maxBy, minBy, minBy, of, of, ofType, ofType, partition, partition, reverse, reverse, scanLeft, scanLeft, scanRight, scanRight, seq, seq, seq, seq, seq, shuffle, shuffle, shuffle, shuffle, skip, skipUntil, skipUntil, skipWhile, skipWhile, slice, 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, zipWithIndexpublic <R> R submitAndBlock(java.util.function.Function<java.util.List<U>,R> fn)
fn - Function that contains parallelStream code to be executed by
the SimpleReact ForkJoinPool (if configured)public <R> java.util.List<java.util.concurrent.CompletableFuture<R>> with(java.util.function.Function<U,R> fn)
List<CompletableFuture<Integer>> futures = new SimpleReact().<Integer, Integer> react(() -> 1, () -> 2, () -> 3)
.with((it) -> it * 100);
In this instance, 3 suppliers generate 3 numbers. These may be executed
in parallel, when they complete each number will be multiplied by 100 -
as a separate parrellel task (handled by a ForkJoinPool or configurable
task executor). A List of Future objects will be returned immediately
from Simple React and the tasks will be executed asynchronously.
React with does not block.fn - Function to be applied to the results of the currently active
event taskspublic <R> Stage<R> then(java.util.function.Function<U,R> fn)
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.html
fn - Function to be applied to the results of the currently active
event taskspublic <R> Stage<R> flatMap(java.util.function.Function<? super U,? extends java.util.stream.Stream<? extends R>> flatFn)
public <R> Stage<R> retry(java.util.function.Function<U,R> fn)
fn - Function that will be executed and retried on failurepublic Stage<U> peek(java.util.function.Consumer<? super U> consumer)
public Stage<U> filter(java.util.function.Predicate<? super U> p)
public <T> java.util.stream.Stream<java.util.concurrent.CompletableFuture<T>> streamCompletableFutures()
public Stage<U> merge(Stage<U> s)
s - Reactive stage builder to merge withpublic static <R> Stage<R> merge(Stage s1, Stage s2)
s1 - Reactive stage builder to merges2 - Reactive stage builder to mergepublic Stage<U> onFail(java.util.function.Function<? extends java.lang.Throwable,U> fn)
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.fn - Recovery function, the exception is input, and the recovery
value is outputpublic Stage<U> capture(java.util.function.Consumer<? extends java.lang.Throwable> errorHandler)
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.errorHandler - A consumer that recieves and deals with an unrecoverable error
in the dataflowpublic ReactCollector<U> collectResults()
Integer result = new SimpleReact()
.<Integer, Integer> react(() -> 1, () -> 2, () -> 3)
.then((it) -> { it * 200)
.collectResults()
.<List<Integer>>block()
.submit(
it -> it.orElse(new ArrayList())
.parallelStream()
.filter(f -> f > 300)
.map(m -> m - 5)
.reduce(0, (acc, next) -> acc + next));
public java.util.List<U> block()
List<String> strings = new SimpleReact().<Integer, Integer> react(() -> 1, () -> 2, () -> 3)
.then((it) -> it * 100)
.then((it) -> "*" + it)
.block();
In this example, once the current thread of execution meets the React
block method, it will block until all tasks have been completed. The
result will be returned as a List. The Reactive tasks triggered by the
Suppliers are non-blocking, and are not impacted by the block method
until they are complete. Block, only blocks the current thread.public <R> R block(java.util.stream.Collector collector)
collector - to perform aggregation / reduction operation on the results
(e.g. to Collect into a List or String)public U first()
public U last()
public <R> R blockAndExtract(Extractor extractor)
extractor - used to determine which value should be returned, recieves
current collected input and extracts a return valuepublic <R> R blockAndExtract(Extractor extractor, java.util.function.Predicate<Status> breakout)
extractor - used to determine which value should be returned, recieves
current collected input and extracts a return valuebreakout - Predicate that determines whether the block should be
continued or removedpublic java.util.List<U> block(java.util.function.Predicate<Status> breakout)
List<String> strings = new SimpleReact().<Integer, Integer> react(() -> 1, () -> 2, () -> 3)
.then(it -> it * 100)
.then(it -> "*" + it)
.block(status -> status.getCompleted()>1);
In this example the current thread will unblock once more than one result
has been returned.breakout - Predicate that determines whether the block should be
continued or removedpublic <R> R block(java.util.stream.Collector collector,
java.util.function.Predicate<Status> breakout)
collector - to perform aggregation / reduction operation on the results
(e.g. to Collect into a List or String)breakout - Predicate that determines whether the block should be
continued or removedpublic <T,R> Stage<R> allOf(java.util.function.Function<java.util.List<T>,R> fn)
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.fn - Function that recieves the results of all currently active
tasks as inputpublic <T,R> Stage<R> allOf(java.util.stream.Collector collector, java.util.function.Function<T,R> fn)
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 inputpublic void run(java.util.concurrent.ExecutorService e)
e - Executor service to trigger lazy stream on (Stream
CompletableFutures will use ExecutorService associated with
this Stage may not be the same one).public void run(java.util.concurrent.ExecutorService e,
java.lang.Runnable r)
public void run()
public <C extends java.util.Collection<U>> C run(java.util.function.Supplier<C> collector)
collector - Supplier that creates a collection to store results inpublic java.util.Iterator<U> iterator()
public java.util.Spliterator<U> spliterator()
public boolean isParallel()
public org.jooq.lambda.Seq<U> sequential()
public org.jooq.lambda.Seq<U> onClose(java.lang.Runnable closeHandler)
public void close()
public java.util.stream.IntStream mapToInt(java.util.function.ToIntFunction<? super U> mapper)
public java.util.stream.LongStream mapToLong(java.util.function.ToLongFunction<? super U> mapper)
public java.util.stream.DoubleStream mapToDouble(java.util.function.ToDoubleFunction<? super U> mapper)
public java.util.stream.IntStream flatMapToInt(java.util.function.Function<? super U,? extends java.util.stream.IntStream> mapper)
public java.util.stream.LongStream flatMapToLong(java.util.function.Function<? super U,? extends java.util.stream.LongStream> mapper)
public java.util.stream.DoubleStream flatMapToDouble(java.util.function.Function<? super U,? extends java.util.stream.DoubleStream> mapper)
public org.jooq.lambda.Seq<U> distinct()
public org.jooq.lambda.Seq<U> sorted()
public Stage<U> self(java.util.function.Consumer<Stage<U>> consumer)
consumer - Consumer that will recieve current stagepublic Queue<U> toQueue()
public org.jooq.lambda.Seq<U> limit(long maxSize)
public org.jooq.lambda.Seq<U> skip(long n)
public void forEach(java.util.function.Consumer<? super U> action)
public void forEachOrdered(java.util.function.Consumer<? super U> action)
forEachOrdered in interface java.util.stream.Stream<U>public java.lang.Object[] toArray()
toArray in interface java.util.stream.Stream<U>public <A> A[] toArray(java.util.function.IntFunction<A[]> generator)
toArray in interface java.util.stream.Stream<U>public U reduce(U identity, java.util.function.BinaryOperator<U> accumulator)
reduce in interface java.util.stream.Stream<U>public java.util.Optional<U> reduce(java.util.function.BinaryOperator<U> accumulator)
reduce in interface java.util.stream.Stream<U>public <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>public <R,A> R collect(java.util.stream.Collector<? super U,A,R> collector)
collect in interface java.util.stream.Stream<U>public java.util.Optional<U> min(java.util.Comparator<? super U> comparator)
min in interface java.util.stream.Stream<U>public java.util.Optional<U> max(java.util.Comparator<? super U> comparator)
max in interface java.util.stream.Stream<U>public long count()
count in interface java.util.stream.Stream<U>public boolean anyMatch(java.util.function.Predicate<? super U> predicate)
anyMatch in interface java.util.stream.Stream<U>public boolean allMatch(java.util.function.Predicate<? super U> predicate)
allMatch in interface java.util.stream.Stream<U>public boolean noneMatch(java.util.function.Predicate<? super U> predicate)
noneMatch in interface java.util.stream.Stream<U>public java.util.Optional<U> findFirst()
findFirst in interface java.util.stream.Stream<U>public java.util.Optional<U> findAny()
findAny in interface java.util.stream.Stream<U>public <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>