Class DequeRequestBuffer<RequestEntryT extends Serializable>

  • All Implemented Interfaces:
    RequestBuffer<RequestEntryT>

    @Internal
    public class DequeRequestBuffer<RequestEntryT extends Serializable>
    extends Object
    implements RequestBuffer<RequestEntryT>
    Default wrapper implementation that uses an ArrayDeque as the underlying data structure.
    • Constructor Detail

      • DequeRequestBuffer

        public DequeRequestBuffer()
        Creates an empty buffer backed by an ArrayDeque.
    • Method Detail

      • add

        public void add​(RequestEntryWrapper<RequestEntryT> entry,
                        boolean prioritize)
        Adds a request entry to the buffer. If prioritize is true, the entry is inserted at the front (for retries). Otherwise, it is added at the end following FIFO order.
        Specified by:
        add in interface RequestBuffer<RequestEntryT extends Serializable>
        Parameters:
        entry - The request entry to add.
        prioritize - If true, insert at the front; otherwise, add at the end.
      • isEmpty

        public boolean isEmpty()
        Checks whether the buffer is empty. Useful for determining if there are pending entries before flushing.
        Specified by:
        isEmpty in interface RequestBuffer<RequestEntryT extends Serializable>
        Returns:
        True if the buffer contains no entries, false otherwise.
      • size

        public int size()
        Returns the number of request entries currently in the buffer. Can be used for batching decisions.
        Specified by:
        size in interface RequestBuffer<RequestEntryT extends Serializable>
        Returns:
        The total number of buffered entries.
      • getBufferedState

        public Collection<RequestEntryWrapper<RequestEntryT>> getBufferedState()
        Retrieves all buffered request entries as a collection. Implementations should return a snapshot of the buffer for checkpointing.

        The returned collection:

        • Must preserve the order in which entries were added (FIFO).
        • Must not modify or clear the internal buffer.
        Specified by:
        getBufferedState in interface RequestBuffer<RequestEntryT extends Serializable>
        Returns:
        A collection of all buffered request entries.
      • totalSizeInBytes

        public long totalSizeInBytes()
        Returns the total size of all buffered request entries in bytes.

        Tracks the cumulative size of all elements in bufferedRequestEntries to facilitate the criterion for flushing after maxBatchSizeInBytes is reached.

        Specified by:
        totalSizeInBytes in interface RequestBuffer<RequestEntryT extends Serializable>
        Returns:
        The total buffered size in bytes.