Interface CloseableReadonlyBuffer<T>

    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      int capacity()
      Returns the overall capacity of this buffer.
      boolean closed()
      Indicates whether the buffer is closed by the producing side.
      Optional<ErrorMessage> error()
      Returns an error from this buffer, if any.
      boolean isEmpty()
      Indicates whether there are messages in the buffer.
      void onAvailable​(Runnable onAvailable)
      Registers an action to be triggered when there is a new message added to the buffer, or the buffer is closed, or the buffer is closed with an error.
      Optional<T> poll()
      Polls the message from this buffer.
    • Method Detail

      • poll

        Optional<T> poll()
        Polls the message from this buffer. If the returned Optional is empty, that doesn't mean that this buffer stays empty forever. The closed() method should be consolidated to validate this.
        Returns:
        an Optional with polled message
      • isEmpty

        boolean isEmpty()
        Indicates whether there are messages in the buffer. If this returns false, that doesn't mean that this buffer stays empty forever. The closed() method should be consolidated to validate this.
        Returns:
        true if buffer is empty, false otherwise
      • capacity

        int capacity()
        Returns the overall capacity of this buffer.
        Returns:
        the overall capacity of this buffer
      • onAvailable

        void onAvailable​(Runnable onAvailable)
        Registers an action to be triggered when there is a new message added to the buffer, or the buffer is closed, or the buffer is closed with an error. The action can check poll(), closed(), and error() to validate this.
        Parameters:
        onAvailable - to be invoked when there are changes in this buffer
      • closed

        boolean closed()
        Indicates whether the buffer is closed by the producing side.
        Returns:
        true if closed, false otherwise