Package org.jctools.channels.mpsc
Class MpscFFLamportOffHeapFixedSizeRingBuffer
- java.lang.Object
-
- org.jctools.channels.proxy.ProxyChannelRingBuffer
-
- org.jctools.channels.OffHeapFixedMessageSizeRingBuffer
-
- org.jctools.channels.mpsc.MpscFFLamportOffHeapFixedSizeRingBuffer
-
public final class MpscFFLamportOffHeapFixedSizeRingBuffer extends OffHeapFixedMessageSizeRingBuffer
A Multi-Producer-Single-Consumer ring buffer. This implies that any thread may call the write methods, but only a single thread may call reads for correctness to maintained.
This implementation follows patterns for False Sharing protection.
This implementation is using the Fast Flow method for polling from the queue (with minor change to correctly publish the index) and an extension of the Leslie Lamport concurrent queue algorithm (originated by Martin Thompson) on the producer side.
-
-
Field Summary
Fields Modifier and Type Field Description private longconsumerIndexCacheAddress-
Fields inherited from class org.jctools.channels.OffHeapFixedMessageSizeRingBuffer
bufferAddress, consumerIndexAddress, HEADER_SIZE, mask, MESSAGE_INDICATOR_SIZE, messageSize, producerIndexAddress, READ_ACQUIRE_INDICATOR, READ_RELEASE_INDICATOR, referenceMessageSize, references, WRITE_ACQUIRE_INDICATOR, WRITE_RELEASE_INDICATOR
-
Fields inherited from class org.jctools.channels.proxy.ProxyChannelRingBuffer
EOF
-
-
Constructor Summary
Constructors Modifier Constructor Description MpscFFLamportOffHeapFixedSizeRingBuffer(int capacity, int primitiveMessageSize, int referenceMessageSize)protectedMpscFFLamportOffHeapFixedSizeRingBuffer(java.nio.ByteBuffer buff, int capacity, boolean isProducer, boolean isConsumer, boolean initialize, int primitiveMessageSize, java.lang.Object[] references, int referenceMessageSize)This is to be used for an IPC queue with the direct buffer used being a memory mapped file.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private booleancasProducerIndex(long expected, long update)private longlpConsumerIndexCache()protected longreadAcquire()Acquire an offset to read fromprotected voidreadRelease(long offset)Release the offset from readingprivate longslowPathWriteAcquire(long wrapPoint)private voidspConsumerIndexCache(long value)private static voidspReadReleaseState(long offset)protected longwriteAcquire()Acquire an offset to write to.protected voidwriteRelease(long offset)protected voidwriteRelease(long offset, int callTypeId)Ordered store of the callTypeId for the message at offset-
Methods inherited from class org.jctools.channels.OffHeapFixedMessageSizeRingBuffer
arrayIndexForCursor, arrayIndexForCursor, capacity, consumerReferenceArrayIndex, createReferenceArray, getRequiredArraySize, getRequiredBufferSize, isEmpty, isReadReleased, lpConsumerIndex, lpProducerIndex, lvConsumerIndex, lvProducerIndex, offsetForIndex, offsetForIndex, producerReferenceArrayIndex, readAcquireState, readReference, readReleaseState, relativeIndexForOffset, relativeIndexForOffset, size, soConsumerIndex, soProducerIndex, writeAcquireState, writeReference, writeReleaseState
-
-
-
-
Constructor Detail
-
MpscFFLamportOffHeapFixedSizeRingBuffer
public MpscFFLamportOffHeapFixedSizeRingBuffer(int capacity, int primitiveMessageSize, int referenceMessageSize)
-
MpscFFLamportOffHeapFixedSizeRingBuffer
protected MpscFFLamportOffHeapFixedSizeRingBuffer(java.nio.ByteBuffer buff, int capacity, boolean isProducer, boolean isConsumer, boolean initialize, int primitiveMessageSize, java.lang.Object[] references, int referenceMessageSize)This is to be used for an IPC queue with the direct buffer used being a memory mapped file.- Parameters:
buff-capacity-
-
-
Method Detail
-
slowPathWriteAcquire
private long slowPathWriteAcquire(long wrapPoint)
-
writeAcquire
protected final long writeAcquire()
Description copied from class:ProxyChannelRingBufferAcquire an offset to write to. If there's no space available a wait strategy may be used.- Specified by:
writeAcquirein classOffHeapFixedMessageSizeRingBuffer- Returns:
- a base address for a message acquired to be written, or EOF if none is available
-
writeRelease
protected final void writeRelease(long offset)
- Specified by:
writeReleasein classOffHeapFixedMessageSizeRingBuffer- Parameters:
offset- the base address of a message that we are done writing and can be read now
-
writeRelease
protected final void writeRelease(long offset, int callTypeId)Description copied from class:ProxyChannelRingBufferOrdered store of the callTypeId for the message at offset- Specified by:
writeReleasein classProxyChannelRingBuffer- Parameters:
offset- the offset that was released for writingcallTypeId- A unique ID for the call
-
readAcquire
protected final long readAcquire()
Description copied from class:ProxyChannelRingBufferAcquire an offset to read from- Specified by:
readAcquirein classOffHeapFixedMessageSizeRingBuffer- Returns:
- a base address for a message acquired to be read, or EOF if none is available
-
readRelease
protected final void readRelease(long offset)
Description copied from class:ProxyChannelRingBufferRelease the offset from reading- Specified by:
readReleasein classOffHeapFixedMessageSizeRingBuffer- Parameters:
offset- the base address of a message that we are done reading and can be overwritten now
-
casProducerIndex
private boolean casProducerIndex(long expected, long update)
-
lpConsumerIndexCache
private long lpConsumerIndexCache()
-
spConsumerIndexCache
private void spConsumerIndexCache(long value)
-
spReadReleaseState
private static void spReadReleaseState(long offset)
-
-