public interface EagerFutureStream<U> extends FutureStream<U>, EagerToQueue<U>
FutureStream.Val<T>
java.util.stream.Stream.Builder<T>
ConfigurableStream.SimpleReactConfigurableStream<U>
softener
Modifier and Type | Method and Description |
---|---|
default <T,R> EagerFutureStream<R> |
allOf(java.util.stream.Collector collector,
java.util.function.Function<T,R> fn) |
default <T,R> EagerFutureStream<R> |
allOf(java.util.function.Function<java.util.List<T>,R> fn)
React and allOf
allOf is a non-blocking equivalent of block.
|
default <R> EagerFutureStream<R> |
anyOf(java.util.function.Function<U,R> fn)
React to the completion of any of the events in the previous stage.
|
default EagerFutureStream<U> |
async() |
default EagerFutureStream<java.util.Collection<U>> |
batch(java.util.function.Function<java.util.function.Supplier<U>,java.util.function.Supplier<java.util.Collection<U>>> fn)
Batch elements into a Stream of collections with user defined function
|
default EagerFutureStream<java.util.Collection<U>> |
batchBySize(int size)
Batch the elements in this stream into Lists of specified size
|
default EagerFutureStream<java.util.Collection<U>> |
batchBySize(int size,
java.util.function.Supplier<java.util.Collection<U>> supplier)
Batch the elements in this stream into Collections of specified size The
type of Collection is determined by the specified supplier
|
default EagerFutureStream<java.util.Collection<U>> |
batchByTime(long time,
java.util.concurrent.TimeUnit unit)
Organise elements in a Stream into a Collections based on the time period
they pass through this stage
|
default EagerFutureStream<java.util.Collection<U>> |
batchByTime(long time,
java.util.concurrent.TimeUnit unit,
java.util.function.Supplier<java.util.Collection<U>> factory)
Organise elements in a Stream into a Collections based on the time period
they pass through this stage
|
default void |
cancel()
Cancel the CompletableFutures in this stage of the stream and the initial
phase
|
void |
cancelOriginal()
Cancel the original tasks that populated the EagerFuturestream
|
default EagerFutureStream<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> EagerFutureStream<U> |
cast(java.lang.Class<U> type) |
default EagerFutureStream<java.util.Collection<U>> |
chunkSinceLastRead() |
default <T> EagerFutureStream<org.jooq.lambda.tuple.Tuple2<U,T>> |
combineLatest(FutureStream<T> s)
Similar to zip and withLatest, except will always take the latest from
either Stream (merged with last available from the other).
|
default FutureStream<U> |
concat(SimpleReactStream<U> other)
Concatenate two streams.
|
default EagerFutureStream<U> |
concat(java.util.stream.Stream<U> other)
Concatenate two streams.
|
default EagerFutureStream<U> |
concat(U... other)
Concatenate two streams.
|
default EagerFutureStream<U> |
concat(U other)
Concatenate two streams.
|
default EagerFutureStream<U> |
control(java.util.function.Function<java.util.function.Supplier<U>,java.util.function.Supplier<U>> fn)
Allows clients to control the emission of data for the next phase of the
Stream.
|
default LazyFutureStream<U> |
convertToLazyStream()
Convert between an Eager and Lazy future stream,
can be used to take advantages of each approach during a single Stream
|
default EagerFutureStream<U> |
debounce(long time,
java.util.concurrent.TimeUnit unit)
Can be used to debounce (accept a single data point from a unit of time)
data.
|
default EagerFutureStream<U> |
distinct() |
default EagerFutureStream<U> |
doOnEach(java.util.function.Function<U,U> fn)
Can only be used on Eager Streams
Applies a function to this phase independent on the main flow.
|
default org.jooq.lambda.tuple.Tuple2<org.jooq.lambda.Seq<U>,org.jooq.lambda.Seq<U>> |
duplicate()
Duplicate a Stream into two equivalent LazyFutureStreams, Streams are duplicated as results
of Futures are populated
|
default org.jooq.lambda.tuple.Tuple2<EagerFutureStream<U>,EagerFutureStream<U>> |
duplicateFutures()
Duplicate a Stream into two equivalent LazyFutureStreams, underlying
Stream of Futures is duplicated
|
static <T> EagerFutureStream<T> |
empty() |
default EagerFutureStream<U> |
filter(java.util.function.Predicate<? super U> p)
Removes elements that do not match the supplied predicate from the
dataflow
|
static <U> EagerFutureStream<U> |
firstOf(EagerFutureStream<U>... futureStreams)
Return first Stream out of provided Streams that starts emitted results
|
default EagerFutureStream<U> |
fixedDelay(long time,
java.util.concurrent.TimeUnit unit)
Apply a fixed delay before emitting elements to the next phase of the
Stream.
|
default <R> EagerFutureStream<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> EagerFutureStream<R> |
fromListCompletableFuture(java.util.List<java.util.concurrent.CompletableFuture<R>> list) |
default <R> EagerFutureStream<R> |
fromStream(java.util.stream.Stream<R> stream) |
default <R> EagerFutureStream<R> |
fromStreamOfFutures(java.util.stream.Stream<java.util.concurrent.CompletableFuture<R>> stream)
Construct a SimpleReactStream from provided Stream of CompletableFutures
|
default EagerFutureStream<U> |
intersperse(U value)
Returns a stream with a given value interspersed between any two values
of this stream.
|
default EagerFutureStream<U> |
jitter(long jitterInNanos)
Introduce a random delay between events in a stream Can be used to
prevent behaviour synchronizing within a system
|
default EagerFutureStream<U> |
limit(long maxSize) |
default EagerFutureStream<U> |
limitFutures(long maxSize)
Perform a limit operation on the underlying Stream of Futures
In contrast to EagerFutureStream#limit this removes entries basaed on their
start position
|
default EagerFutureStream<U> |
limitUntil(java.util.function.Predicate<? super U> predicate)
Returns a stream limited to all elements for which a predicate evaluates
to false.
|
default EagerFutureStream<U> |
limitWhile(java.util.function.Predicate<? super U> predicate)
Returns a stream limited to all elements for which a predicate evaluates
to true.
|
default <R> EagerFutureStream<R> |
map(java.util.function.Function<? super U,? extends R> mapper) |
default EagerFutureStream<U> |
merge(SimpleReactStream<U> s)
Merge this reactive dataflow with another of the same type.
|
static <T> EagerFutureStream<T> |
of(java.util.Iterator<T> iterator)
Wrap an Iterator into a FutureStream.
|
static <T> EagerFutureStream<T> |
of(java.util.stream.Stream<T> stream)
Wrap a Stream into a Sequential synchronous FutureStream.
|
static <T> EagerFutureStream<T> |
of(T... values)
Create a sequential synchronous stream
|
static <T> EagerFutureStream<T> |
of(T value)
Create a sequential synchronous stream
|
static <T> EagerFutureStream<T> |
ofIterable(java.lang.Iterable<T> iterable)
Wrap an Iterable into a FutureStream.
|
default <U> EagerFutureStream<U> |
ofType(java.lang.Class<U> type)
Keep only those elements in a stream that are of a given type.
|
default EagerFutureStream<U> |
onClose(java.lang.Runnable closeHandler) |
default EagerFutureStream<U> |
onePer(long time,
java.util.concurrent.TimeUnit unit)
Slow emissions down, emiting one element per specified time period
|
default EagerFutureStream<U> |
onFail(java.lang.Class<? extends java.lang.Throwable> exceptionClass,
java.util.function.Function<? extends SimpleReactFailedStageException,U> fn)
Recover for a particular class of exceptions only.
|
default EagerFutureStream<U> |
onFail(java.util.function.Function<? extends SimpleReactFailedStageException,U> fn)
React onFail
Define a function that can be used to recover from exceptions during the
preceeding stage of the dataflow.
|
default EagerFutureStream<U> |
parallel() |
static <U> EagerFutureStream<U> |
parallel(U... array)
Construct an Eager SimpleReact Stream from specified array
|
static EagerReact |
parallelBuilder() |
static EagerReact |
parallelBuilder(int parallelism)
Construct a new EagerReact builder, with a new task executor and retry
executor with configured number of threads
|
static EagerReact |
parallelCommonBuilder() |
default org.jooq.lambda.tuple.Tuple2<org.jooq.lambda.Seq<U>,org.jooq.lambda.Seq<U>> |
partition(java.util.function.Predicate<? super U> predicate)
Partition a stream into two given a predicate.
|
default org.jooq.lambda.tuple.Tuple2<EagerFutureStream<U>,EagerFutureStream<U>> |
partitionFutureStream(java.util.function.Predicate<? super U> predicate)
Partition an EagerFutureStream into two EagerFutureStreams given a
predicate.
|
default EagerFutureStream<U> |
peek(java.util.function.Consumer<? super U> consumer)
Peek asynchronously at the results in the current stage.
|
static <T> EagerFutureStream<T> |
react(java.util.function.Supplier<T>... values)
Create a parallel asynchronous stream
|
static <T> EagerFutureStream<T> |
react(java.util.function.Supplier<T> value)
Create a parallel asynchronous stream
|
default <R> EagerFutureStream<R> |
retry(java.util.function.Function<U,R> fn)
Will execute this phase on the RetryExecutor (default or user supplied).
|
default EagerFutureStream<U> |
reverse()
Reverse a stream.
|
default <T> EagerFutureStream<T> |
scanLeft(T seed,
java.util.function.BiFunction<T,? super U,T> function)
Scan a stream to the left.
|
default <R> EagerFutureStream<R> |
scanRight(R seed,
java.util.function.BiFunction<? super U,R,R> function)
Scan a stream to the right.
|
default EagerFutureStream<U> |
self(java.util.function.Consumer<FutureStream<U>> consumer)
Give a function access to the current stage of a SimpleReact Stream
|
default EagerFutureStream<U> |
sequential() |
static EagerReact |
sequentialBuilder() |
static EagerReact |
sequentialCommonBuilder() |
default <K> java.util.Map<K,EagerFutureStream<U>> |
shard(java.util.Map<K,Queue<U>> shards,
java.util.function.Function<U,K> sharder)
Break a stream into multiple Streams based of some characteristic of the
elements of the Stream
e.g.
|
default EagerFutureStream<U> |
shuffle()
Shuffle a stream
|
default EagerFutureStream<U> |
shuffle(java.util.Random random)
Shuffle a stream using specified source of randomness
|
default EagerFutureStream<U> |
skip(long n) |
default EagerFutureStream<U> |
skipFutures(long n)
In contast to EagerFutureStream#skip skipFutures will skip the first n entries
of the underlying Stream of Futures.
|
default <T> EagerFutureStream<U> |
skipUntil(FutureStream<T> s)
Return a Stream with the same values as this Stream, but with all values
omitted until the provided stream starts emitting values.
|
default EagerFutureStream<U> |
skipUntil(java.util.function.Predicate<? super U> predicate)
Returns a stream with all elements skipped for which a predicate
evaluates to false.
|
default EagerFutureStream<U> |
skipWhile(java.util.function.Predicate<? super U> predicate)
Returns a stream with all elements skipped for which a predicate
evaluates to true.
|
default EagerFutureStream<U> |
slice(long from,
long to)
Returns a limited interval from a given Stream.
|
default EagerFutureStream<U> |
sliceFutures(long from,
long to)
Returns a limited interval from a given Stream.
|
default EagerFutureStream<U> |
sorted() |
default EagerFutureStream<U> |
sorted(java.util.Comparator<? super U> comparator) |
default org.jooq.lambda.tuple.Tuple2<org.jooq.lambda.Seq<U>,org.jooq.lambda.Seq<U>> |
splitAt(long position)
Split a EagerFutureStream at a given position.
|
default org.jooq.lambda.tuple.Tuple2<EagerFutureStream<U>,EagerFutureStream<U>> |
splitAtFutures(long position)
Split a stream at a given position.
|
default org.jooq.lambda.tuple.Tuple2<EagerFutureStream<U>,EagerFutureStream<U>> |
splitAtFutureStream(long position)
Split a EagerFutureStream at a given position.
|
default org.jooq.lambda.tuple.Tuple2<java.util.Optional<U>,org.jooq.lambda.Seq<U>> |
splitAtHead()
Split a stream at the head.
|
default org.jooq.lambda.tuple.Tuple2<java.util.Optional<U>,EagerFutureStream<U>> |
splitAtHeadFutureStream()
SplitAtHead but return type is EagerFutureStream
|
default java.util.stream.Stream<U> |
stream() |
default EagerFutureStream<U> |
sync() |
default <T> EagerFutureStream<U> |
takeUntil(FutureStream<T> s)
Return a Stream with the same values, but will stop emitting values once
the provided Stream starts to emit values.
|
default <R> EagerFutureStream<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> EagerFutureStream<R> |
then(java.util.function.Function<U,R> fn,
java.util.concurrent.Executor service) |
default <R> EagerFutureStream<R> |
thenSync(java.util.function.Function<U,R> fn) |
default EagerFutureStream<U> |
unordered() |
EagerFutureStream<U> |
withAsync(boolean async) |
EagerFutureStream<U> |
withErrorHandler(java.util.Optional<java.util.function.Consumer<java.lang.Throwable>> errorHandler) |
EagerFutureStream<U> |
withLastActive(StreamWrapper streamWrapper) |
default <T> EagerFutureStream<org.jooq.lambda.tuple.Tuple2<U,T>> |
withLatest(FutureStream<T> s)
Similar to zip and combineLatest, except will always take the latest from
this Stream while taking the last available value from the provided
stream.
|
EagerFutureStream<U> |
withLazyCollector(LazyResultConsumer<U> lazy) |
EagerFutureStream<U> |
withQueueFactory(QueueFactory<U> queue) |
EagerFutureStream<U> |
withRetrier(com.nurkiewicz.asyncretry.RetryExecutor retry) |
EagerFutureStream<U> |
withSubscription(Continueable sub) |
EagerFutureStream<U> |
withTaskExecutor(java.util.concurrent.Executor e) |
EagerFutureStream<U> |
withWaitStrategy(java.util.function.Consumer<java.util.concurrent.CompletableFuture> c) |
default FutureStream<U> |
xPer(int x,
long time,
java.util.concurrent.TimeUnit unit)
Allows x (specified number of) emissions with a time period before
stopping emmissions until specified time has elapsed since last emission
|
default <R> EagerFutureStream<org.jooq.lambda.tuple.Tuple2<U,R>> |
zip(org.jooq.lambda.Seq<R> other)
Zip two streams into one.
|
default <T,R> EagerFutureStream<R> |
zip(org.jooq.lambda.Seq<T> other,
java.util.function.BiFunction<U,T,R> zipper)
Zip two streams into one using a
BiFunction to produce resulting
values. |
default <R> EagerFutureStream<org.jooq.lambda.tuple.Tuple2<U,R>> |
zipFutures(FutureStream<R> other)
Zip two Streams, zipping against the underlying futures of both Streams
Placeholders (Futures) will be populated immediately in the new zipped Stream and results
will be populated asyncrhonously
|
default <R> EagerFutureStream<org.jooq.lambda.tuple.Tuple2<U,R>> |
zipFutures(java.util.stream.Stream<R> other)
Zip two Streams, zipping against the underlying futures of this stream
|
default EagerFutureStream<org.jooq.lambda.tuple.Tuple2<U,java.lang.Long>> |
zipFuturesWithIndex()
Zip this Stream with an index, but Zip based on the underlying tasks, not completed results.
|
default EagerFutureStream<org.jooq.lambda.tuple.Tuple2<U,java.lang.Long>> |
zipWithIndex()
Zip a Stream with a corresponding Stream of indexes.
|
allMatch, anyMatch, cast, chunkLastReadIterator, close, closeOthers, closeOthers, collect, combineLatest, combineLatest, count, findAny, findFirst, firstOf, flatMapToDouble, flatMapToInt, flatMapToLong, forEach, forEachOrdered, intersperse, isParallel, iterator, lift, lift2, mapToDouble, mapToInt, mapToLong, max, merge, min, noneMatch, ofType, reduce, reduce, reduce, reversedIterator, skipUntil, slice, spliterator, takeUntil, toArray, toArray, withLatest, withLatest
cast, concat, cycle, cycle, duplicate, foldLeft, foldLeft, foldRight, foldRight, generate, generate, generate, groupBy, groupBy, groupBy, groupBy, groupBy, groupBy, intersperse, iterate, join, join, join, join, join, join, limit, limitUntil, limitWhile, maxBy, maxBy, minBy, minBy, ofType, partition, reverse, scanLeft, scanRight, seq, seq, seq, seq, seq, shuffle, shuffle, skip, skipUntil, skipWhile, slice, splitAt, splitAtHead, toCollection, toCollection, toList, toList, toMap, toMap, toMap, toSet, toSet, toString, toString, toString, unfold, unzip, unzip, unzip, unzip, zip, zip, zipWithIndex
assureSimpleReactException, bind, doOnEachSync, filterSync, fromStreamCompletableFutureReplace, getOriginalFutures, getSubscription, handleExceptions, join, lastActiveArray, merge, parallelOf, peekSync, streamCompletableFutures, with
block, block, block, block, blockAndExtract, blockAndExtract, first, last
getErrorHandler, getLastActive, getRetrier, getSimpleReact, getTaskExecutor, isAsync, isEager
getQueueFactory, toQueue, toQueue, toQueue
getQueueFactory, toQueue, toQueue, toQueue
EagerFutureStream<U> withAsync(boolean async)
withAsync
in interface ConfigurableStream<U>
withAsync
in interface ConfigurableStream.SimpleReactConfigurableStream<U>
EagerFutureStream<U> withTaskExecutor(java.util.concurrent.Executor e)
withTaskExecutor
in interface ConfigurableStream<U>
withTaskExecutor
in interface ConfigurableStream.SimpleReactConfigurableStream<U>
EagerFutureStream<U> withRetrier(com.nurkiewicz.asyncretry.RetryExecutor retry)
withRetrier
in interface ConfigurableStream<U>
withRetrier
in interface ConfigurableStream.SimpleReactConfigurableStream<U>
EagerFutureStream<U> withWaitStrategy(java.util.function.Consumer<java.util.concurrent.CompletableFuture> c)
withWaitStrategy
in interface ConfigurableStream<U>
withWaitStrategy
in interface ConfigurableStream.SimpleReactConfigurableStream<U>
EagerFutureStream<U> withLazyCollector(LazyResultConsumer<U> lazy)
withLazyCollector
in interface ConfigurableStream<U>
withLazyCollector
in interface ConfigurableStream.SimpleReactConfigurableStream<U>
EagerFutureStream<U> withQueueFactory(QueueFactory<U> queue)
withQueueFactory
in interface ConfigurableStream<U>
withQueueFactory
in interface ConfigurableStream.SimpleReactConfigurableStream<U>
EagerFutureStream<U> withErrorHandler(java.util.Optional<java.util.function.Consumer<java.lang.Throwable>> errorHandler)
withErrorHandler
in interface ConfigurableStream<U>
withErrorHandler
in interface ConfigurableStream.SimpleReactConfigurableStream<U>
EagerFutureStream<U> withSubscription(Continueable sub)
withSubscription
in interface ConfigurableStream<U>
withSubscription
in interface ConfigurableStream.SimpleReactConfigurableStream<U>
default <R> EagerFutureStream<R> thenSync(java.util.function.Function<U,R> fn)
thenSync
in interface EagerToQueue<U>
thenSync
in interface SimpleReactStream<U>
default EagerFutureStream<U> sync()
sync
in interface FutureStream<U>
sync
in interface SimpleReactStream<U>
default EagerFutureStream<U> async()
async
in interface FutureStream<U>
async
in interface SimpleReactStream<U>
default LazyFutureStream<U> convertToLazyStream()
default <R> EagerFutureStream<R> map(java.util.function.Function<? super U,? extends R> mapper)
map
in interface FutureStream<U>
map
in interface org.jooq.lambda.Seq<U>
map
in interface java.util.stream.Stream<U>
default EagerFutureStream<java.util.Collection<U>> chunkSinceLastRead()
chunkSinceLastRead
in interface FutureStream<U>
default <K> java.util.Map<K,EagerFutureStream<U>> shard(java.util.Map<K,Queue<U>> shards, java.util.function.Function<U,K> sharder)
Queue<Integer> evenQueue = QueueFactories.unboundedQueue().build();
Queue<Integer> oddQueue = QueueFactories.unboundedQueue().build()
EagerFutureStream.of(10,20,25,30,41,43)
.shard(ImmutableMap.of("even",evenQueue,"odd",oddQueue),element-> element==0? "even" : "odd");
Stream<Integer> evenStream = evenQueue.stream();
results in 2 Streams "even": 10,20,30 "odd" : 25,41,43shard
in interface FutureStream<U>
shards
- Map of Queue's keyed by shard identifiersharder
- Function to split split incoming elements into shardsdefault void cancel()
cancel
in interface FutureStream<U>
void cancelOriginal()
default EagerFutureStream<U> debounce(long time, java.util.concurrent.TimeUnit unit)
EagerFutureStream.of(1,2,3,4,5,6)
.debounce(1000,TimeUnit.SECONDS)
.toList();
//[1] - as all events will be passed through in < 1000 seconds, only 1 will be allowed
debounce
in interface FutureStream<U>
time
- Time from which to accept only one elementunit
- Time unit for specified timedefault <T> EagerFutureStream<U> skipUntil(FutureStream<T> s)
EagerFutureStream.react(()->loadNext(1),()->loadNext(2),()->3,()->4,()->loadNext(4))
.skipUntil(EagerFutureStream.react(()->loadFromDb()))
.toList();
skipUntil
in interface FutureStream<U>
s
- Stream that will start the emission of values from this streamdefault <T> EagerFutureStream<U> takeUntil(FutureStream<T> s)
EagerFutureStream.react(()->loadNext(1),()->loadNext(2),()->3,()->4,()->loadNext(4))
.takeUntil(EagerFutureStream.react(()->loadFromDb()))
.toList();
takeUntil
in interface FutureStream<U>
s
- Stream that will stop the emission of values from this streamdefault EagerFutureStream<U> control(java.util.function.Function<java.util.function.Supplier<U>,java.util.function.Supplier<U>> fn)
control
in interface FutureStream<U>
fn
- Function takes a supplier, which can be used repeatedly to get
the next value from the Stream. If there are no more values, a
ClosedQueueException will be thrown. This function should
return a Supplier which returns the desired result for the
next element (or just the next element).default EagerFutureStream<java.util.Collection<U>> batch(java.util.function.Function<java.util.function.Supplier<U>,java.util.function.Supplier<java.util.Collection<U>>> fn)
batch
in interface FutureStream<U>
fn
- Function takes a supplier, which can be used repeatedly to get
the next value from the Stream. If there are no more values, a
ClosedQueueException will be thrown. This function should
return a Supplier which creates a collection of the batched
valuesdefault EagerFutureStream<java.util.Collection<U>> batchBySize(int size)
EagerFutureStream.of(1,2,3,4,5,6)
.batchBySize(3)
.toList();
// [[1,2,3],[4,5,6]]
batchBySize
in interface FutureStream<U>
size
- Size of lists elements should be batched intodefault EagerFutureStream<java.util.Collection<U>> batchBySize(int size, java.util.function.Supplier<java.util.Collection<U>> supplier)
EagerFutureStream.of(1,1,1,1,1,1)
.batchBySize(3,()->new TreeSet<>())
.toList()
//[[1],[1]]
batchBySize
in interface FutureStream<U>
size
- Size of batchsupplier
- Create the batch holding collectiondefault EagerFutureStream<U> jitter(long jitterInNanos)
EagerFutureStream.parallelCommonBuilder()
.of(IntStream.range(0, 100))
.map(it -> it*100)
.jitter(10l)
.peek(System.out::println)
.block();
jitter
in interface FutureStream<U>
jitterInNanos
- Max number of nanos for jitter (random number less than this
will be selected)/default EagerFutureStream<U> fixedDelay(long time, java.util.concurrent.TimeUnit unit)
EagerFutureStream.of(1,2,3,4)
.fixedDelay(1,TimeUnit.hours);
Will emit 1 on start, then 2 after an hour, 3 after 2 hours and so on.
However all 4 numbers will be populated in the Stream immediately.
LazyFutureStream.of(1,2,3,4)
.withQueueFactories(QueueFactories.boundedQueue(1))
.fixedDelay(1,TimeUnit.hours);
Will populate each number in the Stream an hour apart.fixedDelay
in interface FutureStream<U>
time
- amount of time between emissionsunit
- TimeUnit for emissionsdefault EagerFutureStream<U> onePer(long time, java.util.concurrent.TimeUnit unit)
EagerFutureStream.of(1,2,3,4,5,6)
.onePer(1000,TimeUnit.NANOSECONDS)
.toList();
onePer
in interface FutureStream<U>
time
- Frequency period of element emissionunit
- Time unit for frequency perioddefault FutureStream<U> xPer(int x, long time, java.util.concurrent.TimeUnit unit)
EagerFutureStream.of(1,2,3,4,5,6)
.xPer(6,100000000,TimeUnit.NANOSECONDS)
.toList();
xPer
in interface FutureStream<U>
x
- Number of allowable emissions per time periodtime
- Frequency time periodunit
- Frequency time unitdefault EagerFutureStream<java.util.Collection<U>> batchByTime(long time, java.util.concurrent.TimeUnit unit)
EagerFutureStream.of(1,2,3,4,5,6)
.batchByTime(15000,TimeUnit.MICROSECONDS);
batchByTime
in interface FutureStream<U>
time
- Time period during which all elements should be collectedunit
- Time unit during which all elements should be collecteddefault EagerFutureStream<java.util.Collection<U>> batchByTime(long time, java.util.concurrent.TimeUnit unit, java.util.function.Supplier<java.util.Collection<U>> factory)
EagerFutureStream.of(1,1,1,1,1,1)
.batchByTime(1500,TimeUnit.MICROSECONDS,()-> new TreeSet<>())
.toList()
batchByTime
in interface FutureStream<U>
time
- Time period during which all elements should be collectedunit
- Time unit during which all elements should be collectedfactory
- Instantiates the collections used in the batchingdefault <T> EagerFutureStream<org.jooq.lambda.tuple.Tuple2<U,T>> combineLatest(FutureStream<T> s)
EagerFutureStream.of(1,2,3,4,5,6)
.combineLatest(react(()->3,()->value()))
.toList();
combineLatest
in interface FutureStream<U>
s
- Stream to merge withdefault <T> EagerFutureStream<org.jooq.lambda.tuple.Tuple2<U,T>> withLatest(FutureStream<T> s)
EagerFutureStream.of(1,2,3,4,5,6)
.withLatest(of(30,40,50,60,70,80,90,100,110,120,140))
.toList();
withLatest
in interface FutureStream<U>
s
- Stream to merge withstatic <U> EagerFutureStream<U> firstOf(EagerFutureStream<U>... futureStreams)
EagerFutureStream.firstOf(stream1, stream2, stream3)
.peek(System.out::println)
.map(this::saveData)
.block();
futureStreams
- Streams to racedefault <R> EagerFutureStream<R> then(java.util.function.Function<U,R> fn, java.util.concurrent.Executor service)
then
in interface SimpleReactStream<U>
default EagerFutureStream<U> doOnEach(java.util.function.Function<U,U> fn)
doOnEach
in interface SimpleReactStream<U>
fn
- Function to be applied to each completablefuture on completiondefault <R> EagerFutureStream<R> then(java.util.function.Function<U,R> fn)
SimpleReactStream
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 FutureStream<U>
then
in interface SimpleReactStream<U>
fn
- Function to be applied to the results of the currently active
event tasksdefault EagerFutureStream<U> merge(SimpleReactStream<U> s)
SimpleReactStream
merge
in interface FutureStream<U>
merge
in interface SimpleReactStream<U>
s
- Reactive stage builder to merge withdefault EagerFutureStream<U> onFail(java.util.function.Function<? extends SimpleReactFailedStageException,U> fn)
SimpleReactStream
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 FutureStream<U>
onFail
in interface SimpleReactStream<U>
fn
- Recovery function, the exception is input, and the recovery
value is outputdefault EagerFutureStream<U> onFail(java.lang.Class<? extends java.lang.Throwable> exceptionClass, java.util.function.Function<? extends SimpleReactFailedStageException,U> fn)
SimpleReactStream
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 FutureStream<U>
onFail
in interface SimpleReactStream<U>
exceptionClass
- Class of exceptions to recover fromfn
- Recovery functiondefault EagerFutureStream<U> capture(java.util.function.Consumer<? extends java.lang.Throwable> errorHandler)
SimpleReactStream
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 FutureStream<U>
capture
in interface SimpleReactStream<U>
errorHandler
- A consumer that recieves and deals with an unrecoverable error
in the dataflowdefault <T,R> EagerFutureStream<R> allOf(java.util.function.Function<java.util.List<T>,R> fn)
SimpleReactStream
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.allOf
in interface FutureStream<U>
allOf
in interface SimpleReactStream<U>
fn
- Function that recieves the results of all currently active
tasks as inputdefault EagerFutureStream<U> peek(java.util.function.Consumer<? super U> consumer)
SimpleReactStream
peek
in interface FutureStream<U>
peek
in interface org.jooq.lambda.Seq<U>
peek
in interface SimpleReactStream<U>
peek
in interface java.util.stream.Stream<U>
consumer
- That will recieve current resultsdefault EagerFutureStream<U> filter(java.util.function.Predicate<? super U> p)
SimpleReactStream
filter
in interface FutureStream<U>
filter
in interface org.jooq.lambda.Seq<U>
filter
in interface SimpleReactStream<U>
filter
in interface java.util.stream.Stream<U>
p
- Predicate that will be used to filter elements from the
dataflowdefault <R> EagerFutureStream<R> flatMap(java.util.function.Function<? super U,? extends java.util.stream.Stream<? extends R>> flatFn)
SimpleReactStream
flatMap
in interface FutureStream<U>
flatMap
in interface org.jooq.lambda.Seq<U>
flatMap
in interface SimpleReactStream<U>
flatMap
in interface java.util.stream.Stream<U>
flatFn
- Function that coverts a value (e.g. a Collection) into a Streamdefault <R> EagerFutureStream<R> retry(java.util.function.Function<U,R> fn)
SimpleReactStream
retry
in interface FutureStream<U>
retry
in interface SimpleReactStream<U>
fn
- Function that will be executed and retried on failuredefault <T,R> EagerFutureStream<R> allOf(java.util.stream.Collector collector, java.util.function.Function<T,R> fn)
allOf
in interface EagerToQueue<U>
allOf
in interface FutureStream<U>
allOf
in interface SimpleReactStream<U>
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 inputdefault <R> EagerFutureStream<R> anyOf(java.util.function.Function<U,R> fn)
SimpleReactStream
anyOf
in interface FutureStream<U>
anyOf
in interface SimpleReactStream<U>
fn
- Function to apply when any of the previous events completeEagerFutureStream<U> withLastActive(StreamWrapper streamWrapper)
withLastActive
in interface ConfigurableStream<U>
withLastActive
in interface ConfigurableStream.SimpleReactConfigurableStream<U>
default <R> EagerFutureStream<R> fromStream(java.util.stream.Stream<R> stream)
fromStream
in interface FutureStream<U>
fromStream
in interface SimpleReactStream<U>
default <R> EagerFutureStream<R> fromStreamOfFutures(java.util.stream.Stream<java.util.concurrent.CompletableFuture<R>> stream)
SimpleReactStream
fromStreamOfFutures
in interface FutureStream<U>
fromStreamOfFutures
in interface SimpleReactStream<U>
stream
- JDK Stream to construct new SimpleReactStream fromdefault EagerFutureStream<U> limit(long maxSize)
default EagerFutureStream<U> limitFutures(long maxSize)
EagerFutureStream.of(()>loadSlow(),()>loadMedium(),()>loadFast())
.limitFutures(2)
//[loadSlow, loadMedium]
maxSize
- The size of the subsequent Streamdefault EagerFutureStream<U> skip(long n)
default EagerFutureStream<U> skipFutures(long n)
EagerFutureStream.of(()>loadSlow(),()>loadMedium(),()>loadFast())
.skip(2)
//[loadFast]
n
- default <U> EagerFutureStream<U> cast(java.lang.Class<U> type)
cast
in interface FutureStream<U>
cast
in interface org.jooq.lambda.Seq<U>
default <U> EagerFutureStream<U> ofType(java.lang.Class<U> type)
EagerFutureStream.of(1, "a", 2, "b", 3).ofType(Integer.class) gives a Stream of (1,2,3) EagerFutureStream.of(1, "a", 2, "b", 3).ofType(String.class) gives a Stream of ("a","b")
ofType
in interface FutureStream<U>
ofType
in interface org.jooq.lambda.Seq<U>
FutureStream.ofType(java.lang.Class)
default EagerFutureStream<U> concat(java.util.stream.Stream<U> other)
// (1, 2, 3, 4, 5, 6)
EagerFutureStream.of(1, 2,3).concat(Stream.of(4, 5, 6))
concat
in interface org.jooq.lambda.Seq<U>
Seq.concat(Stream[])
default FutureStream<U> concat(SimpleReactStream<U> other)
// (1, 2, 3, 4, 5, 6)
EagerFutureStream.of(1, 2,3).concat(EagerFutureStream.of(4, 5, 6))
Seq.concat(Stream[])
default EagerFutureStream<U> concat(U other)
// (1, 2, 3, 4) EagerFutureStream.of(1, 2, 3).concat(4)
concat
in interface org.jooq.lambda.Seq<U>
Seq.concat(Stream[])
default EagerFutureStream<U> concat(U... other)
// (1, 2, 3, 4, 5, 6) EagerFutureStream.of(1, 2, 3).concat(4, 5, 6)
concat
in interface org.jooq.lambda.Seq<U>
Seq.concat(Stream[])
default EagerFutureStream<U> sliceFutures(long from, long to)
// (4, 5) EagerFutureStream.of(1, 2, 3, 4, 5, 6).sliceFutures(3, 5)
slice(long, long)
default EagerFutureStream<U> slice(long from, long to)
// (4, 5) EagerFutureStream.of(1, 2, 3, 4, 5, 6).slice(3, 5)
slice
in interface FutureStream<U>
slice
in interface org.jooq.lambda.Seq<U>
Seq.slice(Stream, long, long)
default <R> EagerFutureStream<org.jooq.lambda.tuple.Tuple2<U,R>> zip(org.jooq.lambda.Seq<R> other)
// (tuple(1, "a"), tuple(2, "b"), tuple(3, "c")) EagerFutureStream.of(1,
2, 3).zip(EagerFutureStream.of("a", "b", "c"))
zip
in interface org.jooq.lambda.Seq<U>
Seq.zip(Stream, Stream)
default <T,R> EagerFutureStream<R> zip(org.jooq.lambda.Seq<T> other, java.util.function.BiFunction<U,T,R> zipper)
BiFunction
to produce resulting
values.
("1:a", "2:b", "3:c")
EagerFutureStream.of(1, 2,3).zip(EagerFutureStream.of("a", "b", "c"), (i, s) > i + ":" + s)
zip
in interface org.jooq.lambda.Seq<U>
zip(Seq, BiFunction)
default <R> EagerFutureStream<org.jooq.lambda.tuple.Tuple2<U,R>> zipFutures(java.util.stream.Stream<R> other)
zipFutures
in interface FutureStream<U>
other
- default <R> EagerFutureStream<org.jooq.lambda.tuple.Tuple2<U,R>> zipFutures(FutureStream<R> other)
zipFutures
in interface FutureStream<U>
other
- Another FutureStream to zip Futures withdefault EagerFutureStream<org.jooq.lambda.tuple.Tuple2<U,java.lang.Long>> zipFuturesWithIndex()
EagerFutureStream.react(()->takesALotOfTime(),()->veryQuick()).zipWithIndex();
[["takesALotOfTime",0],["veryQuick",1]]
Where as with standard zipWithIndex you would get a new Stream ordered by completion
[["veryQuick",0],["takesALotOfTime",1]]
Seq.zipWithIndex(Stream)
default EagerFutureStream<org.jooq.lambda.tuple.Tuple2<U,java.lang.Long>> zipWithIndex()
// (tuple("a", 0), tuple("b", 1), tuple("c", 2))
EagerFutureStream.of("a", "b", "c").zipWithIndex()
zipWithIndex
in interface org.jooq.lambda.Seq<U>
Seq.zipWithIndex(Stream)
default <T> EagerFutureStream<T> scanLeft(T seed, java.util.function.BiFunction<T,? super U,T> function)
// ("", "a", "ab", "abc") EagerFutureStream.of("a", "b",
"c").scanLeft("", (u, t) > u + t)
scanLeft
in interface org.jooq.lambda.Seq<U>
default <R> EagerFutureStream<R> scanRight(R seed, java.util.function.BiFunction<? super U,R,R> function)
// ("", "c", "cb", "cba") EagerFutureStream.of("a", "b",
"c").scanRight("", (t, u) > u + t)
scanRight
in interface org.jooq.lambda.Seq<U>
default EagerFutureStream<U> reverse()
// (3, 2, 1) EagerFutureStream.of(1, 2, 3).reverse()
reverse
in interface FutureStream<U>
reverse
in interface org.jooq.lambda.Seq<U>
default EagerFutureStream<U> shuffle()
// e.g. (2, 3, 1) EagerFutureStream.of(1, 2, 3).shuffle()
shuffle
in interface org.jooq.lambda.Seq<U>
default EagerFutureStream<U> shuffle(java.util.Random random)
// e.g. (2, 3, 1) EagerFutureStream.of(1, 2, 3).shuffle(new Random())
shuffle
in interface org.jooq.lambda.Seq<U>
default EagerFutureStream<U> skipWhile(java.util.function.Predicate<? super U> predicate)
// (3, 4, 5) EagerFutureStream.of(1, 2, 3, 4, 5).skipWhile(i > i <
3)
skipWhile
in interface org.jooq.lambda.Seq<U>
Seq.skipWhile(Stream, Predicate)
default EagerFutureStream<U> skipUntil(java.util.function.Predicate<? super U> predicate)
// (3, 4, 5) EagerFutureStream.of(1, 2, 3, 4, 5).skipUntil(i > i == 3)
skipUntil
in interface org.jooq.lambda.Seq<U>
Seq.skipUntil(Stream, Predicate)
default EagerFutureStream<U> limitWhile(java.util.function.Predicate<? super U> predicate)
// (1, 2) EagerFutureStream.of(1, 2, 3, 4, 5).limitWhile(i -> i <
3)
limitWhile
in interface org.jooq.lambda.Seq<U>
Seq.limitWhile(Stream, Predicate)
default EagerFutureStream<U> limitUntil(java.util.function.Predicate<? super U> predicate)
// (1, 2) EagerFutureStream.of(1, 2, 3, 4, 5).limitUntil(i > i == 3)
limitUntil
in interface org.jooq.lambda.Seq<U>
Seq.limitUntil(Stream, Predicate)
default EagerFutureStream<U> intersperse(U value)
// (1, 0, 2, 0, 3, 0, 4) EagerFutureStream.of(1, 2, 3, 4).intersperse(0)
intersperse
in interface FutureStream<U>
intersperse
in interface org.jooq.lambda.Seq<U>
Seq.intersperse(Stream, Object)
static <U> EagerFutureStream<U> parallel(U... array)
array
- Values to react todefault EagerFutureStream<U> distinct()
default org.jooq.lambda.tuple.Tuple2<EagerFutureStream<U>,EagerFutureStream<U>> duplicateFutures()
EagerFutureStream.of(1, 2, 3).duplicate()
results in
tuple((1,2,3),(1,2,3))
Care should be taken not to use this method with infinite streams!duplicate()
default org.jooq.lambda.tuple.Tuple2<org.jooq.lambda.Seq<U>,org.jooq.lambda.Seq<U>> duplicate()
EagerFutureStream.of(1, 2, 3).duplicate()
results in
tuple((1,2,3),(1,2,3))
Care should be taken not to use this method with infinite streams!duplicate
in interface org.jooq.lambda.Seq<U>
duplicate()
default org.jooq.lambda.tuple.Tuple2<org.jooq.lambda.Seq<U>,org.jooq.lambda.Seq<U>> partition(java.util.function.Predicate<? super U> predicate)
// tuple((1, 3, 5), (2, 4, 6))
EagerFutureStream.of(1, 2, 3, 4, 5,6).partition(i -> i % 2 != 0)
partition
in interface org.jooq.lambda.Seq<U>
Seq.partition(Stream, Predicate)
default org.jooq.lambda.tuple.Tuple2<EagerFutureStream<U>,EagerFutureStream<U>> partitionFutureStream(java.util.function.Predicate<? super U> predicate)
EagerFutureStream.of(1, 2, 3, 4, 5, 6).partition(i -> i % 2 != 0)
results in
tuple((1, 3, 5), (2, 4, 6))
predicate
- Predicate to split Streampartition(Predicate)
default org.jooq.lambda.tuple.Tuple2<EagerFutureStream<U>,EagerFutureStream<U>> splitAtFutures(long position)
// tuple((1, 2, 3), (4, 5, 6))
EagerFutureStream.of(1, 2, 3, 4, 5,6).splitAt(3)
Seq.splitAt(Stream, long)
default org.jooq.lambda.tuple.Tuple2<org.jooq.lambda.Seq<U>,org.jooq.lambda.Seq<U>> splitAt(long position)
EagerFutureStream.of(1, 2, 3, 4, 5, 6).splitAt(3)
results in tuple((1, 2, 3), (4, 5, 6))
splitAt
in interface org.jooq.lambda.Seq<U>
splitAt(long)
default org.jooq.lambda.tuple.Tuple2<EagerFutureStream<U>,EagerFutureStream<U>> splitAtFutureStream(long position)
EagerFutureStream.of(1, 2, 3, 4, 5, 6).splitAtFutureStream(3)
results in tuple((1, 2, 3), (4, 5, 6))
splitAt(long)
default <R> EagerFutureStream<R> fromListCompletableFuture(java.util.List<java.util.concurrent.CompletableFuture<R>> list)
fromListCompletableFuture
in interface SimpleReactStream<U>
default org.jooq.lambda.tuple.Tuple2<java.util.Optional<U>,org.jooq.lambda.Seq<U>> splitAtHead()
// tuple(1, (2, 3, 4, 5, 6))
EagerFutureStream.of(1, 2, 3, 4, 5, 6).splitHead(3)
splitAtHead
in interface org.jooq.lambda.Seq<U>
Seq.splitAt(Stream, long)
default org.jooq.lambda.tuple.Tuple2<java.util.Optional<U>,EagerFutureStream<U>> splitAtHeadFutureStream()
splitAtHead()
static EagerReact parallelBuilder()
parallelBuilder
in interface SimpleReactStream<U>
SimpleReact.SimpleReact()
static EagerReact parallelBuilder(int parallelism)
parallelBuilder
in interface SimpleReactStream<U>
parallelism
- Number of threads task executor should havestatic EagerReact parallelCommonBuilder()
parallelCommonBuilder
in interface SimpleReactStream<U>
see RetryBuilder#getDefaultInstance()
static EagerReact sequentialBuilder()
sequentialBuilder
in interface SimpleReactStream<U>
static EagerReact sequentialCommonBuilder()
sequentialCommonBuilder
in interface SimpleReactStream<U>
static <T> EagerFutureStream<T> react(java.util.function.Supplier<T> value)
react
in interface SimpleReactStream<U>
Stream.of(Object)
@SafeVarargs static <T> EagerFutureStream<T> react(java.util.function.Supplier<T>... values)
react
in interface SimpleReactStream<U>
Stream.of(Object[])
static <T> EagerFutureStream<T> of(T value)
of
in interface org.jooq.lambda.Seq<U>
of
in interface SimpleReactStream<U>
of
in interface java.util.stream.Stream<U>
Stream.of(Object)
@SafeVarargs static <T> EagerFutureStream<T> of(T... values)
of
in interface org.jooq.lambda.Seq<U>
of
in interface SimpleReactStream<U>
of
in interface java.util.stream.Stream<U>
Stream.of(Object[])
static <T> EagerFutureStream<T> empty()
empty
in interface org.jooq.lambda.Seq<U>
empty
in interface SimpleReactStream<U>
empty
in interface java.util.stream.Stream<U>
Stream.empty()
static <T> EagerFutureStream<T> of(java.util.stream.Stream<T> stream)
of
in interface org.jooq.lambda.Seq<U>
of
in interface SimpleReactStream<U>
of
in interface java.util.stream.Stream<U>
Stream.of(Object)
static <T> EagerFutureStream<T> ofIterable(java.lang.Iterable<T> iterable)
ofIterable
in interface SimpleReactStream<U>
static <T> EagerFutureStream<T> of(java.util.Iterator<T> iterator)
of
in interface org.jooq.lambda.Seq<U>
of
in interface SimpleReactStream<U>
of
in interface java.util.stream.Stream<U>
Stream.of(Object)
default java.util.stream.Stream<U> stream()
stream
in interface FutureStream<U>
stream
in interface org.jooq.lambda.Seq<U>
default EagerFutureStream<U> parallel()
default EagerFutureStream<U> sequential()
sequential
in interface java.util.stream.BaseStream<U,java.util.stream.Stream<U>>
sequential
in interface FutureStream<U>
sequential
in interface org.jooq.lambda.Seq<U>
default EagerFutureStream<U> unordered()
default EagerFutureStream<U> onClose(java.lang.Runnable closeHandler)
default EagerFutureStream<U> sorted()
sorted
in interface FutureStream<U>
sorted
in interface org.jooq.lambda.Seq<U>
sorted
in interface java.util.stream.Stream<U>
default EagerFutureStream<U> sorted(java.util.Comparator<? super U> comparator)
sorted
in interface FutureStream<U>
sorted
in interface org.jooq.lambda.Seq<U>
sorted
in interface java.util.stream.Stream<U>
default EagerFutureStream<U> self(java.util.function.Consumer<FutureStream<U>> consumer)
self
in interface FutureStream<U>
consumer
- Consumer that will recieve current stage