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 TypeMethodDescriptionvoidAdds an item to this holder.voidTerminates this holder, such that no further modifications of this holder are allowed.voidTerminates this holder, such that no further modifications of this holder are allowed.booleantryConsume(ProcessorSignalsConsumer<T> consumer) Try to consume the next item stored in this holder.booleantryConsumeTerminal(ProcessorSignalsConsumer<T> consumer) If there are no items stored in the holder and the holder has terminatedsuccessfullyor with anerrorthen consume thatsuccessfulorfailedtermination.
-
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. Subsequentconsumptionsmust first consume all previouslyaddeditems and thenProcessorSignalsConsumer.consumeTerminal()consume termination}. -
terminate
Terminates this holder, such that no further modifications of this holder are allowed. Subsequentconsumptionsmust first consume all previouslyaddeditems and thenProcessorSignalsConsumer.consumeTerminal()consume termination}.- Parameters:
cause-Throwableas 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 terminatedsuccessfullyor with anerrorthen consume thatsuccessfulorfailedtermination.- Parameters:
consumer-ProcessorSignalsConsumerto consume the next item or termination in this holder- Returns:
trueif any method was called on the passedProcessorSignalsConsumer.
-
tryConsumeTerminal
If there are no items stored in the holder and the holder has terminatedsuccessfullyor with anerrorthen consume thatsuccessfulorfailedtermination. If there are items in the holder then this method does nothing.- Parameters:
consumer-ProcessorSignalsConsumerto consume the next item or termination in this holder- Returns:
trueif a terminal event was consumed by the passedProcessorSignalsConsumer.
-