Class DequeRequestBuffer<RequestEntryT extends Serializable>
- java.lang.Object
-
- org.apache.flink.connector.base.sink.writer.DequeRequestBuffer<RequestEntryT>
-
- All Implemented Interfaces:
RequestBuffer<RequestEntryT>
@Internal public class DequeRequestBuffer<RequestEntryT extends Serializable> extends Object implements RequestBuffer<RequestEntryT>
Default wrapper implementation that uses anArrayDequeas the underlying data structure.
-
-
Constructor Summary
Constructors Constructor Description DequeRequestBuffer()Creates an empty buffer backed by anArrayDeque.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(RequestEntryWrapper<RequestEntryT> entry, boolean prioritize)Adds a request entry to the buffer.Collection<RequestEntryWrapper<RequestEntryT>>getBufferedState()Retrieves all buffered request entries as a collection.booleanisEmpty()Checks whether the buffer is empty.RequestEntryWrapper<RequestEntryT>peek()Retrieves, but does not remove, the next available request entry from the buffer.RequestEntryWrapper<RequestEntryT>poll()Retrieves and removes the next available request entry from the buffer.intsize()Returns the number of request entries currently in the buffer.longtotalSizeInBytes()Returns the total size of all buffered request entries in bytes.
-
-
-
Constructor Detail
-
DequeRequestBuffer
public DequeRequestBuffer()
Creates an empty buffer backed by anArrayDeque.
-
-
Method Detail
-
add
public void add(RequestEntryWrapper<RequestEntryT> entry, boolean prioritize)
Adds a request entry to the buffer. Ifprioritizeis true, the entry is inserted at the front (for retries). Otherwise, it is added at the end following FIFO order.- Specified by:
addin interfaceRequestBuffer<RequestEntryT extends Serializable>- Parameters:
entry- The request entry to add.prioritize- If true, insert at the front; otherwise, add at the end.
-
peek
public RequestEntryWrapper<RequestEntryT> peek()
Retrieves, but does not remove, the next available request entry from the buffer. This allows checking the next request before processing.- Specified by:
peekin interfaceRequestBuffer<RequestEntryT extends Serializable>- Returns:
- The next request entry, or null if the buffer is empty.
-
isEmpty
public boolean isEmpty()
Checks whether the buffer is empty. Useful for determining if there are pending entries before flushing.- Specified by:
isEmptyin interfaceRequestBuffer<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:
sizein interfaceRequestBuffer<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:
getBufferedStatein interfaceRequestBuffer<RequestEntryT extends Serializable>- Returns:
- A collection of all buffered request entries.
-
poll
public RequestEntryWrapper<RequestEntryT> poll()
Retrieves and removes the next available request entry from the buffer. The removal order is determined by the implementation.- Specified by:
pollin interfaceRequestBuffer<RequestEntryT extends Serializable>- Returns:
- The removed request entry, or null if the buffer is empty.
-
totalSizeInBytes
public long totalSizeInBytes()
Returns the total size of all buffered request entries in bytes.Tracks the cumulative size of all elements in
bufferedRequestEntriesto facilitate the criterion for flushing after maxBatchSizeInBytes is reached.- Specified by:
totalSizeInBytesin interfaceRequestBuffer<RequestEntryT extends Serializable>- Returns:
- The total buffered size in bytes.
-
-