Class AccessBuffer<K>

  • Type Parameters:
    K - the type of keys

    public class AccessBuffer<K>
    extends Object
    A lock-free access buffer that records cache operations using ring buffers and write-ahead logging for high-performance concurrent access.

    This implementation provides:

    • Lock-Free Recording: Uses atomic operations for access tracking
    • Write-Ahead Logging: Ensures operation ordering and consistency
    • Batched Processing: Reduces contention through batch operations
    • Backpressure Handling: Manages buffer overflow gracefully
    Since:
    1.0.0
    • Constructor Detail

      • AccessBuffer

        public AccessBuffer​(int drainThreshold,
                            long drainIntervalNanos)
        Creates a new access buffer.
        Parameters:
        drainThreshold - the number of accesses that trigger a drain
        drainIntervalNanos - the maximum time between drains in nanoseconds
    • Method Detail

      • recordAccess

        public boolean recordAccess​(K key,
                                    AccessBuffer.AccessType type,
                                    int frequency)
        Records a cache access operation.
        Parameters:
        key - the cache key
        type - the access type
        frequency - the current frequency estimate
        Returns:
        true if the access was recorded
      • drainToHandler

        public int drainToHandler​(Consumer<AccessBuffer.AccessRecord<K>> processor)
        Drains the access buffer and processes all recorded accesses.
        Parameters:
        processor - the function to process each access record
        Returns:
        the number of records processed
      • forceDrain

        public int forceDrain​(Consumer<AccessBuffer.AccessRecord<K>> processor)
        Forces an immediate drain of all pending accesses.
        Parameters:
        processor - the function to process each access record
        Returns:
        the number of records processed
      • getPendingAccessCount

        public int getPendingAccessCount()
        Returns the current number of pending accesses.
        Returns:
        the number of pending accesses
      • getContentionLevel

        public long getContentionLevel()
        Returns the current contention level.
        Returns:
        the contention level
      • getStripeCount

        public int getStripeCount()
        Returns the number of stripes in the ring buffer.
        Returns:
        the stripe count
      • needsDraining

        public boolean needsDraining()
        Checks if draining is needed.
        Returns:
        true if draining is needed
      • shutdown

        public void shutdown()
        Shuts down the access buffer.
      • isShutdown

        public boolean isShutdown()
        Checks if the access buffer is shut down.
        Returns:
        true if shut down
      • clear

        public void clear()
        Clears all pending accesses.