T
- The Payload type@ProviderType public interface PushStream<T> extends AutoCloseable
Modifier and Type | Method and Description |
---|---|
PushStream<T> |
adjustBackPressure(LongUnaryOperator adjustment)
Changes the back-pressure propagated by this pipeline stage.
|
PushStream<T> |
adjustBackPressure(ToLongBiFunction<T,Long> adjustment)
Changes the back-pressure propagated by this pipeline stage.
|
Promise<Boolean> |
allMatch(Predicate<? super T> predicate)
Closes the channel and resolve the promise with false when the predicate
does not matches a pay load.
|
Promise<Boolean> |
anyMatch(Predicate<? super T> predicate)
Close the channel and resolve the promise with true when the predicate
matches a payload.
|
<R> PushStream<R> |
asyncMap(int n,
int delay,
Function<? super T,Promise<? extends R>> mapper)
Asynchronously map the payload values.
|
PushStream<T> |
buffer()
Buffer the events in a queue using default values for the queue size and
other behaviors.
|
<U extends BlockingQueue<PushEvent<? extends T>>> |
buildBuffer()
Build a buffer to enqueue events in a queue using custom values for the
queue size and other behaviors.
|
void |
close()
Close this PushStream by sending an event of type
PushEvent.EventType.CLOSE downstream. |
<R> PushStream<R> |
coalesce(Function<? super T,Optional<R>> f)
Coalesces a number of events into a new type of event.
|
<R> PushStream<R> |
coalesce(int count,
Function<Collection<T>,R> f)
Coalesces a number of events into a new type of event.
|
<R> PushStream<R> |
coalesce(IntSupplier count,
Function<Collection<T>,R> f)
Coalesces a number of events into a new type of event.
|
<R,A> Promise<R> |
collect(Collector<? super T,A,R> collector)
See Stream.
|
Promise<Long> |
count()
See Stream.
|
PushStream<T> |
distinct()
Remove any duplicates.
|
PushStream<T> |
filter(Predicate<? super T> predicate)
Only pass events downstream when the predicate tests true.
|
Promise<Optional<T>> |
findAny()
Close the channel and resolve the promise with the first element.
|
Promise<Optional<T>> |
findFirst()
Close the channel and resolve the promise with the first element.
|
<R> PushStream<R> |
flatMap(Function<? super T,? extends PushStream<? extends R>> mapper)
Flat map the payload value (turn one event into 0..n events of
potentially another type).
|
Promise<Void> |
forEach(Consumer<? super T> action)
Execute the action for each event received until the channel is closed.
|
Promise<Long> |
forEachEvent(PushEventConsumer<? super T> action)
Pass on each event to another consumer until the stream is closed.
|
PushStream<T> |
fork(int n,
int delay,
Executor e)
Execute the downstream events in up to n background threads.
|
PushStream<T> |
limit(Duration maxTime)
Automatically close the channel after the given amount of time has
elapsed.
|
PushStream<T> |
limit(long maxSize)
Automatically close the channel after the maxSize number of elements is
received.
|
<R> PushStream<R> |
map(Function<? super T,? extends R> mapper)
Map a payload value.
|
Promise<Optional<T>> |
max(Comparator<? super T> comparator)
See Stream.
|
PushStream<T> |
merge(PushEventSource<? extends T> source)
Merge in the events from another source.
|
PushStream<T> |
merge(PushStream<? extends T> source)
Merge in the events from another PushStream.
|
Promise<Optional<T>> |
min(Comparator<? super T> comparator)
See Stream.
|
Promise<Boolean> |
noneMatch(Predicate<? super T> predicate)
Closes the channel and resolve the promise with false when the predicate
matches any pay load.
|
PushStream<T> |
onClose(Runnable closeHandler)
Provide a handler that must be run after the PushStream is closed.
|
PushStream<T> |
onError(Consumer<? super Throwable> errorHandler)
Provide a handler that will be called if the PushStream is closed with an
event of type
PushEvent.EventType.ERROR . |
Promise<Optional<T>> |
reduce(BinaryOperator<T> accumulator)
Standard reduce without identity, so the return is an Optional.
|
Promise<T> |
reduce(T identity,
BinaryOperator<T> accumulator)
Standard reduce, see Stream.
|
<U> Promise<U> |
reduce(U identity,
BiFunction<U,? super T,U> accumulator,
BinaryOperator<U> combiner)
Standard reduce with identity, accumulator and combiner.
|
PushStream<T> |
sequential()
Ensure that any events are delivered sequentially.
|
PushStream<T> |
skip(long n)
Skip a number of events in the channel.
|
PushStream<T> |
sorted()
Sorted the elements, assuming that T extends Comparable.
|
PushStream<T> |
sorted(Comparator<? super T> comparator)
Sorted the elements with the given comparator.
|
PushStream<T>[] |
split(Predicate<? super T>... predicates)
Split the events to different streams based on a predicate.
|
PushStream<T> |
timeout(Duration idleTime)
Automatically fail the channel if no events are received for the
indicated length of time.
|
Promise<Object[]> |
toArray()
Collect the payloads in an Object array after the channel is closed.
|
<A> Promise<A[]> |
toArray(IntFunction<A[]> generator)
Collect the payloads in an Object array after the channel is closed.
|
<R> PushStream<R> |
window(Duration d,
Executor executor,
Function<Collection<T>,R> f)
Buffers a number of events over a fixed time interval and then forwards
the events to an accumulator function.
|
<R> PushStream<R> |
window(Duration d,
Function<Collection<T>,R> f)
Buffers a number of events over a fixed time interval and then forwards
the events to an accumulator function.
|
<R> PushStream<R> |
window(Supplier<Duration> timeSupplier,
IntSupplier maxEvents,
BiFunction<Long,Collection<T>,R> f)
Buffers a number of events over a variable time interval and then
forwards the events to an accumulator function.
|
<R> PushStream<R> |
window(Supplier<Duration> timeSupplier,
IntSupplier maxEvents,
Executor executor,
BiFunction<Long,Collection<T>,R> f)
Buffers a number of events over a variable time interval and then
forwards the events to an accumulator function.
|
void close()
PushEvent.EventType.CLOSE
downstream. Closing a PushStream is a
safe operation that will not throw an Exception.
Calling close()
on a closed PushStream has no effect.
close
in interface AutoCloseable
PushStream<T> onClose(Runnable closeHandler)
closeHandler
- Will be called on closePushStream<T> onError(Consumer<? super Throwable> errorHandler)
PushEvent.EventType.ERROR
. The error value from
this event will be passed to the callback function after the PushStream
is closed. This handler will run after any downstream operations have
processed the error event but before any upstream operations have
processed the error event.errorHandler
- Will be called on an error eventPushStream<T> filter(Predicate<? super T> predicate)
predicate
- The predicate that is tested (not null)<R> PushStream<R> map(Function<? super T,? extends R> mapper)
mapper
- The map function<R> PushStream<R> asyncMap(int n, int delay, Function<? super T,Promise<? extends R>> mapper)
The PushStream limits the number of concurrently running mapping operations, and returns back pressure based on the number of existing queued operations.
n
- number of simultaneous promises to usedelay
- Nr of ms/promise that is queued back pressuremapper
- The mapping functionIllegalArgumentException
- if the number of threads is < 1 or
the delay is < 0NullPointerException
- if the mapper is null<R> PushStream<R> flatMap(Function<? super T,? extends PushStream<? extends R>> mapper)
mapper
- The flat map functionPushStream<T> distinct()
PushStream<T> sorted()
PushStream<T> sorted(Comparator<? super T> comparator)
comparator
- PushStream<T> limit(long maxSize)
maxSize
- Maximum number of elements has been receivedPushStream<T> limit(Duration maxTime)
maxTime
- The maximum time that the stream should remain openPushStream<T> timeout(Duration idleTime)
TimeoutException
will be sent.idleTime
- The length of time that the stream should remain open
when no events are being received.PushStream<T> skip(long n)
n
- number of elements to skipIllegalArgumentException
- if the number of events to skip is
negativePushStream<T> fork(int n, int delay, Executor e)
n
- number of simultaneous background threads to usedelay
- Nr of ms/thread that is queued back pressuree
- an executor to use for the background threads.IllegalArgumentException
- if the number of threads is < 1 or
the delay is < 0NullPointerException
- if the Executor is nullPushStream<T> buffer()
Buffers are useful for "bursty" event sources which produce a number of
events close together, then none for some time. These bursts can
sometimes overwhelm downstream event consumers. Buffering will not,
however, protect downstream components from a source which produces
events faster than they can be consumed. For fast sources
filter(Predicate)
and coalesce(int, Function)
fork(int, int, Executor)
are better choices.
<U extends BlockingQueue<PushEvent<? extends T>>> PushStreamBuilder<T,U> buildBuffer()
Buffers are useful for "bursty" event sources which produce a number of
events close together, then none for some time. These bursts can
sometimes overwhelm downstream event consumers. Buffering will not,
however, protect downstream components from a source which produces
events faster than they can be consumed. For fast sources
filter(Predicate)
and coalesce(int, Function)
fork(int, int, Executor)
are better choices.
Buffers are also useful as "circuit breakers" in the pipeline. If a
QueuePolicyOption.FAIL
is used then a full buffer will trigger
the stream to close, preventing an event storm from reaching the client.
PushStream<T> merge(PushEventSource<? extends T> source)
source
- The source to merge in.PushStream<T> merge(PushStream<? extends T> source)
source
- The source to merge in.PushStream<T>[] split(Predicate<? super T>... predicates)
This method differs from other methods of PushStream in three significant ways:
predicates
- the predicates to testPushStream<T> sequential()
<R> PushStream<R> coalesce(Function<? super T,Optional<R>> f)
f
- <R> PushStream<R> coalesce(int count, Function<Collection<T>,R> f)
count
- f
- <R> PushStream<R> coalesce(IntSupplier count, Function<Collection<T>,R> f)
count
- f
- <R> PushStream<R> window(Duration d, Function<Collection<T>,R> f)
PushStream
.
d
- f
- <R> PushStream<R> window(Duration d, Executor executor, Function<Collection<T>,R> f)
d
- executor
- f
- <R> PushStream<R> window(Supplier<Duration> timeSupplier, IntSupplier maxEvents, BiFunction<Long,Collection<T>,R> f)
PushStream
.
timeSupplier
- maxEvents
- f
- <R> PushStream<R> window(Supplier<Duration> timeSupplier, IntSupplier maxEvents, Executor executor, BiFunction<Long,Collection<T>,R> f)
PushStream
.
timeSupplier
- maxEvents
- executor
- f
- PushStream<T> adjustBackPressure(LongUnaryOperator adjustment)
The supplied function receives the back pressure returned by the next pipeline stage and returns the back pressure that should be returned by this stage. This function will not be called if the previous pipeline stage returns negative back pressure.
adjustment
- PushStream<T> adjustBackPressure(ToLongBiFunction<T,Long> adjustment)
The supplied function receives the data object passed to the next pipeline stage and the back pressure that was returned by that stage when accepting it. The function returns the back pressure that should be returned by this stage. This function will not be called if the previous pipeline stage returns negative back pressure.
adjustment
- Promise<Void> forEach(Consumer<? super T> action)
This is a terminal operation
action
- The action to performPromise<Object[]> toArray()
This is a terminal operation
<A> Promise<A[]> toArray(IntFunction<A[]> generator)
This is a terminal operation
A
- The element type of the resulting array.generator
- A function which returns an array into which the
payloads are stored.Promise<T> reduce(T identity, BinaryOperator<T> accumulator)
This is a terminal operation
identity
- The identity/begin valueaccumulator
- The accumulatorPromise<Optional<T>> reduce(BinaryOperator<T> accumulator)
This is a terminal operation
accumulator
- The accumulator<U> Promise<U> reduce(U identity, BiFunction<U,? super T,U> accumulator, BinaryOperator<U> combiner)
This is a terminal operation
identity
- accumulator
- combiner
- combines two U's into one U (for example, combine two
lists)<R,A> Promise<R> collect(Collector<? super T,A,R> collector)
This is a terminal operation
collector
- Promise<Optional<T>> min(Comparator<? super T> comparator)
This is a terminal operation
comparator
- Promise<Optional<T>> max(Comparator<? super T> comparator)
This is a terminal operation
comparator
- Promise<Long> count()
This is a terminal operation
Promise<Boolean> anyMatch(Predicate<? super T> predicate)
This is a short circuiting terminal operation
predicate
- Promise<Boolean> allMatch(Predicate<? super T> predicate)
This is a short circuiting terminal operation
predicate
- Promise<Boolean> noneMatch(Predicate<? super T> predicate)
This is a short circuiting terminal operation
predicate
- Promise<Optional<T>> findFirst()
Promise<Optional<T>> findAny()
This is a terminal operation
Promise<Long> forEachEvent(PushEventConsumer<? super T> action)
This is a terminal operation
action
- Copyright © Contributors to the Eclipse Foundation Licensed under the Eclipse Foundation Specification License – v1.0