Package io.servicetalk.concurrent.api
Interface PublisherProcessorSignalsHolder<T>
- Type Parameters:
T
- Type of items stored in this holder.
public interface PublisherProcessorSignalsHolder<T>
A holder of items for a
PublisherSource.Processor
. A PublisherSource.Processor
decouples production of data
from
the consumption of data
and this holder acts as the implementation for that
decoupling by using an intermediate in-memory storage. This in-memory storage layer can be used in different ways,
some of which are enumerated below:
- Implement a custom signal rejection strategy when some signals can be dropped in favor of others.
- Store reduced set of signals when intermediary signals can either be discarded or coalesced.
- Reverse order of consumption of items when stored signals reach a threshold.
Multi-threaded access
Implementations may assume that the consumption of the holder (methodstryConsume(ProcessorSignalsConsumer)
and tryConsumeTerminal(ProcessorSignalsConsumer)
) is always done serially however the production (methods
add(Object)
, terminate(Throwable)
and terminate()
) can be done concurrently.-
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds an item to this holder.void
Terminates this holder, such that no further modifications of this holder are allowed.void
Terminates this holder, such that no further modifications of this holder are allowed.boolean
tryConsume
(ProcessorSignalsConsumer<T> consumer) Try to consume the next item stored in this holder.boolean
tryConsumeTerminal
(ProcessorSignalsConsumer<T> consumer) If there are no items stored in the holder and the holder has terminatedsuccessfully
or with anerror
then consume thatsuccessful
orfailed
termination.
-
Method Details
-
add
Adds an item to this holder.- Parameters:
item
- to add.
-
terminate
void terminate()Terminates this holder, such that no further modifications of this holder are allowed. Subsequentconsumptions
must first consume all previouslyadded
items and thenProcessorSignalsConsumer.consumeTerminal()
consume termination}. -
terminate
Terminates this holder, such that no further modifications of this holder are allowed. Subsequentconsumptions
must first consume all previouslyadded
items and thenProcessorSignalsConsumer.consumeTerminal()
consume termination}.- Parameters:
cause
-Throwable
as a cause for termination.
-
tryConsume
Try to consume the next item stored in this holder. If there are no items stored in the holder and the holder has terminatedsuccessfully
or with anerror
then consume thatsuccessful
orfailed
termination.- Parameters:
consumer
-ProcessorSignalsConsumer
to consume the next item or termination in this holder- Returns:
true
if any method was called on the passedProcessorSignalsConsumer
.
-
tryConsumeTerminal
If there are no items stored in the holder and the holder has terminatedsuccessfully
or with anerror
then consume thatsuccessful
orfailed
termination. If there are items in the holder then this method does nothing.- Parameters:
consumer
-ProcessorSignalsConsumer
to consume the next item or termination in this holder- Returns:
true
if a terminal event was consumed by the passedProcessorSignalsConsumer
.
-