public interface BlockingStream<U> extends ConfigurableStream<U>
| Modifier and Type | Field and Description |
|---|---|
static ExceptionSoftener |
exceptionSoftener |
| Modifier and Type | Method and Description |
|---|---|
static <R> R |
aggregateResults(java.util.stream.Collector collector,
java.util.List<java.util.concurrent.CompletableFuture> completedFutures,
java.util.Optional<java.util.function.Consumer<java.lang.Throwable>> errorHandler) |
default 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. |
default <R> R |
block(java.util.stream.Collector collector) |
default <R> R |
block(java.util.stream.Collector collector,
java.util.function.Predicate<Status> breakout) |
default <R> R |
block(java.util.stream.Collector collector,
StreamWrapper lastActive) |
default 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.
|
default <R> R |
blockAndExtract(Extractor extractor)
Block until tasks complete and return a value determined by the extractor
supplied.
|
default <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.
|
static void |
capture(java.lang.Exception e,
java.util.Optional<java.util.function.Consumer<java.lang.Throwable>> errorHandler) |
default ReactCollector<U> |
collectResults()
This provides a mechanism to collect all of the results of active tasks
inside a dataflow stage.
|
default U |
first()
Block until first result received
|
static java.lang.Object |
getSafe(java.util.concurrent.CompletableFuture next,
java.util.Optional<java.util.function.Consumer<java.lang.Throwable>> errorHandler) |
default U |
last()
Block until all results received.
|
default <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.
|
getErrorHandler, getLastActive, getRetrier, getSimpleReact, getTaskExecutor, isEager, withEager, withErrorHandler, withLastActive, withLazyCollector, withQueueFactory, withRetrier, withTaskExecutor, withWaitStrategystatic final ExceptionSoftener exceptionSoftener
default 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));
default 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.default <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)default <R> R block(java.util.stream.Collector collector,
StreamWrapper lastActive)
static <R> R aggregateResults(java.util.stream.Collector collector,
java.util.List<java.util.concurrent.CompletableFuture> completedFutures,
java.util.Optional<java.util.function.Consumer<java.lang.Throwable>> errorHandler)
static void capture(java.lang.Exception e,
java.util.Optional<java.util.function.Consumer<java.lang.Throwable>> errorHandler)
static java.lang.Object getSafe(java.util.concurrent.CompletableFuture next,
java.util.Optional<java.util.function.Consumer<java.lang.Throwable>> errorHandler)
default U first()
default U last()
default <R> R blockAndExtract(Extractor extractor)
extractor - used to determine which value should be returned, recieves
current collected input and extracts a return valuedefault <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 removeddefault 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 removeddefault <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 removeddefault <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)