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 aPublisherSource.Processor. APublisherSource.Processordecouplesproduction of datafrom theconsumption of dataand 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)andtryConsumeTerminal(ProcessorSignalsConsumer)) is always done serially however the production (methodsadd(Object),terminate(Throwable)andterminate()) can be done concurrently.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidadd(T item)Adds an item to this holder.voidterminate()Terminates this holder, such that no further modifications of this holder are allowed.voidterminate(java.lang.Throwable cause)Terminates 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 Detail
-
add
void add(@Nullable T item)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
void terminate(java.lang.Throwable cause)
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
boolean tryConsume(ProcessorSignalsConsumer<T> consumer)
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
boolean tryConsumeTerminal(ProcessorSignalsConsumer<T> consumer)
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.
-
-