T
- The Payload type@ProviderType public interface PushStream<T> extends java.lang.AutoCloseable
Modifier and Type | Method and Description |
---|---|
PushStream<T> |
adjustBackPressure(java.util.function.LongUnaryOperator adjustment)
Changes the back-pressure propagated by this pipeline stage.
|
PushStream<T> |
adjustBackPressure(java.util.function.ToLongBiFunction<T,java.lang.Long> adjustment)
Changes the back-pressure propagated by this pipeline stage.
|
Promise<java.lang.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<java.lang.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 java.util.concurrent.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,java.util.Optional<R>> f)
Coalesces a number of events into a new type of event.
|
<R> PushStream<R> |
coalesce(int count,
Function<java.util.Collection<T>,R> f)
Coalesces a number of events into a new type of event.
|
<R> PushStream<R> |
coalesce(java.util.function.IntSupplier count,
Function<java.util.Collection<T>,R> f)
Coalesces a number of events into a new type of event.
|
<R,A> Promise<R> |
collect(java.util.stream.Collector<? super T,A,R> collector)
See Stream.
|
Promise<java.lang.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<java.util.Optional<T>> |
findAny()
Close the channel and resolve the promise with the first element.
|
Promise<java.util.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<java.lang.Void> |
forEach(java.util.function.Consumer<? super T> action)
Execute the action for each event received until the channel is closed.
|
Promise<java.lang.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,
java.util.concurrent.Executor e)
Execute the downstream events in up to n background threads.
|
PushStream<T> |
limit(java.time.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<java.util.Optional<T>> |
max(java.util.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<java.util.Optional<T>> |
min(java.util.Comparator<? super T> comparator)
See Stream.
|
Promise<java.lang.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(java.lang.Runnable closeHandler)
Must be run after the channel is closed.
|
PushStream<T> |
onError(java.util.function.Consumer<? super java.lang.Throwable> closeHandler)
Must be run after the channel is closed.
|
Promise<java.util.Optional<T>> |
reduce(java.util.function.BinaryOperator<T> accumulator)
Standard reduce without identity, so the return is an Optional.
|
Promise<T> |
reduce(T identity,
java.util.function.BinaryOperator<T> accumulator)
Standard reduce, see Stream.
|
<U> Promise<U> |
reduce(U identity,
java.util.function.BiFunction<U,? super T,U> accumulator,
java.util.function.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(java.util.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(java.time.Duration idleTime)
Automatically fail the channel if no events are received for the
indicated length of time.
|
Promise<java.lang.Object[]> |
toArray()
Collect the payloads in an Object array after the channel is closed.
|
<A extends T> |
toArray(java.util.function.IntFunction<A[]> generator)
Collect the payloads in an Object array after the channel is closed.
|
<R> PushStream<R> |
window(java.time.Duration d,
java.util.concurrent.Executor executor,
Function<java.util.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(java.time.Duration d,
Function<java.util.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(java.util.function.Supplier<java.time.Duration> timeSupplier,
java.util.function.IntSupplier maxEvents,
java.util.function.BiFunction<java.lang.Long,java.util.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(java.util.function.Supplier<java.time.Duration> timeSupplier,
java.util.function.IntSupplier maxEvents,
java.util.concurrent.Executor executor,
java.util.function.BiFunction<java.lang.Long,java.util.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 java.lang.AutoCloseable
PushStream<T> onClose(java.lang.Runnable closeHandler)
closeHandler
- Will be called on closePushStream<T> onError(java.util.function.Consumer<? super java.lang.Throwable> closeHandler)
closeHandler
- Will be called on closePushStream<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 functionjava.lang.IllegalArgumentException
- if the number of threads is < 1 or
the delay is < 0java.lang.NullPointerException
- 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(java.util.Comparator<? super T> comparator)
comparator
- PushStream<T> limit(long maxSize)
maxSize
- Maximum number of elements has been receivedPushStream<T> limit(java.time.Duration maxTime)
maxTime
- The maximum time that the stream should remain openPushStream<T> timeout(java.time.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 skipjava.lang.IllegalArgumentException
- if the number of events to skip is
negativePushStream<T> fork(int n, int delay, java.util.concurrent.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.java.lang.IllegalArgumentException
- if the number of threads is < 1 or
the delay is < 0java.lang.NullPointerException
- 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 java.util.concurrent.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,java.util.Optional<R>> f)
f
- <R> PushStream<R> coalesce(int count, Function<java.util.Collection<T>,R> f)
count
- f
- <R> PushStream<R> coalesce(java.util.function.IntSupplier count, Function<java.util.Collection<T>,R> f)
count
- f
- <R> PushStream<R> window(java.time.Duration d, Function<java.util.Collection<T>,R> f)
PushStream
.
d
- f
- <R> PushStream<R> window(java.time.Duration d, java.util.concurrent.Executor executor, Function<java.util.Collection<T>,R> f)
d
- executor
- f
- <R> PushStream<R> window(java.util.function.Supplier<java.time.Duration> timeSupplier, java.util.function.IntSupplier maxEvents, java.util.function.BiFunction<java.lang.Long,java.util.Collection<T>,R> f)
PushStream
.
timeSupplier
- maxEvents
- f
- <R> PushStream<R> window(java.util.function.Supplier<java.time.Duration> timeSupplier, java.util.function.IntSupplier maxEvents, java.util.concurrent.Executor executor, java.util.function.BiFunction<java.lang.Long,java.util.Collection<T>,R> f)
PushStream
.
timeSupplier
- maxEvents
- executor
- f
- PushStream<T> adjustBackPressure(java.util.function.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(java.util.function.ToLongBiFunction<T,java.lang.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<java.lang.Void> forEach(java.util.function.Consumer<? super T> action)
This is a terminal operation
action
- The action to performPromise<java.lang.Object[]> toArray()
This is a terminal operation
<A extends T> Promise<A[]> toArray(java.util.function.IntFunction<A[]> generator)
This is a terminal operation
generator
- Promise<T> reduce(T identity, java.util.function.BinaryOperator<T> accumulator)
This is a terminal operation
identity
- The identity/begin valueaccumulator
- The accumulatorPromise<java.util.Optional<T>> reduce(java.util.function.BinaryOperator<T> accumulator)
This is a terminal operation
accumulator
- The accumulator<U> Promise<U> reduce(U identity, java.util.function.BiFunction<U,? super T,U> accumulator, java.util.function.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(java.util.stream.Collector<? super T,A,R> collector)
This is a terminal operation
collector
- Promise<java.util.Optional<T>> min(java.util.Comparator<? super T> comparator)
This is a terminal operation
comparator
- Promise<java.util.Optional<T>> max(java.util.Comparator<? super T> comparator)
This is a terminal operation
comparator
- Promise<java.lang.Long> count()
This is a terminal operation
Promise<java.lang.Boolean> anyMatch(Predicate<? super T> predicate)
This is a short circuiting terminal operation
predicate
- Promise<java.lang.Boolean> allMatch(Predicate<? super T> predicate)
This is a short circuiting terminal operation
predicate
- Promise<java.lang.Boolean> noneMatch(Predicate<? super T> predicate)
This is a short circuiting terminal operation
predicate
- Promise<java.util.Optional<T>> findFirst()
Promise<java.util.Optional<T>> findAny()
This is a terminal operation
Promise<java.lang.Long> forEachEvent(PushEventConsumer<? super T> action)
This is a terminal operation
action
- Copyright © OSGi Alliance (2000, 2018). All Rights Reserved. Licensed under the OSGi Specification License, Version 2.0