Package io.servicetalk.concurrent.api
Interface BlockingProcessorSignalsHolder<T>
-
- Type Parameters:
T- Type of items stored in this holder.
public interface BlockingProcessorSignalsHolder<T>A holder of items for aBlockingIterable.Processor.Multi-threaded access
Implementations may assume that the consumption of the items (methodsconsume(ProcessorSignalsConsumer)andconsume(ProcessorSignalsConsumer, long, TimeUnit)) is always done serially however the production (methodsadd(Object),terminate(Throwable)andterminate()) may 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.booleanconsume(ProcessorSignalsConsumer<T> consumer)Consumes the next item stored in this holder.booleanconsume(ProcessorSignalsConsumer<T> consumer, long waitFor, java.util.concurrent.TimeUnit waitForUnit)Consumes the next item stored in this holder.voidterminate()Terminates this holder, such that no further modifications of this holder are expected.voidterminate(java.lang.Throwable cause)Terminates this holder, such that no further modifications of this holder are expected.
-
-
-
Method Detail
-
add
void add(@Nullable T item) throws java.lang.InterruptedExceptionAdds an item to this holder.- Parameters:
item- to add.- Throws:
java.lang.InterruptedException- If the add was interrupted.
-
terminate
void terminate() throws java.lang.InterruptedExceptionTerminates this holder, such that no further modifications of this holder are expected. Subsequentconsumptionsmust first consume all previouslyaddeditems and thenProcessorSignalsConsumer.consumeTerminal()consume termination}.- Throws:
java.lang.InterruptedException- If termination was interrupted.
-
terminate
void terminate(java.lang.Throwable cause) throws java.lang.InterruptedExceptionTerminates this holder, such that no further modifications of this holder are expected. Subsequentconsumptionsmust first consume all previouslyaddeditems and thenProcessorSignalsConsumer.consumeTerminal()consume termination}.- Parameters:
cause-Throwableas a cause for termination.- Throws:
java.lang.InterruptedException- If termination was interrupted.
-
consume
boolean consume(ProcessorSignalsConsumer<T> consumer) throws java.lang.InterruptedException
Consumes 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.This method will block till an item or a terminal event is available in the holder.
- Parameters:
consumer-ProcessorSignalsConsumerto consume the next item or termination in this holder- Returns:
trueif any method was called on the passedProcessorSignalsConsumer.- Throws:
java.lang.InterruptedException- If the thread was interrupted while waiting for an item or terminal event.
-
consume
boolean consume(ProcessorSignalsConsumer<T> consumer, long waitFor, java.util.concurrent.TimeUnit waitForUnit) throws java.util.concurrent.TimeoutException, java.lang.InterruptedException
Consumes 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.This method will block till an item or a terminal event is available in the holder or the passed
waitForduration has elapsed.- Parameters:
consumer-ProcessorSignalsConsumerto consume the next item or termination in this holderwaitFor- Duration to wait for an item or termination to be available.waitForUnit-TimeUnitforwaitFor.- Returns:
trueif any method was called on the passedProcessorSignalsConsumer.- Throws:
java.util.concurrent.TimeoutException- If there was no item or termination available in the holder for the passedwaitFordurationjava.lang.InterruptedException- If the thread was interrupted while waiting for an item or terminal event.
-
-