Package io.servicetalk.concurrent.api
Interface BufferStrategy<T,BC extends BufferStrategy.Accumulator<T,B>,B>
- Type Parameters:
T
- items emitted from thePublisher
which are to be buffered using thisBufferStrategy
.BC
- An intermediate mutable object that holds the items into a buffer before it is emitted.B
- The buffer of items.
public interface BufferStrategy<T,BC extends BufferStrategy.Accumulator<T,B>,B>
A strategy for
buffering
items emitted from a Publisher
.
A buffer strategy represents asynchronous buffer boundaries
over which items from a
Publisher
are buffered. Each item emitted from the boundary Publisher
represents the end of the
last boundary and start of the next boundary. The first item emitted from this Publisher
is treated as the
start of the first boundary and Publisher.buffer(BufferStrategy)
may decide to defer requesting items from
the Publisher
on which that operator is applied.
-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic interface
An intermediate mutable object that holds items till it isfinished
. -
Method Summary
Modifier and TypeMethodDescriptionReturns aPublisher
representing asynchronous buffer boundaries.int
A rough estimate of the number of items in a buffer.
-
Method Details
-
boundaries
Returns aPublisher
representing asynchronous buffer boundaries.Notes:
- This
Publisher
is expected to be an infinitePublisher
. Hence, it should never terminate anyPublisherSource.Subscriber
subscribed to it. InsteadPublisherSource.Subscriber
s will alwayscancel
theirPublisherSource.Subscription
. If this expectation is violated, buffered items may be discarded. - If this
Publisher
returns more boundaries faster than accumulation or emission of the previous boundary can be processed, these new boundaries may be discarded without invocation of eitherBufferStrategy.Accumulator.accumulate(Object)
orBufferStrategy.Accumulator.finish()
methods. Avoid initializing expensive state before any of theBufferStrategy.Accumulator
methods are invoked.
- Returns:
- A
Publisher
representing asynchronous buffer boundaries.
- This
-
bufferSizeHint
int bufferSizeHint()A rough estimate of the number of items in a buffer.Note: if
boundaries()
are generated based on the number of accumulated items, this hint size MUST always be equal or less than the number of items that generates a boundary. Otherwise, there is a risk of emitting more buffers than requested.- Returns:
- A rough estimate of the number of items in a buffer.
-