Top Description Methods
org.osgi.util.pushstream

public Interface PushStream<T>

extends AutoCloseable
Known Direct Implementers
org.osgi.util.pushstream.UnbufferedPushStreamImpl, org.osgi.util.pushstream.AbstractPushStreamImpl, org.osgi.util.pushstream.BufferedPushStreamImpl, org.osgi.util.pushstream.IntermediatePushStreamImpl
Annotations
@ProviderType
Type Parameters
<T>
The Payload type
Imports
java.time.Duration, java.util.Collection, .Comparator, .Optional, java.util.concurrent.BlockingQueue, .Executor, java.util.function.BiFunction, .BinaryOperator, .Consumer, .IntFunction, .IntSupplier, .LongUnaryOperator, .Supplier, .ToLongBiFunction, java.util.stream.Collector, org.osgi.annotation.versioning.ProviderType, org.osgi.util.function.Function, .Predicate, org.osgi.util.promise.Promise, .TimeoutException

A Push Stream fulfills the same role as the Java 8 stream but it reverses the control direction. The Java 8 stream is pull based and this is push based. A Push Stream makes it possible to build a pipeline of transformations using a builder kind of model. Just like streams, it provides a number of terminating methods that will actually open the channel and perform the processing until the channel is closed (The source sends a Close event). The results of the processing will be send to a Promise, just like any error events. A stream can be used multiple times. The Push Stream represents a pipeline. Upstream is in the direction of the source, downstream is in the direction of the terminating method. Events are sent downstream asynchronously with no guarantee for ordering or concurrency. Methods are available to provide serialization of the events and splitting in background threads.

Method Summary

Modifier and TypeMethod and Description
public PushStream<T>

Returns:

Builder style (can be a new or the same object)
adjustBackPressure
(LongUnaryOperator adjustment)

Changes the back-pressure propagated by this pipeline stage.

public PushStream<T>

Returns:

Builder style (can be a new or the same object)
adjustBackPressure
(ToLongBiFunction<T, Long> adjustment)

Changes the back-pressure propagated by this pipeline stage.

public Promise<Boolean>

Returns:

A Promise that will resolve when an event fails to match the predicate, or the end of the stream is reached
allMatch
(Predicate<? super T> predicate)

Closes the channel and resolve the promise with false when the predicate does not matches a pay load.

public Promise<Boolean>

Returns:

A Promise that will resolve when an event matches the predicate, or the end of the stream is reached
anyMatch
(Predicate<? super T> predicate)

Close the channel and resolve the promise with true when the predicate matches a payload.

public <R> PushStream<R>

Returns:

Builder style (can be a new or the same object)
asyncMap
(int
number of simultaneous promises to use
n
,
int
Nr of ms/promise that is queued back pressure
delay
,
Function<? super T, Promise<? extends R>>
The mapping function
mapper
)

Asynchronously map the payload values.

public PushStream<T>

Returns:

Builder style (can be a new or the same object)
buffer
()

Buffer the events in a queue using default values for the queue size and other behaviors.

public <U extends BlockingQueue<PushEvent<? extends T>>> PushStreamBuilder<T, U>

Returns:

A builder which can be used to configure the buffer for this pipeline stage.
buildBuffer
()

Build a buffer to enqueue events in a queue using custom values for the queue size and other behaviors.

public void
close()

Redeclares java.lang.AutoCloseable.close.

Close this PushStream by sending an event of type PushEvent.EventType#CLOSE downstream.

public <R> PushStream<R>

Returns:

Builder style (can be a new or the same object)
coalesce
(Function<? super T, Optional<R>> f)

Coalesces a number of events into a new type of event.

public <R> PushStream<R>

Returns:

Builder style (can be a new or the same object)
coalesce
(int count, Function<Collection<T>, R> f)

Coalesces a number of events into a new type of event.

public <R> PushStream<R>

Returns:

Builder style (can be a new or the same object)
coalesce
(IntSupplier count, Function<Collection<T>, R> f)

Coalesces a number of events into a new type of event.

public <R, A> Promise<R>

Returns:

A Promise representing the collected results
collect
(Collector<? super T, A, R> collector)

See Stream.

public Promise<Long>

Returns:

A Promise representing the number of values in the stream
count
()

See Stream.

public PushStream<T>

Returns:

Builder style (can be a new or the same object)
distinct
()

Remove any duplicates.

public PushStream<T>

Returns:

Builder style (can be a new or the same object)
filter
(Predicate<? super T>
The predicate that is tested (not null)
predicate
)

Only pass events downstream when the predicate tests true.

public Promise<Optional<T>>

Returns:

a promise
findAny
()

Close the channel and resolve the promise with the first element.

public Promise<Optional<T>>

Returns:

a promise
findFirst
()

Close the channel and resolve the promise with the first element.

public <R> PushStream<R>

Returns:

Builder style (can be a new or the same object)
flatMap
(Function<? super T, ? extends PushStream<? extends R>>
The flat map function
mapper
)

Flat map the payload value (turn one event into 0..n events of potentially another type).

public Promise<Void>

Returns:

A promise that is resolved when the channel closes.
forEach
(Consumer<? super T>
The action to perform
action
)

Execute the action for each event received until the channel is closed.

public Promise<Long>

Returns:

a promise
forEachEvent
(PushEventConsumer<? super T> action)

Pass on each event to another consumer until the stream is closed.

public PushStream<T>

Returns:

Builder style (can be a new or the same object)
fork
(int
number of simultaneous background threads to use
n
,
int
Nr of ms/thread that is queued back pressure
delay
,
Executor
an executor to use for the background threads.
e
)

Execute the downstream events in up to n background threads.

public PushStream<T>

Returns:

Builder style (can be a new or the same object)
limit
(long
Maximum number of elements has been received
maxSize
)

Automatically close the channel after the maxSize number of elements is received.

public PushStream<T>

Returns:

Builder style (can be a new or the same object)
limit
(Duration
The maximum time that the stream should remain open
maxTime
)

Automatically close the channel after the given amount of time has elapsed.

public <R> PushStream<R>

Returns:

Builder style (can be a new or the same object)
map
(Function<? super T, ? extends R>
The map function
mapper
)

Map a payload value.

public Promise<Optional<T>>

Returns:

A Promise representing the maximum value, or null if no values are seen before the end of the stream
max
(Comparator<? super T> comparator)

See Stream.

public PushStream<T>

Returns:

Builder style (can be a new or the same object)
merge
(PushEventSource<? extends T>
The source to merge in.
source
)

Merge in the events from another source.

public PushStream<T>

Returns:

Builder style (can be a new or the same object)
merge
(PushStream<? extends T>
The source to merge in.
source
)

Merge in the events from another PushStream.

public Promise<Optional<T>>

Returns:

A Promise representing the minimum value, or null if no values are seen before the end of the stream
min
(Comparator<? super T> comparator)

See Stream.

public Promise<Boolean>

Returns:

A Promise that will resolve when an event matches the predicate, or the end of the stream is reached
noneMatch
(Predicate<? super T> predicate)

Closes the channel and resolve the promise with false when the predicate matches any pay load.

public PushStream<T>

Returns:

This stream
onClose
(Runnable
Will be called on close
closeHandler
)

Provide a handler that must be run after the PushStream is closed.

public PushStream<T>

Returns:

This stream
onError
(Consumer<? super Throwable>
Will be called on an error event
errorHandler
)

Provide a handler that will be called if the PushStream is closed with an event of type PushEvent.EventType#ERROR.

public Promise<T>

Returns:

A
reduce
(T
The identity/begin value
identity
,
BinaryOperator<T>
The accumulator
accumulator
)

Standard reduce, see Stream.

public Promise<Optional<T>>

Returns:

an Optional
reduce
(BinaryOperator<T>
The accumulator
accumulator
)

Standard reduce without identity, so the return is an Optional.

public <U> Promise<U>

Returns:

The promise
reduce
(U identity, BiFunction<U, ? super T, U> accumulator, BinaryOperator<U>
combines two U's into one U (for example, combine two lists)
combiner
)

Standard reduce with identity, accumulator and combiner.

public PushStream<T>

Returns:

Builder style (can be a new or the same object)
sequential
()

Ensure that any events are delivered sequentially.

public PushStream<T>

Returns:

Builder style (can be a new or the same object)
skip
(long
number of elements to skip
n
)

Skip a number of events in the channel.

public PushStream<T>

Returns:

Builder style (can be a new or the same object)
sorted
()

Sorted the elements, assuming that T extends Comparable.

public PushStream<T>

Returns:

Builder style (can be a new or the same object)
sorted
(Comparator<? super T> comparator)

Sorted the elements with the given comparator.

public PushStream<T>[]

Returns:

streams that map to the predicates
split
(Predicate<? super T>...
the predicates to test
predicates
)

Split the events to different streams based on a predicate.

public PushStream<T>

Returns:

Builder style (can be a new or the same object)
timeout
(Duration
The length of time that the stream should remain open when no events are being received.
idleTime
)

Automatically fail the channel if no events are received for the indicated length of time.

public Promise<Object[]>

Returns:

A promise that is resolved with all the payloads received over the channel
toArray
()

Collect the payloads in an Object array after the channel is closed.

public <
The element type of the resulting array.
A
>
Promise<A[]>

Returns:

A promise that is resolved with all the payloads received over the channel. The promise will be failed with an ArrayStoreException if the runtime type of the array returned by the array generator is not a supertype of the runtime type of every payload in the channel.
toArray
(IntFunction<A[]>
A function which returns an array into which the payloads are stored.
generator
)

Collect the payloads in an Object array after the channel is closed.

public <R> PushStream<R>

Returns:

Builder style (can be a new or the same object)
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.

public <R> PushStream<R>

Returns:

Builder style (can be a new or the same object)
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.

public <R> PushStream<R>

Returns:

Builder style (can be a new or the same object)
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.

public <R> PushStream<R>

Returns:

Builder style (can be a new or the same object)
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.

Method Detail

adjustBackPressureback to summary
public PushStream<T> adjustBackPressure(LongUnaryOperator adjustment)

Changes the back-pressure propagated by this pipeline stage.

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.

Returns:PushStream<T>

Builder style (can be a new or the same object)

adjustBackPressureback to summary
public PushStream<T> adjustBackPressure(ToLongBiFunction<T, Long> adjustment)

Changes the back-pressure propagated by this pipeline stage.

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.

Returns:PushStream<T>

Builder style (can be a new or the same object)

allMatchback to summary
public 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. If the channel is closed before, the promise is resolved with true.

This is a short circuiting terminal operation

Returns:Promise<Boolean>

A Promise that will resolve when an event fails to match the predicate, or the end of the stream is reached

anyMatchback to summary
public Promise<Boolean> anyMatch(Predicate<? super T> predicate)

Close the channel and resolve the promise with true when the predicate matches a payload. If the channel is closed before the predicate matches, the promise is resolved with false.

This is a short circuiting terminal operation

Returns:Promise<Boolean>

A Promise that will resolve when an event matches the predicate, or the end of the stream is reached

asyncMapback to summary
public <R> PushStream<R> asyncMap(int n, int delay, Function<? super T, Promise<? extends R>> mapper)

Asynchronously map the payload values. The mapping function returns a Promise representing the asynchronous mapping operation.

The PushStream limits the number of concurrently running mapping operations, and returns back pressure based on the number of existing queued operations.

Parameters
n:int

number of simultaneous promises to use

delay:int

Nr of ms/promise that is queued back pressure

mapper:Function<? super T, Promise<? extends R>>

The mapping function

Returns:PushStream<R>

Builder style (can be a new or the same object)

Exceptions
IllegalArgumentException:
if the number of threads is < 1 or the delay is < 0
NullPointerException:
if the mapper is null
bufferback to summary
public PushStream<T> buffer()

Buffer the events in a queue using default values for the queue size and other behaviors. Buffered work will be processed asynchronously in the rest of the chain. Buffering also blocks the transmission of back pressure to previous elements in the chain, although back pressure is honored by the 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.

Returns:PushStream<T>

Builder style (can be a new or the same object)

buildBufferback to summary
public <U extends BlockingQueue<PushEvent<? extends T>>> PushStreamBuilder<T, U> buildBuffer()

Build a buffer to enqueue events in a queue using custom values for the queue size and other behaviors. Buffered work will be processed asynchronously in the rest of the chain. Buffering also blocks the transmission of back pressure to previous elements in the chain, although back pressure is honored by the 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.

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.

Returns:PushStreamBuilder<T, U>

A builder which can be used to configure the buffer for this pipeline stage.

closeback to summary
public void close()

Redeclares java.lang.AutoCloseable.close.

Close this PushStream by sending an event of type 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.

Annotations
@Override
coalesceback to summary
public <R> PushStream<R> coalesce(Function<? super T, Optional<R>> f)

Coalesces a number of events into a new type of event. The input events are forwarded to a accumulator function. This function returns an Optional. If the optional is present, it's value is send downstream, otherwise it is ignored.

Returns:PushStream<R>

Builder style (can be a new or the same object)

coalesceback to summary
public <R> PushStream<R> coalesce(int count, Function<Collection<T>, R> f)

Coalesces a number of events into a new type of event. A fixed number of input events are forwarded to a accumulator function. This function returns new event data to be forwarded on.

Returns:PushStream<R>

Builder style (can be a new or the same object)

coalesceback to summary
public <R> PushStream<R> coalesce(IntSupplier count, Function<Collection<T>, R> f)

Coalesces a number of events into a new type of event. A variable number of input events are forwarded to a accumulator function. The number of events to be forwarded is determined by calling the count function. The accumulator function then returns new event data to be forwarded on.

Returns:PushStream<R>

Builder style (can be a new or the same object)

collectback to summary
public <R, A> Promise<R> collect(Collector<? super T, A, R> collector)

See Stream. Will resolve once the channel closes.

This is a terminal operation

Returns:Promise<R>

A Promise representing the collected results

countback to summary
public Promise<Long> count()

See Stream. Will resolve onces the channel closes.

This is a terminal operation

Returns:Promise<Long>

A Promise representing the number of values in the stream

distinctback to summary
public PushStream<T> distinct()

Remove any duplicates. Notice that this can be expensive in a large stream since it must track previous payloads.

Returns:PushStream<T>

Builder style (can be a new or the same object)

filterback to summary
public PushStream<T> filter(Predicate<? super T> predicate)

Only pass events downstream when the predicate tests true.

Parameters
predicate:Predicate<? super T>

The predicate that is tested (not null)

Returns:PushStream<T>

Builder style (can be a new or the same object)

findAnyback to summary
public Promise<Optional<T>> findAny()

Close the channel and resolve the promise with the first element. If the channel is closed before, the Optional will have no value.

This is a terminal operation

Returns:Promise<Optional<T>>

a promise

findFirstback to summary
public Promise<Optional<T>> findFirst()

Close the channel and resolve the promise with the first element. If the channel is closed before, the Optional will have no value.

Returns:Promise<Optional<T>>

a promise

flatMapback to summary
public <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).

Parameters
mapper:Function<? super T, ? extends PushStream<? extends R>>

The flat map function

Returns:PushStream<R>

Builder style (can be a new or the same object)

forEachback to summary
public Promise<Void> forEach(Consumer<? super T> action)

Execute the action for each event received until the channel is closed. This is a terminating method, the returned promise is resolved when the channel closes.

This is a terminal operation

Parameters
action:Consumer<? super T>

The action to perform

Returns:Promise<Void>

A promise that is resolved when the channel closes.

forEachEventback to summary
public Promise<Long> forEachEvent(PushEventConsumer<? super T> action)

Pass on each event to another consumer until the stream is closed.

This is a terminal operation

Returns:Promise<Long>

a promise

forkback to summary
public PushStream<T> fork(int n, int delay, Executor e)

Execute the downstream events in up to n background threads. If more requests are outstanding apply delay * nr of delayed threads back pressure. A downstream channel that is closed or throws an exception will cause all execution to cease and the stream to close

Parameters
n:int

number of simultaneous background threads to use

delay:int

Nr of ms/thread that is queued back pressure

e:Executor

an executor to use for the background threads.

Returns:PushStream<T>

Builder style (can be a new or the same object)

Exceptions
IllegalArgumentException:
if the number of threads is < 1 or the delay is < 0
NullPointerException:
if the Executor is null
limitback to summary
public PushStream<T> limit(long maxSize)

Automatically close the channel after the maxSize number of elements is received.

Parameters
maxSize:long

Maximum number of elements has been received

Returns:PushStream<T>

Builder style (can be a new or the same object)

limitback to summary
public PushStream<T> limit(Duration maxTime)

Automatically close the channel after the given amount of time has elapsed.

Parameters
maxTime:Duration

The maximum time that the stream should remain open

Returns:PushStream<T>

Builder style (can be a new or the same object)

mapback to summary
public <R> PushStream<R> map(Function<? super T, ? extends R> mapper)

Map a payload value.

Parameters
mapper:Function<? super T, ? extends R>

The map function

Returns:PushStream<R>

Builder style (can be a new or the same object)

maxback to summary
public Promise<Optional<T>> max(Comparator<? super T> comparator)

See Stream. Will resolve onces the channel closes.

This is a terminal operation

Returns:Promise<Optional<T>>

A Promise representing the maximum value, or null if no values are seen before the end of the stream

mergeback to summary
public PushStream<T> merge(PushEventSource<? extends T> source)

Merge in the events from another source. The resulting channel is not closed until this channel and the channel from the source are closed.

Parameters
source:PushEventSource<? extends T>

The source to merge in.

Returns:PushStream<T>

Builder style (can be a new or the same object)

mergeback to summary
public PushStream<T> merge(PushStream<? extends T> source)

Merge in the events from another PushStream. The resulting channel is not closed until this channel and the channel from the source are closed.

Parameters
source:PushStream<? extends T>

The source to merge in.

Returns:PushStream<T>

Builder style (can be a new or the same object)

minback to summary
public Promise<Optional<T>> min(Comparator<? super T> comparator)

See Stream. Will resolve onces the channel closes.

This is a terminal operation

Returns:Promise<Optional<T>>

A Promise representing the minimum value, or null if no values are seen before the end of the stream

noneMatchback to summary
public Promise<Boolean> noneMatch(Predicate<? super T> predicate)

Closes the channel and resolve the promise with false when the predicate matches any pay load. If the channel is closed before, the promise is resolved with true.

This is a short circuiting terminal operation

Returns:Promise<Boolean>

A Promise that will resolve when an event matches the predicate, or the end of the stream is reached

onCloseback to summary
public PushStream<T> onClose(Runnable closeHandler)

Provide a handler that must be run after the PushStream is closed. This handler will run after any downstream operations have processed the terminal event but before any upstream operations have processed the terminal event.

Parameters
closeHandler:Runnable

Will be called on close

Returns:PushStream<T>

This stream

onErrorback to summary
public 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. 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.

Parameters
errorHandler:Consumer<? super Throwable>

Will be called on an error event

Returns:PushStream<T>

This stream

reduceback to summary
public Promise<T> reduce(T identity, BinaryOperator<T> accumulator)

Standard reduce, see Stream. The returned promise will be resolved when the channel closes.

This is a terminal operation

Parameters
identity:T

The identity/begin value

accumulator:BinaryOperator<T>

The accumulator

Returns:Promise<T>

A

reduceback to summary
public Promise<Optional<T>> reduce(BinaryOperator<T> accumulator)

Standard reduce without identity, so the return is an Optional. The returned promise will be resolved when the channel closes.

This is a terminal operation

Parameters
accumulator:BinaryOperator<T>

The accumulator

Returns:Promise<Optional<T>>

an Optional

reduceback to summary
public <U> Promise<U> reduce(U identity, BiFunction<U, ? super T, U> accumulator, BinaryOperator<U> combiner)

Standard reduce with identity, accumulator and combiner. The returned promise will be resolved when the channel closes.

This is a terminal operation

Parameters
combiner:BinaryOperator<U>

combines two U's into one U (for example, combine two lists)

Returns:Promise<U>

The promise

sequentialback to summary
public PushStream<T> sequential()

Ensure that any events are delivered sequentially. That is, no overlapping calls downstream. This can be used to turn a forked stream (where for example a heavy conversion is done in multiple threads) back into a sequential stream so a reduce is simple to do.

Returns:PushStream<T>

Builder style (can be a new or the same object)

skipback to summary
public PushStream<T> skip(long n)

Skip a number of events in the channel.

Parameters
n:long

number of elements to skip

Returns:PushStream<T>

Builder style (can be a new or the same object)

Exceptions
IllegalArgumentException:
if the number of events to skip is negative
sortedback to summary
public PushStream<T> sorted()

Sorted the elements, assuming that T extends Comparable. This is of course expensive for large or infinite streams since it requires buffering the stream until close.

Returns:PushStream<T>

Builder style (can be a new or the same object)

sortedback to summary
public PushStream<T> sorted(Comparator<? super T> comparator)

Sorted the elements with the given comparator. This is of course expensive for large or infinite streams since it requires buffering the stream until close.

Returns:PushStream<T>

Builder style (can be a new or the same object)

splitback to summary
public PushStream<T>[] split(Predicate<? super T>... predicates)

Split the events to different streams based on a predicate. If the predicate is true, the event is dispatched to that channel on the same position. All predicates are tested for every event.

This method differs from other methods of PushStream in three significant ways:

  • The return value contains multiple streams.
  • This stream will only close when all of these child streams have closed.
  • Event delivery is made to all open children that accept the event.
Parameters
predicates:Predicate<? super T>[]

the predicates to test

Returns:PushStream<T>[]

streams that map to the predicates

Annotations
@SuppressWarnings:unchecked
timeoutback to summary
public PushStream<T> timeout(Duration idleTime)

Automatically fail the channel if no events are received for the indicated length of time. If the timeout is reached then a failure event containing a TimeoutException will be sent.

Parameters
idleTime:Duration

The length of time that the stream should remain open when no events are being received.

Returns:PushStream<T>

Builder style (can be a new or the same object)

toArrayback to summary
public Promise<Object[]> toArray()

Collect the payloads in an Object array after the channel is closed. This is a terminating method, the returned promise is resolved when the channel is closed.

This is a terminal operation

Returns:Promise<Object[]>

A promise that is resolved with all the payloads received over the channel

toArrayback to summary
public <A> Promise<A[]> toArray(IntFunction<A[]> generator)

Collect the payloads in an Object array after the channel is closed. This is a terminating method, the returned promise is resolved when the channel is closed. The type of the array is handled by the caller using a generator function that gets the length of the desired array.

This is a terminal operation

Parameters
<A>
The element type of the resulting array.
generator:IntFunction<A[]>

A function which returns an array into which the payloads are stored.

Returns:Promise<A[]>

A promise that is resolved with all the payloads received over the channel. The promise will be failed with an ArrayStoreException if the runtime type of the array returned by the array generator is not a supertype of the runtime type of every payload in the channel.

windowback to summary
public <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. This function returns new event data to be forwarded on. Note that:

  • The collection forwarded to the accumulator function will be empty if no events arrived during the time interval.
  • The accumulator function will be run and the forwarded event delivered as a different task, (and therefore potentially on a different thread) from the one that delivered the event to this PushStream.
  • Due to the buffering and asynchronous delivery required, this method prevents the propagation of back-pressure to earlier stages
Returns:PushStream<R>

Builder style (can be a new or the same object)

windowback to summary
public <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. This function returns new event data to be forwarded on. Note that:

  • The collection forwarded to the accumulator function will be empty if no events arrived during the time interval.
  • The accumulator function will be run and the forwarded event delivered by a task given to the supplied executor.
  • Due to the buffering and asynchronous delivery required, this method prevents the propagation of back-pressure to earlier stages
Returns:PushStream<R>

Builder style (can be a new or the same object)

windowback to summary
public <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. The length of time over which events are buffered is determined by the time function. A maximum number of events can also be requested, if this number of events is reached then the accumulator will be called early. The accumulator function returns new event data to be forwarded on. It is also given the length of time for which the buffer accumulated data. This may be less than the requested interval if the buffer reached the maximum number of requested events early. Note that:

  • The collection forwarded to the accumulator function will be empty if no events arrived during the time interval.
  • The accumulator function will be run and the forwarded event delivered as a different task, (and therefore potentially on a different thread) from the one that delivered the event to this PushStream.
  • Due to the buffering and asynchronous delivery required, this method prevents the propagation of back-pressure to earlier stages
  • If the window finishes by hitting the maximum number of events then the remaining time in the window will be applied as back-pressure to the previous stage, attempting to slow the producer to the expected windowing threshold.
Returns:PushStream<R>

Builder style (can be a new or the same object)

windowback to summary
public <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. The length of time over which events are buffered is determined by the time function. A maximum number of events can also be requested, if this number of events is reached then the accumulator will be called early. The accumulator function returns new event data to be forwarded on. It is also given the length of time for which the buffer accumulated data. This may be less than the requested interval if the buffer reached the maximum number of requested events early. Note that:

  • The collection forwarded to the accumulator function will be empty if no events arrived during the time interval.
  • The accumulator function will be run and the forwarded event delivered as a different task, (and therefore potentially on a different thread) from the one that delivered the event to this PushStream.
  • If the window finishes by hitting the maximum number of events then the remaining time in the window will be applied as back-pressure to the previous stage, attempting to slow the producer to the expected windowing threshold.
Returns:PushStream<R>

Builder style (can be a new or the same object)