public interface BaseSimpleReactStream<U> extends BlockingStream<U>
Modifier and Type | Method and Description |
---|---|
BaseSimpleReactStream<U> |
async() |
BaseSimpleReactStream<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> BaseSimpleReactStream<U> |
cast(java.lang.Class<U> type) |
BaseSimpleReactStream<U> |
doOnEach(java.util.function.Function<U,U> fn)
Applies a function to this phase independent on the main flow.
|
BaseSimpleReactStream<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.
|
static <T> SimpleReactStream<T> |
empty()
Create an empty sequential synchronous stream that runs on the current thread
|
BaseSimpleReactStream<U> |
filter(java.util.function.Predicate<? super U> p)
Removes elements that do not match the supplied predicate from the
dataflow
|
BaseSimpleReactStream<U> |
filterSync(java.util.function.Predicate<? super U> p)
Synchronous filtering operation
Removes elements that do not match the supplied predicate from the
dataflow
|
<R> BaseSimpleReactStream<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.
|
<R> BaseSimpleReactStream<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
|
<R> BaseSimpleReactStream<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
|
static <T> SimpleReactStream<T> |
freeThread(T... values)
Create a sequential synchronous stream that runs on the current thread
|
static <T> SimpleReactStream<T> |
freeThread(T value)
Create a sequential synchronous stream that runs on the current thread
|
<R> BaseSimpleReactStream<R> |
fromStream(java.util.stream.Stream<R> stream) |
StreamWrapper<U> |
getLastActive() |
QueueFactory<U> |
getQueueFactory() |
ReactBuilder |
getSimpleReact() |
Continueable |
getSubscription() |
java.util.concurrent.Executor |
getTaskExecutor() |
default BaseSimpleReactStream<U> |
intersperse(U value)
Returns a stream with a given value interspersed between any two values
of this stream.
|
boolean |
isAsync() |
default java.util.Iterator<U> |
iterator() |
static <T> SimpleReactStream<T> |
of(T... values)
Create a sequential synchronous stream that runs on the current thread
|
static <T> SimpleReactStream<T> |
of(T value)
Create a sequential synchronous stream that runs on the current thread
|
default <U> BaseSimpleReactStream<U> |
ofType(java.lang.Class<U> type)
Keep only those elements in a stream that are of a given type.
|
BaseSimpleReactStream<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.
|
BaseSimpleReactStream<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.
|
static <U> SimpleReactStream<U> |
parallel(U... array)
Construct an SimpleReactStream from specified array, that will run in parallel
on the common Parallel executor service (by default the Common ForkJoinPool) see ThreadPools#setUseCommon
to change to a different pool
|
BaseSimpleReactStream<U> |
peek(java.util.function.Consumer<? super U> consumer)
Peek asynchronously at the results in the current stage.
|
BaseSimpleReactStream<U> |
peekSync(java.util.function.Consumer<? super U> consumer)
Synchronous peek operator
|
static <T> SimpleReactStream<T> |
react(java.util.function.Supplier<T>... values)
Create a 'free threaded' asynchronous stream that runs on a single thread (not current)
The supplier will be executed asyncrhonously, subsequent tasks will be executed synchronously unless the async() operator is invoked.
|
static <T> SimpleReactStream<T> |
react(java.util.function.Supplier<T> value)
Create a 'free threaded' asynchronous stream that runs on a single thread (not current)
The supplier will be executed asyncrhonously, subsequent tasks will be executed synchronously unless the async() operator is invoked.
|
<R> java.lang.Object |
retry(java.util.function.Function<? super U,? extends R> fn)
Will execute this phase on the RetryExecutor (default or user supplied).
|
static <T> SimpleReactStream<T> |
simpleReactStream(java.util.concurrent.CompletableFuture<T>... values)
Create a 'free threaded' asynchronous stream that runs on a single thread (not current)
The supplier will be executed asyncrhonously, subsequent tasks will be executed synchronously unless the async() operator
is invoked.
|
static <T> BaseSimpleReactStream<T> |
simpleReactStream(java.util.concurrent.CompletableFuture<T> value)
Create a 'free threaded' asynchronous stream that runs on the supplied CompletableFutures executor service (unless async operator invoked
, in which it will switch to the common 'free' thread executor)
Subsequent tasks will be executed synchronously unless the async() operator is invoked.
|
static <T> SimpleReactStream<T> |
simpleReactStream(java.util.Iterator<T> iterator)
Wrap an Iterator into a FutureStream.
|
static <T> SimpleReactStream<T> |
simpleReactStream(java.util.stream.Stream<T> stream)
Wrap a Stream into a SimpleReactStream.
|
static <T> BaseSimpleReactStream<T> |
simpleReactStreamFrom(java.util.stream.Stream<java.util.concurrent.CompletableFuture<T>> stream)
Create a 'free threaded' asynchronous stream that runs on the supplied CompletableFutures executor service (unless async operator invoked
, in which it will switch to the common 'free' thread executor)
Subsequent tasks will be executed synchronously unless the async() operator is invoked.
|
static <T> SimpleReactStream<T> |
simpleReactStreamFromIterable(java.lang.Iterable<T> iterable)
Wrap an Iterable into a FutureStream.
|
BaseSimpleReactStream<U> |
skip(long n) |
<T> java.util.stream.Stream<java.util.concurrent.CompletableFuture<T>> |
streamCompletableFutures() |
BaseSimpleReactStream<U> |
sync() |
<R> BaseSimpleReactStream<R> |
then(java.util.function.Function<? super U,? extends R> fn,
java.util.concurrent.Executor service) |
<R> BaseSimpleReactStream<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.
|
<R> BaseSimpleReactStream<R> |
thenSync(java.util.function.Function<? super U,? extends R> fn) |
Queue<U> |
toQueue() |
BaseSimpleReactStream<U> |
withQueueFactory(QueueFactory<U> queueFactory) |
BaseSimpleReactStream<U> |
withRetrier(com.nurkiewicz.asyncretry.RetryExecutor executor) |
BaseSimpleReactStream<U> |
withSubscription(Continueable subscription) |
block, block, getErrorHandler
ReactBuilder getSimpleReact()
default <U> BaseSimpleReactStream<U> ofType(java.lang.Class<U> type)
default <U> BaseSimpleReactStream<U> cast(java.lang.Class<U> type)
default BaseSimpleReactStream<U> intersperse(U value)
// (1, 0, 2, 0, 3, 0, 4)
SimpleReactStream.of(1, 2, 3, 4).intersperse(0)
BaseSimpleReactStream<U> skip(long n)
default java.util.Iterator<U> iterator()
StreamWrapper<U> getLastActive()
getLastActive
in interface BlockingStream<U>
<R> BaseSimpleReactStream<R> then(java.util.function.Function<? super U,? extends R> fn, java.util.concurrent.Executor service)
<R> BaseSimpleReactStream<R> thenSync(java.util.function.Function<? super U,? extends R> fn)
<R> java.lang.Object retry(java.util.function.Function<? super U,? extends R> fn)
fn
- Function that will be executed and retried on failure<R> BaseSimpleReactStream<R> fromStream(java.util.stream.Stream<R> stream)
<R> BaseSimpleReactStream<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 fn
- Function to be applied to the results of the currently active
event tasksBaseSimpleReactStream<U> doOnEach(java.util.function.Function<U,U> fn)
fn
- Function to be applied to each completablefuture on completionBaseSimpleReactStream<U> doOnEachSync(java.util.function.Function<U,U> fn)
fn
- Function to be applied to each completablefuture on completionBaseSimpleReactStream<U> peek(java.util.function.Consumer<? super U> consumer)
consumer
- That will recieve current resultsBaseSimpleReactStream<U> peekSync(java.util.function.Consumer<? super U> consumer)
consumer
- Peek consumer<R> BaseSimpleReactStream<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 valuesflatFn
- flatMap function<R> BaseSimpleReactStream<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 valuesflatFn
- flatMap function<R> BaseSimpleReactStream<R> flatMap(java.util.function.Function<? super U,? extends java.util.stream.Stream<? extends R>> flatFn)
flatFn
- Function that coverts a value (e.g. a Collection) into a StreamBaseSimpleReactStream<U> filter(java.util.function.Predicate<? super U> p)
p
- Predicate that will be used to filter elements from the
dataflowBaseSimpleReactStream<U> filterSync(java.util.function.Predicate<? super U> p)
p
- Predicate that will be used to filter elements from the
dataflow<T> java.util.stream.Stream<java.util.concurrent.CompletableFuture<T>> streamCompletableFutures()
BaseSimpleReactStream<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.fn
- Recovery function, the exception is input, and the recovery
value is outputBaseSimpleReactStream<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 calledexceptionClass
- Class of exceptions to recover fromfn
- Recovery functionBaseSimpleReactStream<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 dataflowBaseSimpleReactStream<U> sync()
BaseSimpleReactStream<U> async()
static <T> SimpleReactStream<T> react(java.util.function.Supplier<T> value)
@SafeVarargs static <T> SimpleReactStream<T> react(java.util.function.Supplier<T>... values)
static <T> SimpleReactStream<T> of(T value)
@SafeVarargs static <T> SimpleReactStream<T> of(T... values)
static <T> SimpleReactStream<T> freeThread(T value)
Stream.of(Object)
@SafeVarargs static <T> SimpleReactStream<T> freeThread(T... values)
Stream.of(Object[])
static <T> SimpleReactStream<T> empty()
static <U> SimpleReactStream<U> parallel(U... array)
array
- Array of value to form the reactive stream / sequencestatic <T> BaseSimpleReactStream<T> simpleReactStreamFrom(java.util.stream.Stream<java.util.concurrent.CompletableFuture<T>> stream)
Stream.of(Object)
static <T> BaseSimpleReactStream<T> simpleReactStream(java.util.concurrent.CompletableFuture<T> value)
Stream.of(Object)
static <T> SimpleReactStream<T> simpleReactStream(java.util.concurrent.CompletableFuture<T>... values)
Stream.of(Object)
static <T> SimpleReactStream<T> simpleReactStream(java.util.stream.Stream<T> stream)
static <T> SimpleReactStream<T> simpleReactStreamFromIterable(java.lang.Iterable<T> iterable)
static <T> SimpleReactStream<T> simpleReactStream(java.util.Iterator<T> iterator)
Continueable getSubscription()
QueueFactory<U> getQueueFactory()
BaseSimpleReactStream<U> withSubscription(Continueable subscription)
BaseSimpleReactStream<U> withQueueFactory(QueueFactory<U> queueFactory)
BaseSimpleReactStream<U> withRetrier(com.nurkiewicz.asyncretry.RetryExecutor executor)
java.util.concurrent.Executor getTaskExecutor()
boolean isAsync()