A high-performance, non-blocking Multi-Producer Single-Consumer (MPSC) ring buffer for generic reference types.
Multiple threads may call offer concurrently, but only a single consumer thread may call take. This is enforced by contract — no runtime check is performed for the single-consumer invariant.
The algorithm follows the JCTools MpscArrayQueue design:
- Producers claim a slot via CAS on
producerIndex, then write the element with release semantics. - The consumer reads elements using acquire semantics. A
nullslot indicates either an empty queue or a producer that has claimed a slot but has not yet written the element (the "FastFlow" pattern). In the latter case,takereturnsnullrather than spinning, followingrelaxedPollsemantics. - A cached
producerLimitavoids readingconsumerIndexon every offer, reducing cross-core traffic.
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
- MpscRingBuffer.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. Uses relaxed poll semantics: stops at the first null slot (either empty or producer mid-write).
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
- MpscRingBuffer.scala
Returns true if the buffer appears to contain no elements (approximate under concurrency).
Returns true if the buffer appears to contain no elements (approximate under concurrency).
Attributes
- Source
- MpscRingBuffer.scala
Returns true if the buffer appears to be full (approximate under concurrency).
Returns true if the buffer appears to be full (approximate under concurrency).
Attributes
- Source
- MpscRingBuffer.scala
Tries to insert an element into the buffer without blocking.
Tries to insert an element into the buffer without blocking.
Any thread may call this method concurrently. The implementation uses a CAS loop to claim a slot in the circular buffer, then writes the element with release semantics.
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 - Source
- MpscRingBuffer.scala
Returns the approximate number of elements currently in the buffer.
Returns the approximate number of elements currently in the buffer.
Under concurrent access this value is a snapshot and may be stale by the time the caller observes it.
Attributes
- Source
- MpscRingBuffer.scala
Tries to remove an element from the buffer without blocking.
Tries to remove an element from the buffer without blocking.
Uses the FastFlow pattern: reads the array slot directly with acquire semantics. A null value means either the buffer is empty or a producer has claimed the slot but has not yet written the element. In both cases, null is returned (relaxed poll semantics).
Attributes
- Returns
-
the element, or
nullif the buffer is empty (or a producer is mid-write) - Note
-
Must be called from the consumer thread only.
- Source
- MpscRingBuffer.scala
Concrete fields
Attributes
- Source
- MpscRingBuffer.scala
Inherited fields
Attributes
- Inherited from:
- MpscConsumerFields (hidden)
- Source
- MpscRingBuffer.scala
Attributes
- Inherited from:
- MpscPad0 (hidden)
- Source
- MpscRingBuffer.scala
Attributes
- Inherited from:
- MpscPad0 (hidden)
- Source
- MpscRingBuffer.scala
Attributes
- Inherited from:
- MpscPad0 (hidden)
- Source
- MpscRingBuffer.scala
Attributes
- Inherited from:
- MpscPad0 (hidden)
- Source
- MpscRingBuffer.scala
Attributes
- Inherited from:
- MpscPad0 (hidden)
- Source
- MpscRingBuffer.scala
Attributes
- Inherited from:
- MpscPad0 (hidden)
- Source
- MpscRingBuffer.scala
Attributes
- Inherited from:
- MpscPad0 (hidden)
- Source
- MpscRingBuffer.scala
Attributes
- Inherited from:
- MpscPad0 (hidden)
- Source
- MpscRingBuffer.scala
Attributes
- Inherited from:
- MpscPad0 (hidden)
- Source
- MpscRingBuffer.scala
Attributes
- Inherited from:
- MpscPad0 (hidden)
- Source
- MpscRingBuffer.scala
Attributes
- Inherited from:
- MpscPad0 (hidden)
- Source
- MpscRingBuffer.scala
Attributes
- Inherited from:
- MpscPad0 (hidden)
- Source
- MpscRingBuffer.scala
Attributes
- Inherited from:
- MpscPad0 (hidden)
- Source
- MpscRingBuffer.scala
Attributes
- Inherited from:
- MpscPad0 (hidden)
- Source
- MpscRingBuffer.scala
Attributes
- Inherited from:
- MpscPad0 (hidden)
- Source
- MpscRingBuffer.scala
Attributes
- Inherited from:
- MpscPad0 (hidden)
- Source
- MpscRingBuffer.scala
Attributes
- Inherited from:
- MpscPad1 (hidden)
- Source
- MpscRingBuffer.scala
Attributes
- Inherited from:
- MpscPad1 (hidden)
- Source
- MpscRingBuffer.scala
Attributes
- Inherited from:
- MpscPad1 (hidden)
- Source
- MpscRingBuffer.scala
Attributes
- Inherited from:
- MpscPad1 (hidden)
- Source
- MpscRingBuffer.scala
Attributes
- Inherited from:
- MpscPad1 (hidden)
- Source
- MpscRingBuffer.scala
Attributes
- Inherited from:
- MpscPad1 (hidden)
- Source
- MpscRingBuffer.scala
Attributes
- Inherited from:
- MpscPad1 (hidden)
- Source
- MpscRingBuffer.scala
Attributes
- Inherited from:
- MpscPad1 (hidden)
- Source
- MpscRingBuffer.scala
Attributes
- Inherited from:
- MpscPad1 (hidden)
- Source
- MpscRingBuffer.scala
Attributes
- Inherited from:
- MpscPad1 (hidden)
- Source
- MpscRingBuffer.scala
Attributes
- Inherited from:
- MpscPad1 (hidden)
- Source
- MpscRingBuffer.scala
Attributes
- Inherited from:
- MpscPad1 (hidden)
- Source
- MpscRingBuffer.scala
Attributes
- Inherited from:
- MpscPad1 (hidden)
- Source
- MpscRingBuffer.scala
Attributes
- Inherited from:
- MpscPad1 (hidden)
- Source
- MpscRingBuffer.scala
Attributes
- Inherited from:
- MpscPad1 (hidden)
- Source
- MpscRingBuffer.scala
Attributes
- Inherited from:
- MpscPad1 (hidden)
- Source
- MpscRingBuffer.scala
Attributes
- Inherited from:
- MpscPad2 (hidden)
- Source
- MpscRingBuffer.scala
Attributes
- Inherited from:
- MpscPad2 (hidden)
- Source
- MpscRingBuffer.scala
Attributes
- Inherited from:
- MpscPad2 (hidden)
- Source
- MpscRingBuffer.scala
Attributes
- Inherited from:
- MpscPad2 (hidden)
- Source
- MpscRingBuffer.scala
Attributes
- Inherited from:
- MpscPad2 (hidden)
- Source
- MpscRingBuffer.scala
Attributes
- Inherited from:
- MpscPad2 (hidden)
- Source
- MpscRingBuffer.scala
Attributes
- Inherited from:
- MpscPad2 (hidden)
- Source
- MpscRingBuffer.scala
Attributes
- Inherited from:
- MpscPad2 (hidden)
- Source
- MpscRingBuffer.scala
Attributes
- Inherited from:
- MpscPad2 (hidden)
- Source
- MpscRingBuffer.scala
Attributes
- Inherited from:
- MpscPad2 (hidden)
- Source
- MpscRingBuffer.scala
Attributes
- Inherited from:
- MpscPad2 (hidden)
- Source
- MpscRingBuffer.scala
Attributes
- Inherited from:
- MpscPad2 (hidden)
- Source
- MpscRingBuffer.scala
Attributes
- Inherited from:
- MpscPad2 (hidden)
- Source
- MpscRingBuffer.scala
Attributes
- Inherited from:
- MpscPad2 (hidden)
- Source
- MpscRingBuffer.scala
Attributes
- Inherited from:
- MpscPad2 (hidden)
- Source
- MpscRingBuffer.scala
Attributes
- Inherited from:
- MpscPad2 (hidden)
- Source
- MpscRingBuffer.scala
Attributes
- Inherited from:
- MpscPad3 (hidden)
- Source
- MpscRingBuffer.scala
Attributes
- Inherited from:
- MpscPad3 (hidden)
- Source
- MpscRingBuffer.scala
Attributes
- Inherited from:
- MpscPad3 (hidden)
- Source
- MpscRingBuffer.scala
Attributes
- Inherited from:
- MpscPad3 (hidden)
- Source
- MpscRingBuffer.scala
Attributes
- Inherited from:
- MpscPad3 (hidden)
- Source
- MpscRingBuffer.scala
Attributes
- Inherited from:
- MpscPad3 (hidden)
- Source
- MpscRingBuffer.scala
Attributes
- Inherited from:
- MpscPad3 (hidden)
- Source
- MpscRingBuffer.scala
Attributes
- Inherited from:
- MpscPad3 (hidden)
- Source
- MpscRingBuffer.scala
Attributes
- Inherited from:
- MpscPad3 (hidden)
- Source
- MpscRingBuffer.scala
Attributes
- Inherited from:
- MpscPad3 (hidden)
- Source
- MpscRingBuffer.scala
Attributes
- Inherited from:
- MpscPad3 (hidden)
- Source
- MpscRingBuffer.scala
Attributes
- Inherited from:
- MpscPad3 (hidden)
- Source
- MpscRingBuffer.scala
Attributes
- Inherited from:
- MpscPad3 (hidden)
- Source
- MpscRingBuffer.scala
Attributes
- Inherited from:
- MpscPad3 (hidden)
- Source
- MpscRingBuffer.scala
Attributes
- Inherited from:
- MpscPad3 (hidden)
- Source
- MpscRingBuffer.scala
Attributes
- Inherited from:
- MpscPad3 (hidden)
- Source
- MpscRingBuffer.scala
Attributes
- Inherited from:
- MpscProducerFields (hidden)
- Source
- MpscRingBuffer.scala
Attributes
- Inherited from:
- MpscProducerLimitFields (hidden)
- Source
- MpscRingBuffer.scala