Class RingBuffer<E>

  • Type Parameters:
    E - the type of elements stored in the buffer

    public class RingBuffer<E>
    extends Object
    A striped ring buffer for lock-free access recording in cache operations.

    This implementation provides high-throughput access recording by using multiple ring buffers (stripes) to reduce contention. Each thread maps to a specific stripe based on its hash, distributing the load evenly.

    Key Features:

    • Lock-Free Writes: Uses CAS operations for buffer updates
    • Striped Architecture: Multiple buffers reduce contention
    • Overflow Handling: Graceful degradation when buffers are full
    • Memory Efficient: Compact representation of buffer entries
    Since:
    1.0.0
    • Constructor Detail

      • RingBuffer

        public RingBuffer()
        Creates a new ring buffer.
    • Method Detail

      • offer

        public boolean offer​(E element)
        Attempts to add an element to the buffer.
        Parameters:
        element - the element to add
        Returns:
        true if the element was added, false if the buffer is full
      • drain

        public int drain​(Consumer<E> processor)
        Drains elements from the buffer and processes them.
        Parameters:
        processor - the function to process each element
        Returns:
        the number of elements processed
      • size

        public int size()
        Returns the current size of the buffer.
        Returns:
        the number of elements in the buffer
      • isEmpty

        public boolean isEmpty()
        Checks if the buffer is empty.
        Returns:
        true if the buffer is empty
      • isFull

        public boolean isFull()
        Checks if the buffer is full.
        Returns:
        true if the buffer is full
      • getDrainStatus

        public RingBuffer.DrainStatus getDrainStatus()
        Gets the current drain status.
        Returns:
        the drain status
      • clear

        public void clear()
        Clears all elements from the buffer.