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 a
BlockingIterable.Processor
.
Multi-threaded access
Implementations may assume that the consumption of the items (methodsconsume(ProcessorSignalsConsumer)
and consume(ProcessorSignalsConsumer, long, TimeUnit)
) is always done serially however the production
(methods add(Object)
, terminate(Throwable)
and terminate()
) may be done concurrently.-
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds an item to this holder.boolean
consume
(ProcessorSignalsConsumer<T> consumer) Consumes the next item stored in this holder.boolean
consume
(ProcessorSignalsConsumer<T> consumer, long waitFor, TimeUnit waitForUnit) Consumes the next item stored in this holder.void
Terminates this holder, such that no further modifications of this holder are expected.void
Terminates this holder, such that no further modifications of this holder are expected.
-
Method Details
-
add
Adds an item to this holder.- Parameters:
item
- to add.- Throws:
InterruptedException
- If the add was interrupted.
-
terminate
Terminates this holder, such that no further modifications of this holder are expected. Subsequentconsumptions
must first consume all previouslyadded
items and thenProcessorSignalsConsumer.consumeTerminal()
consume termination}.- Throws:
InterruptedException
- If termination was interrupted.
-
terminate
Terminates this holder, such that no further modifications of this holder are expected. Subsequentconsumptions
must first consume all previouslyadded
items and thenProcessorSignalsConsumer.consumeTerminal()
consume termination}.- Parameters:
cause
-Throwable
as a cause for termination.- Throws:
InterruptedException
- If termination was interrupted.
-
consume
Consumes 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.This method will block till an item or a terminal event is available in the holder.
- Parameters:
consumer
-ProcessorSignalsConsumer
to consume the next item or termination in this holder- Returns:
true
if any method was called on the passedProcessorSignalsConsumer
.- Throws:
InterruptedException
- If the thread was interrupted while waiting for an item or terminal event.
-
consume
boolean consume(ProcessorSignalsConsumer<T> consumer, long waitFor, TimeUnit waitForUnit) throws TimeoutException, InterruptedException Consumes 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.This method will block till an item or a terminal event is available in the holder or the passed
waitFor
duration has elapsed.- Parameters:
consumer
-ProcessorSignalsConsumer
to consume the next item or termination in this holderwaitFor
- Duration to wait for an item or termination to be available.waitForUnit
-TimeUnit
forwaitFor
.- Returns:
true
if any method was called on the passedProcessorSignalsConsumer
.- Throws:
TimeoutException
- If there was no item or termination available in the holder for the passedwaitFor
durationInterruptedException
- If the thread was interrupted while waiting for an item or terminal event.
-