Package io.activej.csp.queue
Class ChannelZeroBuffer<T>
java.lang.Object
io.activej.csp.queue.ChannelZeroBuffer<T>
- Type Parameters:
T- type of data passed through the buffer
- All Implemented Interfaces:
io.activej.async.process.AsyncCloseable,ChannelConsumerTransformer<T,,ChannelConsumer<T>> ChannelSupplierTransformer<T,,ChannelSupplier<T>> ChannelTransformer<T,,T> ChannelQueue<T>
Represents a buffer of zero capacity and stores only
one value. There are
take and put
SettablePromises which represent status of
corresponding operations. Unless they are null,
they are waiting for the operation to be completed.-
Field Summary
Fields inherited from interface io.activej.async.process.AsyncCloseable
STATIC -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidCloses the buffer if thisexceptionis notnull.@Nullable Exceptionbooleanbooleanio.activej.promise.Promise<Void>Sets the providedvalueto currentvalue, then setsputas a newSettablePromiseand returns it.io.activej.promise.Promise<T>take()Returns a promise of currentvalue, if theputis notnull.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.activej.async.process.AsyncCloseable
closeMethods inherited from interface io.activej.csp.queue.ChannelQueue
getConsumer, getConsumer, getSupplier, transform, transform
-
Constructor Details
-
ChannelZeroBuffer
public ChannelZeroBuffer()
-
-
Method Details
-
isSaturated
public boolean isSaturated()- Specified by:
isSaturatedin interfaceChannelQueue<T>
-
isExhausted
public boolean isExhausted()- Specified by:
isExhaustedin interfaceChannelQueue<T>
-
put
Sets the providedvalueto currentvalue, then setsputas a newSettablePromiseand returns it.If
takeisn'tnull, thevaluewill be set to it.Current
putmust benull. If currentexceptionis notnull, providedvaluewill be recycled and a promise of the exception will be returned.- Specified by:
putin interfaceChannelQueue<T>- Parameters:
item- a value passed to the buffer- Returns:
putif currenttakeisnull, otherwise returns a successfully completed promise. If currentexceptionis notnull, a promise of theexceptionwill be returned.
-
take
Returns a promise of currentvalue, if theputis notnull.Sets
putandvalueasnullafter the operation.If the
putisnull, setstakeas a newSettablePromiseand returns it. If currentexceptionis notnull, returns a promise of the exception and does nothing else.- Specified by:
takein interfaceChannelQueue<T>- Returns:
- a promise of the
valueor ofnull. If thisexceptionis notnull, returns a promise of exception.
-
closeEx
Closes the buffer if thisexceptionis notnull. Recycles all elements of the buffer and setselements,putandtaketonull.- Specified by:
closeExin interfaceio.activej.async.process.AsyncCloseable- Parameters:
e- exception that is used to close buffer with
-
getException
-