Package io.activej.csp.queue
Interface ChannelQueue<T>
- Type Parameters:
T- type of values stored in the queue
- All Superinterfaces:
io.activej.async.process.AsyncCloseable,ChannelConsumerTransformer<T,,ChannelConsumer<T>> ChannelSupplierTransformer<T,,ChannelSupplier<T>> ChannelTransformer<T,T>
- All Known Implementing Classes:
ChannelBuffer,ChannelBufferWithFallback,ChannelFileBuffer,ChannelZeroBuffer
public interface ChannelQueue<T>
extends ChannelTransformer<T,T>, io.activej.async.process.AsyncCloseable
Represents a queue of elements, which you can
put
or take to pass from ChannelConsumer to
ChannelSupplier.-
Field Summary
Fields inherited from interface io.activej.async.process.AsyncCloseable
STATIC -
Method Summary
Modifier and TypeMethodDescriptiondefault ChannelConsumer<T>Returns aChannelConsumerwhich puts value in this queue whenaccept(T value)is called.default ChannelConsumer<T>getConsumer(io.activej.promise.Promise<Void> acknowledgement) Returns aChannelConsumerwhich puts non-null value in this queue whenaccept(T value)is called.default ChannelSupplier<T>booleanbooleanio.activej.promise.Promise<Void>Puts an item in the queue and returns apromiseofnullas a marker of completion.io.activej.promise.Promise<T>take()Takes an element of this queue and wraps it inpromise.default ChannelConsumer<T>transform(ChannelConsumer<T> consumer) default ChannelSupplier<T>transform(ChannelSupplier<T> supplier) Methods inherited from interface io.activej.async.process.AsyncCloseable
close, closeEx
-
Method Details
-
put
Puts an item in the queue and returns apromiseofnullas a marker of completion.- Parameters:
item- a item passed to the queue- Returns:
promiseofnullas a marker of completion
-
take
io.activej.promise.Promise<T> take()Takes an element of this queue and wraps it inpromise.- Returns:
- a
promiseof value from the queue
-
isSaturated
boolean isSaturated() -
isExhausted
boolean isExhausted() -
getConsumer
Returns aChannelConsumerwhich puts value in this queue whenaccept(T value)is called.- Returns:
- a
ChannelConsumerfor this queue
-
getConsumer
Returns aChannelConsumerwhich puts non-null value in this queue whenaccept(T value)is called. Otherwise, putsnulland waits for theacknowledgementcompletion.This method is useful if you need to control the situations when there are no more elements to be accepted (for example, get a
ChannelSupplierin such case).- Parameters:
acknowledgement- a promise which will work when anullvalue is passed- Returns:
- a ChannelConsumer with custom behaviour in case a
nullvalue is accepted
-
getSupplier
- Returns:
- a ChannelSupplier which takes values from this queue
-
transform
- Specified by:
transformin interfaceChannelConsumerTransformer<T,ChannelConsumer<T>>
-
transform
- Specified by:
transformin interfaceChannelSupplierTransformer<T,ChannelSupplier<T>>
-