A high-performance, non-blocking SPSC ring buffer for generic reference types.
Uses the FastFlow pattern: the array element's null/non-null state IS the synchronization signal. The producer never reads consumerIndex; the consumer never reads producerIndex. This minimizes cross-core cache traffic.
Optimized for SPSC (Single Producer, Single Consumer). Only one producer thread and one consumer thread should access the buffer concurrently.
Null elements are not permitted. offer(null) throws NullPointerException.
Value parameters
- capacity
-
the buffer capacity, must be a positive power of two
Attributes
- Companion
- object
- Source
- SpscRingBuffer.scala
- Graph
-
- Supertypes
Members list
Value members
Concrete methods
Drains up to limit elements from the buffer, passing each to the given consumer callback.
Drains up to limit elements from the buffer, passing each to the given consumer callback.
Elements are consumed in FIFO order. The consumer index is advanced after each element is passed to the callback, so if the callback throws, all previously consumed elements remain consumed and the buffer is in a consistent state.
Value parameters
- consumer
-
the callback invoked for each drained element
- limit
-
the maximum number of elements to drain; must be non-negative
Attributes
- Returns
-
the number of elements actually drained (0 if the buffer is empty)
- Throws
-
java.lang.IllegalArgumentException
if
limitis negative - Note
-
Must be called from the consumer thread only.
- Source
- SpscRingBuffer.scala
Fills up to limit slots in the buffer by calling the supplier for each new element.
Fills up to limit slots in the buffer by calling the supplier for each new element.
Elements are inserted in order. The producer index is advanced after each element is stored. If the supplier throws, all previously inserted elements remain in the buffer.
Value parameters
- limit
-
the maximum number of elements to insert; must be non-negative
- supplier
-
the callback invoked to produce each new element; must not return
null
Attributes
- Returns
-
the number of elements actually inserted (0 if the buffer is full)
- Throws
-
java.lang.IllegalArgumentException
if
limitis negativejava.lang.NullPointerExceptionif the supplier returns
null - Note
-
Must be called from the producer thread only.
- Source
- SpscRingBuffer.scala
Returns true if the buffer contains no elements (approximate under concurrency).
Returns true if the buffer contains no elements (approximate under concurrency).
Attributes
- Source
- SpscRingBuffer.scala
Returns true if the buffer is full (approximate under concurrency).
Returns true if the buffer is full (approximate under concurrency).
Attributes
- Source
- SpscRingBuffer.scala
Tries to insert an element into the buffer without blocking.
Tries to insert an element into the buffer without blocking.
Value parameters
- a
-
the element to insert; must not be
null
Attributes
- Returns
-
trueif the element was successfully inserted,falseif the buffer is full - Throws
-
java.lang.NullPointerException
if the element is
null - Note
-
Must be called from the producer thread only.
- Source
- SpscRingBuffer.scala
Returns the number of elements currently in the buffer (approximate under concurrency).
Returns the number of elements currently in the buffer (approximate under concurrency).
Attributes
- Source
- SpscRingBuffer.scala
Tries to remove an element from the buffer without blocking. Uses FastFlow: reads the array slot directly. Null = empty, non-null = data available.
Tries to remove an element from the buffer without blocking. Uses FastFlow: reads the array slot directly. Null = empty, non-null = data available.
Attributes
- Returns
-
the element, or
nullif the buffer is empty - Note
-
Must be called from the consumer thread only.
- Source
- SpscRingBuffer.scala
Concrete fields
Attributes
- Source
- SpscRingBuffer.scala
Inherited fields
Attributes
- Inherited from:
- SpscConsumerFields (hidden)
- Source
- SpscRingBuffer.scala
Attributes
- Inherited from:
- SpscPad0 (hidden)
- Source
- SpscRingBuffer.scala
Attributes
- Inherited from:
- SpscPad0 (hidden)
- Source
- SpscRingBuffer.scala
Attributes
- Inherited from:
- SpscPad0 (hidden)
- Source
- SpscRingBuffer.scala
Attributes
- Inherited from:
- SpscPad0 (hidden)
- Source
- SpscRingBuffer.scala
Attributes
- Inherited from:
- SpscPad0 (hidden)
- Source
- SpscRingBuffer.scala
Attributes
- Inherited from:
- SpscPad0 (hidden)
- Source
- SpscRingBuffer.scala
Attributes
- Inherited from:
- SpscPad0 (hidden)
- Source
- SpscRingBuffer.scala
Attributes
- Inherited from:
- SpscPad0 (hidden)
- Source
- SpscRingBuffer.scala
Attributes
- Inherited from:
- SpscPad0 (hidden)
- Source
- SpscRingBuffer.scala
Attributes
- Inherited from:
- SpscPad0 (hidden)
- Source
- SpscRingBuffer.scala
Attributes
- Inherited from:
- SpscPad0 (hidden)
- Source
- SpscRingBuffer.scala
Attributes
- Inherited from:
- SpscPad0 (hidden)
- Source
- SpscRingBuffer.scala
Attributes
- Inherited from:
- SpscPad0 (hidden)
- Source
- SpscRingBuffer.scala
Attributes
- Inherited from:
- SpscPad0 (hidden)
- Source
- SpscRingBuffer.scala
Attributes
- Inherited from:
- SpscPad0 (hidden)
- Source
- SpscRingBuffer.scala
Attributes
- Inherited from:
- SpscPad0 (hidden)
- Source
- SpscRingBuffer.scala
Attributes
- Inherited from:
- SpscPad1 (hidden)
- Source
- SpscRingBuffer.scala
Attributes
- Inherited from:
- SpscPad1 (hidden)
- Source
- SpscRingBuffer.scala
Attributes
- Inherited from:
- SpscPad1 (hidden)
- Source
- SpscRingBuffer.scala
Attributes
- Inherited from:
- SpscPad1 (hidden)
- Source
- SpscRingBuffer.scala
Attributes
- Inherited from:
- SpscPad1 (hidden)
- Source
- SpscRingBuffer.scala
Attributes
- Inherited from:
- SpscPad1 (hidden)
- Source
- SpscRingBuffer.scala
Attributes
- Inherited from:
- SpscPad1 (hidden)
- Source
- SpscRingBuffer.scala
Attributes
- Inherited from:
- SpscPad1 (hidden)
- Source
- SpscRingBuffer.scala
Attributes
- Inherited from:
- SpscPad1 (hidden)
- Source
- SpscRingBuffer.scala
Attributes
- Inherited from:
- SpscPad1 (hidden)
- Source
- SpscRingBuffer.scala
Attributes
- Inherited from:
- SpscPad1 (hidden)
- Source
- SpscRingBuffer.scala
Attributes
- Inherited from:
- SpscPad1 (hidden)
- Source
- SpscRingBuffer.scala
Attributes
- Inherited from:
- SpscPad1 (hidden)
- Source
- SpscRingBuffer.scala
Attributes
- Inherited from:
- SpscPad1 (hidden)
- Source
- SpscRingBuffer.scala
Attributes
- Inherited from:
- SpscPad1 (hidden)
- Source
- SpscRingBuffer.scala
Attributes
- Inherited from:
- SpscPad1 (hidden)
- Source
- SpscRingBuffer.scala
Attributes
- Inherited from:
- SpscPad2 (hidden)
- Source
- SpscRingBuffer.scala
Attributes
- Inherited from:
- SpscPad2 (hidden)
- Source
- SpscRingBuffer.scala
Attributes
- Inherited from:
- SpscPad2 (hidden)
- Source
- SpscRingBuffer.scala
Attributes
- Inherited from:
- SpscPad2 (hidden)
- Source
- SpscRingBuffer.scala
Attributes
- Inherited from:
- SpscPad2 (hidden)
- Source
- SpscRingBuffer.scala
Attributes
- Inherited from:
- SpscPad2 (hidden)
- Source
- SpscRingBuffer.scala
Attributes
- Inherited from:
- SpscPad2 (hidden)
- Source
- SpscRingBuffer.scala
Attributes
- Inherited from:
- SpscPad2 (hidden)
- Source
- SpscRingBuffer.scala
Attributes
- Inherited from:
- SpscPad2 (hidden)
- Source
- SpscRingBuffer.scala
Attributes
- Inherited from:
- SpscPad2 (hidden)
- Source
- SpscRingBuffer.scala
Attributes
- Inherited from:
- SpscPad2 (hidden)
- Source
- SpscRingBuffer.scala
Attributes
- Inherited from:
- SpscPad2 (hidden)
- Source
- SpscRingBuffer.scala
Attributes
- Inherited from:
- SpscPad2 (hidden)
- Source
- SpscRingBuffer.scala
Attributes
- Inherited from:
- SpscPad2 (hidden)
- Source
- SpscRingBuffer.scala
Attributes
- Inherited from:
- SpscPad2 (hidden)
- Source
- SpscRingBuffer.scala
Attributes
- Inherited from:
- SpscPad2 (hidden)
- Source
- SpscRingBuffer.scala
Attributes
- Inherited from:
- SpscProducerFields (hidden)
- Source
- SpscRingBuffer.scala
Attributes
- Inherited from:
- SpscProducerFields (hidden)
- Source
- SpscRingBuffer.scala