public class LazyReact extends BaseSimpleReact
Constructor and Description |
---|
LazyReact()
Construct a LazyReact builder using standard thread pool.
|
LazyReact(java.util.concurrent.Executor executor)
Construct a LazyReact builder with provided Executor
|
LazyReact(java.util.concurrent.Executor currentThreadExecutor,
com.nurkiewicz.asyncretry.AsyncRetryExecutor withScheduler,
boolean async,
MaxActive maxActive2) |
LazyReact(java.util.concurrent.Executor executor,
com.nurkiewicz.asyncretry.RetryExecutor retrier,
java.lang.Boolean async,
MaxActive maxActive,
java.util.concurrent.Executor pub,
boolean streamOfFutures,
boolean objectPoolingActive,
boolean autoOptimize) |
LazyReact(int threadPoolSize,
int maxActiveTasks)
LazyReact builder with a new TaskExecutor with threads determined by threadPoolSize
Max concurrent tasks is determined by concurrency
|
Modifier and Type | Method and Description |
---|---|
LazyReact |
async()
Start any created Streams in asyncrhonous mode - that is tasks will be submited to an Executor to be run.
|
LazyReact |
autoOptimizeOff()
Turn off automatic threading management.
|
LazyReact |
autoOptimizeOn()
Turn on automatic threading optimization.
|
<U> LazyFutureStream<U> |
construct(java.util.stream.Stream s) |
<U> LazyFutureStream<U> |
constructFutures(java.util.stream.Stream<java.util.concurrent.CompletableFuture<U>> s) |
<R> LazyFutureStream<R> |
from(java.util.Collection<R> collection)
Start a LazyFutureStream from a Collection
|
<U> LazyFutureStream<U> |
from(java.util.concurrent.CompletableFuture<U>... cf) |
<U> LazyFutureStream<U> |
from(java.util.concurrent.CompletableFuture<U> cf) |
LazyFutureStream<java.lang.Double> |
from(java.util.stream.DoubleStream stream)
Start a reactive dataflow from a stream.
|
LazyFutureStream<java.lang.Integer> |
from(java.util.stream.IntStream stream)
Start a reactive dataflow from a stream.
|
<U> LazyFutureStream<U> |
from(java.util.Iterator<U> iterator)
Start a LazyFutureStream from a JDK Iterator
|
LazyFutureStream<java.lang.Long> |
from(java.util.stream.LongStream stream)
Start a reactive dataflow from a stream.
|
<U> LazyFutureStream<U> |
from(java.util.stream.Stream<U> stream)
Start a reactive dataflow from a stream.
|
<U> LazyFutureStream<U> |
fromIterable(java.lang.Iterable<U> iter)
Start a reactive flow from a JDK Iterator
|
<U> LazyFutureStream<U> |
fromStream(java.util.stream.Stream<java.util.concurrent.CompletableFuture<U>> stream)
Start a reactive dataflow from a stream of CompletableFutures.
|
boolean |
isAsync() |
<U> LazyFutureStream<U> |
iterateInfinitely(U seed,
java.util.function.UnaryOperator<U> f)
Iterate infinitely using the supplied seed and function
|
LazyReact |
objectPoolingOff()
Turn objectPooling off for any Streams created by the returned LazyReact builder.
|
LazyReact |
objectPoolingOn()
Turn objectPooling on for any Streams created by the returned LazyReact builder
This improves performance for Streams with very large numbers of elements, by reusing
Future instances.
|
<U> LazyFutureStream<U> |
of(U... array) |
static LazyReact |
parallelBuilder() |
static LazyReact |
parallelBuilder(int parallelism)
Construct a new LazyReact builder, with a new task executor and retry
executor with configured number of threads
|
static LazyReact |
parallelCommonBuilder() |
LazyFutureStream<java.lang.Integer> |
range(int startInclusive,
int endExclusive) |
<U> LazyFutureStream<U> |
react(java.util.Collection<java.util.function.Supplier<U>> actions)
Start a reactive dataflow with a list of one-off-suppliers
|
<U> LazyFutureStream<U> |
react(java.util.Iterator<java.util.function.Supplier<U>> actions)
Start a reactive dataflow with a list of one-off-suppliers
|
<U> LazyFutureStream<U> |
react(java.util.stream.Stream<java.util.function.Supplier<U>> actions)
Start a reactive dataflow with a list of one-off-suppliers
|
<U> LazyFutureStream<U> |
react(java.util.function.Supplier<U>... actions)
Start a reactive dataflow with an array of one-off-suppliers
|
protected <U> LazyFutureStream<U> |
reactI(java.util.function.Supplier<U>... actions)
This internal method has been left protected, so it can be mocked / stubbed as some of the entry points are final
|
<U> LazyFutureStream<U> |
reactInfinitely(java.util.function.Supplier<U> s)
Generate an infinite reactive flow.
|
<U> LazyFutureStream<U> |
reactInfinitelyAsync(java.util.function.Supplier<U> s)
Generate an infinite reactive flow.
|
<U> LazyFutureStream<U> |
reactIterable(java.lang.Iterable<java.util.function.Supplier<U>> actions)
Start a reactive dataflow with a list of one-off-suppliers
|
static LazyReact |
sequentialBuilder() |
static LazyReact |
sequentialCommonBuilder() |
static LazyReact |
sequentialCurrentBuilder() |
LazyReact |
sync()
Start any created Streams in syncrhonous mode - that is tasks will be executed on the calling thread
|
getExecutor, getRetrier
public LazyReact()
ThreadPools.getStandard()
public LazyReact(java.util.concurrent.Executor executor)
executor
- Executor to usepublic LazyReact(int threadPoolSize, int maxActiveTasks)
threadPoolSize
- maxActiveTasks
- public LazyReact(java.util.concurrent.Executor executor, com.nurkiewicz.asyncretry.RetryExecutor retrier, java.lang.Boolean async, MaxActive maxActive, java.util.concurrent.Executor pub, boolean streamOfFutures, boolean objectPoolingActive, boolean autoOptimize)
executor
- Task Executor for concurrent tasksretrier
- Async Retrierasync
- If true each task will be submitted to an executor servicepublic LazyReact(java.util.concurrent.Executor currentThreadExecutor, com.nurkiewicz.asyncretry.AsyncRetryExecutor withScheduler, boolean async, MaxActive maxActive2)
public boolean isAsync()
isAsync
in class BaseSimpleReact
public <U> LazyFutureStream<U> from(java.util.concurrent.CompletableFuture<U> cf)
from
in class BaseSimpleReact
public <U> LazyFutureStream<U> from(java.util.concurrent.CompletableFuture<U>... cf)
from
in class BaseSimpleReact
public <U> LazyFutureStream<U> construct(java.util.stream.Stream s)
construct
in class BaseSimpleReact
public <U> LazyFutureStream<U> constructFutures(java.util.stream.Stream<java.util.concurrent.CompletableFuture<U>> s)
public LazyReact objectPoolingOn()
return new LazyReact()
.objectPoolingOn()
.range(0,5_000_000_000)
.map(this::process)
.forEach(System.out::println);
public LazyReact objectPoolingOff()
LazyReact react;
react.objectPoolingOff()
.range(0,5_000)
.map(this::process)
.forEach(System.out::println);
public LazyReact autoOptimizeOn()
new LazyReact().autoOptimizeOn()
.range(0, 1_000_000)
.map(i->i+2)
.map(i->Thread.currentThread().getId())
.peek(System.out::println)
.runOnCurrent();
public LazyReact autoOptimizeOff()
LazyReact react;
react.autoOptimizeOff()
.range(0, 1_000_000)
.map(i->i+2)
.map(i->Thread.currentThread().getId())
.peek(System.out::println)
.runOnCurrent();
public LazyReact async()
public LazyReact sync()
public LazyFutureStream<java.lang.Integer> range(int startInclusive, int endExclusive)
range
in class BaseSimpleReact
public <U> LazyFutureStream<U> fromStream(java.util.stream.Stream<java.util.concurrent.CompletableFuture<U>> stream)
BaseSimpleReact
fromStream
in class BaseSimpleReact
stream
- of CompletableFutures that will be used to drive the reactive dataflow@SafeVarargs public final <U> LazyFutureStream<U> react(java.util.function.Supplier<U>... actions)
BaseSimpleReact
react
in class BaseSimpleReact
actions
- Array of Suppliers to provide data (and thus events) that
downstream jobs will react toopublic <U> LazyFutureStream<U> from(java.util.stream.Stream<U> stream)
BaseSimpleReact
from
in class BaseSimpleReact
stream
- that will be used to drive the reactive dataflowpublic LazyFutureStream<java.lang.Integer> from(java.util.stream.IntStream stream)
BaseSimpleReact
from
in class BaseSimpleReact
stream
- that will be used to drive the reactive dataflowpublic LazyFutureStream<java.lang.Double> from(java.util.stream.DoubleStream stream)
BaseSimpleReact
from
in class BaseSimpleReact
stream
- that will be used to drive the reactive dataflowpublic LazyFutureStream<java.lang.Long> from(java.util.stream.LongStream stream)
BaseSimpleReact
from
in class BaseSimpleReact
stream
- that will be used to drive the reactive dataflowpublic <U> LazyFutureStream<U> of(U... array)
of
in class BaseSimpleReact
public <U> LazyFutureStream<U> react(java.util.Collection<java.util.function.Supplier<U>> actions)
BaseSimpleReact
react
in class BaseSimpleReact
actions
- List of Suppliers to provide data (and thus events) that
downstream jobs will react toopublic <U> LazyFutureStream<U> from(java.util.Iterator<U> iterator)
from
in class BaseSimpleReact
iterator
- SimpleReact will iterate over this iterator concurrently to start the reactive dataflowpublic <R> LazyFutureStream<R> from(java.util.Collection<R> collection)
from
in class BaseSimpleReact
collection
- - Collection Stream will be formed fromprotected <U> LazyFutureStream<U> reactI(java.util.function.Supplier<U>... actions)
BaseSimpleReact
reactI
in class BaseSimpleReact
public <U> LazyFutureStream<U> fromIterable(java.lang.Iterable<U> iter)
BaseSimpleReact
fromIterable
in class BaseSimpleReact
iter
- SimpleReact will iterate over this iterator concurrently to start the reactive dataflowpublic <U> LazyFutureStream<U> react(java.util.stream.Stream<java.util.function.Supplier<U>> actions)
BaseSimpleReact
react
in class BaseSimpleReact
actions
- Stream of Suppliers to provide data (and thus events) that
downstream jobs will react toopublic <U> LazyFutureStream<U> react(java.util.Iterator<java.util.function.Supplier<U>> actions)
BaseSimpleReact
react
in class BaseSimpleReact
actions
- Iterator over Suppliers to provide data (and thus events) that
downstream jobs will react toopublic <U> LazyFutureStream<U> reactIterable(java.lang.Iterable<java.util.function.Supplier<U>> actions)
BaseSimpleReact
reactIterable
in class BaseSimpleReact
actions
- Stream of Suppliers to provide data (and thus events) that
downstream jobs will react toopublic static LazyReact parallelBuilder()
public static LazyReact parallelBuilder(int parallelism)
parallelism
- Number of threads task executor should havepublic static LazyReact parallelCommonBuilder()
see RetryBuilder#getDefaultInstance()
public static LazyReact sequentialBuilder()
public static LazyReact sequentialCommonBuilder()
public static LazyReact sequentialCurrentBuilder()
public <U> LazyFutureStream<U> reactInfinitely(java.util.function.Supplier<U> s)
s
- Supplier to generate the infinite flowSimpleReact Queue for a way to create a more managable infinit flow
public <U> LazyFutureStream<U> reactInfinitelyAsync(java.util.function.Supplier<U> s)
s
- Supplier to generate the infinite flowSimpleReact Queue for a way to create a more managable infinit flow
public <U> LazyFutureStream<U> iterateInfinitely(U seed, java.util.function.UnaryOperator<U> f)
seed
- Initial valuef
- Function that performs the iteration