Class ChannelZeroBuffer<T>

java.lang.Object
io.activej.reactor.AbstractReactive
io.activej.reactor.ImplicitlyReactive
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>, io.activej.reactor.Reactive

public final class ChannelZeroBuffer<T> extends io.activej.reactor.ImplicitlyReactive 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.
  • Field Summary

    Fields inherited from class io.activej.reactor.AbstractReactive

    reactor

    Fields inherited from interface io.activej.async.process.AsyncCloseable

    STATIC
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Closes the buffer if this exception is not null.
    @Nullable Exception
     
    boolean
     
    boolean
     
    io.activej.promise.Promise<Void>
    put(T item)
    Sets the provided value to current value, then sets put as a new SettablePromise and returns it.
    io.activej.promise.Promise<T>
    Returns a promise of current value, if the put is not null.

    Methods inherited from class io.activej.reactor.AbstractReactive

    getReactor

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface io.activej.async.process.AsyncCloseable

    close

    Methods 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:
      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(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()