public final class PushStreamProvider
extends java.lang.Object
PushStream
instances, and utility methods for handling
PushEventSource
s and PushEventConsumer
sConstructor and Description |
---|
PushStreamProvider() |
Modifier and Type | Method and Description |
---|---|
<T,U extends java.util.concurrent.BlockingQueue<PushEvent<? extends T>>> |
buildBufferedConsumer(PushEventConsumer<T> delegate)
Build a buffered
PushEventConsumer with custom configuration. |
<T,U extends java.util.concurrent.BlockingQueue<PushEvent<? extends T>>> |
buildEventSourceFromStream(PushStream<T> stream)
Convert an
PushStream into an PushEventSource . |
<T,U extends java.util.concurrent.BlockingQueue<PushEvent<? extends T>>> |
buildSimpleEventSource(java.lang.Class<T> type)
Build a
SimplePushEventSource with the supplied type and custom
buffering behaviors. |
<T,U extends java.util.concurrent.BlockingQueue<PushEvent<? extends T>>> |
buildStream(PushEventSource<T> eventSource)
Builds a push stream with custom configuration.
|
<T> PushEventConsumer<T> |
createBufferedConsumer(PushEventConsumer<T> delegate)
Create a buffered
PushEventConsumer with the default configured
buffer, executor size, queue, queue policy and pushback policy. |
<T> PushEventSource<T> |
createEventSourceFromStream(PushStream<T> stream)
Convert an
PushStream into an PushEventSource . |
<T> SimplePushEventSource<T> |
createSimpleEventSource(java.lang.Class<T> type)
Create a
SimplePushEventSource with the supplied type and default
buffering behaviors. |
<T> PushStream<T> |
createStream(PushEventSource<T> eventSource)
Create a stream with the default configured buffer, executor size, queue,
queue policy and pushback policy.
|
<T> PushStream<T> |
streamOf(java.util.concurrent.Executor executor,
java.util.concurrent.ScheduledExecutorService scheduler,
java.util.stream.Stream<T> items)
Create an Unbuffered
PushStream from a Java Stream The
data from the stream will be pushed into the PushStream asynchronously
using the supplied Executor. |
<T> PushStream<T> |
streamOf(java.util.stream.Stream<T> items)
Create an Unbuffered
PushStream from a Java Stream The
data from the stream will be pushed into the PushStream synchronously as
it is opened. |
public <T> PushStream<T> createStream(PushEventSource<T> eventSource)
buildStream(source).create();
This stream will be buffered from the event producer, and will honor back pressure even if the source does not.
Buffered streams 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 processors. Buffering will not, however, protect downstream components from a source which produces events faster (on average) than they can be consumed.
Event delivery will not begin until a terminal operation is reached on the chain of PushStreams. Once a terminal operation is reached the stream will be connected to the event source.
eventSource
- PushStream
with a default initial bufferpublic <T,U extends java.util.concurrent.BlockingQueue<PushEvent<? extends T>>> PushStreamBuilder<T,U> buildStream(PushEventSource<T> eventSource)
The resulting PushStream
may be buffered or unbuffered depending
on how it is configured.
eventSource
- The source of the eventsPushStreamBuilder
for the streampublic <T> PushEventSource<T> createEventSourceFromStream(PushStream<T> stream)
PushStream
into an PushEventSource
. The first
call to PushEventSource.open(PushEventConsumer)
will begin event
processing. The PushEventSource
will remain active until the
backing stream is closed, and permits multiple consumers to
PushEventSource.open(PushEventConsumer)
it. This is equivalent
to:
buildEventSourceFromStream(stream).create();
stream
- PushEventSource
backed by the PushStream
public <T,U extends java.util.concurrent.BlockingQueue<PushEvent<? extends T>>> BufferBuilder<PushEventSource<T>,T,U> buildEventSourceFromStream(PushStream<T> stream)
PushStream
into an PushEventSource
. The first
call to PushEventSource.open(PushEventConsumer)
will begin event
processing.
The PushEventSource
will remain active until the backing stream
is closed, and permits multiple consumers to
PushEventSource.open(PushEventConsumer)
it. Note that this means
the caller of this method is responsible for closing the supplied
stream if it is not finite in length.
Late joining consumers will not receive historical events, but will immediately receive the terminal event which closed the stream if the stream is already closed.
stream
- PushEventSource
backed by the PushStream
public <T> SimplePushEventSource<T> createSimpleEventSource(java.lang.Class<T> type)
SimplePushEventSource
with the supplied type and default
buffering behaviors. The SimplePushEventSource will respond to back
pressure requests from the consumers connected to it. This is equivalent
to:
buildSimpleEventSource(type).create();
type
- SimplePushEventSource
public <T,U extends java.util.concurrent.BlockingQueue<PushEvent<? extends T>>> BufferBuilder<SimplePushEventSource<T>,T,U> buildSimpleEventSource(java.lang.Class<T> type)
SimplePushEventSource
with the supplied type and custom
buffering behaviors. The SimplePushEventSource will respond to back
pressure requests from the consumers connected to it.type
- SimplePushEventSource
public <T> PushEventConsumer<T> createBufferedConsumer(PushEventConsumer<T> delegate)
PushEventConsumer
with the default configured
buffer, executor size, queue, queue policy and pushback policy. This is
equivalent to calling
buildBufferedConsumer(delegate).create();
The returned consumer will be buffered from the event source, and will honor back pressure requests from its delegate even if the event source does not.
Buffered consumers are useful for "bursty" event sources which produce a number of events close together, then none for some time. These bursts can sometimes overwhelm the consumer. Buffering will not, however, protect downstream components from a source which produces events faster than they can be consumed.
delegate
- PushEventConsumer
with a buffer directly before itpublic <T,U extends java.util.concurrent.BlockingQueue<PushEvent<? extends T>>> BufferBuilder<PushEventConsumer<T>,T,U> buildBufferedConsumer(PushEventConsumer<T> delegate)
PushEventConsumer
with custom configuration.
The returned consumer will be buffered from the event source, and will honor back pressure requests from its delegate even if the event source does not.
Buffered consumers are useful for "bursty" event sources which produce a number of events close together, then none for some time. These bursts can sometimes overwhelm the consumer. Buffering will not, however, protect downstream components from a source which produces events faster than they can be consumed.
Buffers are also useful as "circuit breakers". If a
QueuePolicyOption.FAIL
is used then a full buffer will request
that the stream close, preventing an event storm from reaching the
client.
Note that this buffered consumer will close when it receives a terminal event, or if the delegate returns negative backpressure. No further events will be propagated after this time.
delegate
- PushEventConsumer
with a buffer directly before itpublic <T> PushStream<T> streamOf(java.util.stream.Stream<T> items)
PushStream
from a Java Stream
The
data from the stream will be pushed into the PushStream synchronously as
it is opened. This may make terminal operations blocking unless a buffer
has been added to the PushStream
. Care should be taken with
infinite Stream
s to avoid blocking indefinitely.items
- The items to push into the PushStreampublic <T> PushStream<T> streamOf(java.util.concurrent.Executor executor, java.util.concurrent.ScheduledExecutorService scheduler, java.util.stream.Stream<T> items)
PushStream
from a Java Stream
The
data from the stream will be pushed into the PushStream asynchronously
using the supplied Executor.executor
- The worker to use to push items from the Stream into the
PushStreamscheduler
- The scheduler to use to trigger timed events in the
PushStreamitems
- The items to push into the PushStreamCopyright © OSGi Alliance (2000, 2018). All Rights Reserved. Licensed under the OSGi Specification License, Version 2.0