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>

public final class ChannelZeroBuffer<T> extends Object implements 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.
  • Constructor Details

    • ChannelZeroBuffer

      public ChannelZeroBuffer()
  • Method Details

    • isSaturated

      public boolean isSaturated()
      Specified by:
      isSaturated in interface ChannelQueue<T>
    • isExhausted

      public boolean isExhausted()
      Specified by:
      isExhausted in interface ChannelQueue<T>
    • put

      public io.activej.promise.Promise<Void> put(@Nullable T item)
      Sets the provided value to current value, then sets put as a new SettablePromise and returns it.

      If take isn't null, the value will be set to it.

      Current put must be null. If current exception is not null, provided value will be recycled and a promise of the exception will be returned.

      Specified by:
      put in interface ChannelQueue<T>
      Parameters:
      item - a value passed to the buffer
      Returns:
      put if current take is null, otherwise returns a successfully completed promise. If current exception is not null, a promise of the exception will be returned.
    • take

      public io.activej.promise.Promise<T> take()
      Returns a promise of current value, if the put is not null.

      Sets put and value as null after the operation.

      If the put is null, sets take as a new SettablePromise and returns it. If current exception is not null, returns a promise of the exception and does nothing else.

      Specified by:
      take in interface ChannelQueue<T>
      Returns:
      a promise of the value or of null. If this exception is not null, returns a promise of exception.
    • closeEx

      public void closeEx(@NotNull @NotNull Exception e)
      Closes the buffer if this exception is not null. Recycles all elements of the buffer and sets elements, put and take to null.
      Specified by:
      closeEx in interface io.activej.async.process.AsyncCloseable
      Parameters:
      e - exception that is used to close buffer with
    • getException

      @Nullable public @Nullable Exception getException()