public interface LazySimpleReactStream<U> extends BlockingStream<U>, ConfigurableStream<U,FastFuture<U>>, ToQueue<U>, BaseSimpleReactStream<U>
Modifier and Type | Method and Description |
---|---|
static SimpleReactFailedStageException |
assureSimpleReactException(java.lang.Throwable throwable) |
default LazySimpleReactStream<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 ListX<BaseSimpleReactStream<U>> |
copySimpleReactStream(int times) |
default LazySimpleReactStream<U> |
doOnEach(java.util.function.Function<U,U> fn)
Applies a function to this phase independent on the main flow.
|
default LazySimpleReactStream<U> |
doOnEachSync(java.util.function.Function<U,U> fn)
Applies a function to this phase independent on the main flow, continues on the currently executing thread.
|
default LazySimpleReactStream<U> |
filter(java.util.function.Predicate<? super U> p)
Removes elements that do not match the supplied predicate from the
dataflow
|
default LazySimpleReactStream<U> |
filterSync(java.util.function.Predicate<? super U> p)
Synchronous filtering operation
Removes elements that do not match the supplied predicate from the
dataflow
|
default <R> LazySimpleReactStream<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 <R> LazySimpleReactStream<R> |
flatMapToCompletableFuture(java.util.function.Function<U,java.util.concurrent.CompletableFuture<R>> flatFn)
Perform a flatMap operation where the CompletableFuture type returned is flattened from the resulting Stream
If in async mode this operation is performed asyncrhonously
If in sync mode this operation is performed synchronously
|
default <R> LazySimpleReactStream<R> |
flatMapToCompletableFutureSync(java.util.function.Function<U,java.util.concurrent.CompletableFuture<R>> flatFn)
Perform a flatMap operation where the CompletableFuture type returned is flattened from the resulting Stream
This operation is performed synchronously
|
LazyStreamWrapper<U> |
getLastActive() |
LazyReact |
getSimpleReact() |
Continueable |
getSubscription() |
static <U,R> java.util.function.Function<U,R> |
handleExceptions(java.util.function.Function<? super U,? extends R> fn) |
default LazySimpleReactStream<U> |
onFail(java.lang.Class<? extends java.lang.Throwable> exceptionClass,
java.util.function.Function<SimpleReactFailedStageException,U> fn)
Recover for a particular class of exceptions only.
|
default LazySimpleReactStream<U> |
onFail(java.util.function.Function<SimpleReactFailedStageException,U> fn)
React onFail
Define a function that can be used to recover from exceptions during the
preceeding stage of the dataflow.
|
default LazySimpleReactStream<U> |
peek(java.util.function.Consumer<? super U> consumer)
Peek asynchronously at the results in the current stage.
|
default LazySimpleReactStream<U> |
peekSync(java.util.function.Consumer<? super U> consumer)
Synchronous peek operator
|
default <R> LazySimpleReactStream<R> |
retry(java.util.function.Function<? super U,? extends R> fn)
Will execute this phase on the RetryExecutor (default or user supplied).
|
default <T> java.util.stream.Stream<java.util.concurrent.CompletableFuture<T>> |
streamCompletableFutures() |
default <R> LazySimpleReactStream<R> |
then(java.util.function.Function<? super U,? extends R> fn,
java.util.concurrent.Executor service) |
default <R> LazySimpleReactStream<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 <R> LazySimpleReactStream<R> |
thenSync(java.util.function.Function<? super U,? extends R> fn) |
LazySimpleReactStream<U> |
withAsync(boolean b) |
LazySimpleReactStream<U> |
withErrorHandler(java.util.Optional<java.util.function.Consumer<java.lang.Throwable>> errorHandler) |
<R> LazySimpleReactStream<R> |
withLastActive(LazyStreamWrapper<R> streamWrapper) |
LazySimpleReactStream<U> |
withQueueFactory(QueueFactory<U> queue) |
LazySimpleReactStream<U> |
withRetrier(com.nurkiewicz.asyncretry.RetryExecutor retry) |
LazySimpleReactStream<U> |
withSubscription(Continueable sub) |
LazySimpleReactStream<U> |
withTaskExecutor(java.util.concurrent.Executor e) |
getErrorHandler, getRetrier, getTaskExecutor, isAsync
addToQueue, getQueueFactory, toQueue, toQueue, toQueue
async, cast, empty, freeThread, freeThread, fromStream, getQueueFactory, getTaskExecutor, intersperse, isAsync, iterator, of, of, ofType, parallel, react, react, simpleReactStream, simpleReactStream, simpleReactStream, simpleReactStream, simpleReactStreamFrom, simpleReactStreamFromIterable, skip, sync, toQueue
block, block, getErrorHandler
LazyReact getSimpleReact()
getSimpleReact
in interface BaseSimpleReactStream<U>
getSimpleReact
in interface ConfigurableStream<U,FastFuture<U>>
LazySimpleReactStream<U> withTaskExecutor(java.util.concurrent.Executor e)
withTaskExecutor
in interface ConfigurableStream<U,FastFuture<U>>
LazySimpleReactStream<U> withRetrier(com.nurkiewicz.asyncretry.RetryExecutor retry)
withRetrier
in interface BaseSimpleReactStream<U>
withRetrier
in interface ConfigurableStream<U,FastFuture<U>>
LazySimpleReactStream<U> withQueueFactory(QueueFactory<U> queue)
withQueueFactory
in interface BaseSimpleReactStream<U>
withQueueFactory
in interface ConfigurableStream<U,FastFuture<U>>
LazySimpleReactStream<U> withErrorHandler(java.util.Optional<java.util.function.Consumer<java.lang.Throwable>> errorHandler)
withErrorHandler
in interface ConfigurableStream<U,FastFuture<U>>
LazySimpleReactStream<U> withSubscription(Continueable sub)
withSubscription
in interface BaseSimpleReactStream<U>
withSubscription
in interface ConfigurableStream<U,FastFuture<U>>
LazySimpleReactStream<U> withAsync(boolean b)
withAsync
in interface ConfigurableStream<U,FastFuture<U>>
Continueable getSubscription()
getSubscription
in interface BaseSimpleReactStream<U>
<R> LazySimpleReactStream<R> withLastActive(LazyStreamWrapper<R> streamWrapper)
LazyStreamWrapper<U> getLastActive()
getLastActive
in interface BaseSimpleReactStream<U>
getLastActive
in interface BlockingStream<U>
default <R> LazySimpleReactStream<R> then(java.util.function.Function<? super U,? extends R> fn, java.util.concurrent.Executor service)
then
in interface BaseSimpleReactStream<U>
default <R> LazySimpleReactStream<R> thenSync(java.util.function.Function<? super U,? extends R> fn)
thenSync
in interface BaseSimpleReactStream<U>
default <R> LazySimpleReactStream<R> retry(java.util.function.Function<? super U,? extends R> fn)
retry
in interface BaseSimpleReactStream<U>
fn
- Function that will be executed and retried on failuredefault <R> LazySimpleReactStream<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.htm
l then
in interface BaseSimpleReactStream<U>
fn
- Function to be applied to the results of the currently active
event tasksdefault LazySimpleReactStream<U> doOnEach(java.util.function.Function<U,U> fn)
doOnEach
in interface BaseSimpleReactStream<U>
fn
- Function to be applied to each completablefuture on completiondefault LazySimpleReactStream<U> doOnEachSync(java.util.function.Function<U,U> fn)
doOnEachSync
in interface BaseSimpleReactStream<U>
fn
- Function to be applied to each completablefuture on completiondefault LazySimpleReactStream<U> peek(java.util.function.Consumer<? super U> consumer)
peek
in interface BaseSimpleReactStream<U>
consumer
- That will recieve current resultsdefault LazySimpleReactStream<U> peekSync(java.util.function.Consumer<? super U> consumer)
peekSync
in interface BaseSimpleReactStream<U>
consumer
- Peek consumerstatic <U,R> java.util.function.Function<U,R> handleExceptions(java.util.function.Function<? super U,? extends R> fn)
default <R> LazySimpleReactStream<R> flatMapToCompletableFuture(java.util.function.Function<U,java.util.concurrent.CompletableFuture<R>> flatFn)
assertThat( new SimpleReact()
.of(1,2,3)
.flatMapCompletableFuture(i->CompletableFuture.completedFuture(i))
.block(),equalTo(Arrays.asList(1,2,3)));
In this example the result of the flatMapCompletableFuture is 'flattened' to the raw integer valuesflatMapToCompletableFuture
in interface BaseSimpleReactStream<U>
flatFn
- flatMap functiondefault <R> LazySimpleReactStream<R> flatMapToCompletableFutureSync(java.util.function.Function<U,java.util.concurrent.CompletableFuture<R>> flatFn)
assertThat( new SimpleReact()
.of(1,2,3)
.flatMapCompletableFutureSync(i->CompletableFuture.completedFuture(i))
.block(),equalTo(Arrays.asList(1,2,3)));
In this example the result of the flatMapCompletableFuture is 'flattened' to the raw integer valuesflatMapToCompletableFutureSync
in interface BaseSimpleReactStream<U>
flatFn
- flatMap functiondefault <R> LazySimpleReactStream<R> flatMap(java.util.function.Function<? super U,? extends java.util.stream.Stream<? extends R>> flatFn)
flatMap
in interface BaseSimpleReactStream<U>
flatFn
- Function that coverts a value (e.g. a Collection) into a Streamdefault ListX<BaseSimpleReactStream<U>> copySimpleReactStream(int times)
default LazySimpleReactStream<U> filter(java.util.function.Predicate<? super U> p)
filter
in interface BaseSimpleReactStream<U>
p
- Predicate that will be used to filter elements from the
dataflowdefault LazySimpleReactStream<U> filterSync(java.util.function.Predicate<? super U> p)
filterSync
in interface BaseSimpleReactStream<U>
p
- Predicate that will be used to filter elements from the
dataflowdefault <T> java.util.stream.Stream<java.util.concurrent.CompletableFuture<T>> streamCompletableFutures()
streamCompletableFutures
in interface BaseSimpleReactStream<U>
default LazySimpleReactStream<U> onFail(java.util.function.Function<SimpleReactFailedStageException,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.onFail
in interface BaseSimpleReactStream<U>
fn
- Recovery function, the exception is input, and the recovery
value is outputdefault LazySimpleReactStream<U> onFail(java.lang.Class<? extends java.lang.Throwable> exceptionClass, java.util.function.Function<SimpleReactFailedStageException,U> fn)
onFail(IOException.class, recoveryFunction1)
.onFail(Throwable.class,recovertyFunction2)
For an IOException recoveryFunction1 will be executed
but with the definitions reveresed
onFail(Throwable.class,recovertyFunction2)
.onFail(IOException.class, recoveryFunction1)
recoveryFunction1 will not be calledonFail
in interface BaseSimpleReactStream<U>
exceptionClass
- Class of exceptions to recover fromfn
- Recovery functionstatic SimpleReactFailedStageException assureSimpleReactException(java.lang.Throwable throwable)
default LazySimpleReactStream<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.capture
in interface BaseSimpleReactStream<U>
errorHandler
- A consumer that recieves and deals with an unrecoverable error
in the dataflow