Package org.jctools.channels
Class OffHeapFixedMessageSizeRingBuffer
- java.lang.Object
-
- org.jctools.channels.proxy.ProxyChannelRingBuffer
-
- org.jctools.channels.OffHeapFixedMessageSizeRingBuffer
-
- Direct Known Subclasses:
MpscFFLamportOffHeapFixedSizeRingBuffer,MpscOffHeapFixedSizeRingBuffer,SpscOffHeapFixedSizeRingBuffer
public abstract class OffHeapFixedMessageSizeRingBuffer extends ProxyChannelRingBuffer
Channel protocol: - Fixed message size - 'null' indicator in message preceding byte (potentially use same for type mapping in future) - Use FF algorithm relying on indicator to support in place detection of next element existence
-
-
Field Summary
Fields Modifier and Type Field Description protected longbufferAddressprivate java.nio.ByteBufferbuffyprotected longconsumerIndexAddressstatic intHEADER_SIZEprotected longmaskstatic byteMESSAGE_INDICATOR_SIZEprotected intmessageSizeprotected longproducerIndexAddressstatic intREAD_ACQUIRE_INDICATORstatic intREAD_RELEASE_INDICATORprotected intreferenceMessageSizeprotected java.lang.Object[]referencesstatic intWRITE_ACQUIRE_INDICATORstatic intWRITE_RELEASE_INDICATOR-
Fields inherited from class org.jctools.channels.proxy.ProxyChannelRingBuffer
EOF
-
-
Constructor Summary
Constructors Modifier Constructor Description OffHeapFixedMessageSizeRingBuffer(int capacity, int primitiveMessageSize, int referenceMessageSize)protectedOffHeapFixedMessageSizeRingBuffer(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 Abstract Methods Concrete Methods Modifier and Type Method Description protected longarrayIndexForCursor(long currentHead)protected static longarrayIndexForCursor(long mask, int referenceMessageSize, long currentHead)intcapacity()protected longconsumerReferenceArrayIndex(long offset)Get the position index of the consumer in the reference arrayprotected static java.lang.Object[]createReferenceArray(int capacity, int referenceMessageSize)static intgetRequiredArraySize(int capacity, int primitiveMessageSize)static intgetRequiredBufferSize(int capacity, int messageSize)booleanisEmpty()protected booleanisReadReleased(long offset)protected longlpConsumerIndex()protected longlpProducerIndex()protected longlvConsumerIndex()protected longlvProducerIndex()protected longoffsetForIndex(long currentHead)protected static longoffsetForIndex(long bufferAddress, long mask, int messageSize, long currentHead)protected longproducerReferenceArrayIndex(long offset)Get the position index of the producer in the reference arrayprotected abstract longreadAcquire()Acquire an offset to read fromprotected voidreadAcquireState(long offset)protected java.lang.ObjectreadReference(long offset)Read a reference at the given positionprotected abstract voidreadRelease(long offset)Release the offset from readingprotected voidreadReleaseState(long offset)protected longrelativeIndexForOffset(long offset)protected static longrelativeIndexForOffset(long bufferAddress, int messageSize, long offset)Computes an index relative to the buffer start for an offset.intsize()protected voidsoConsumerIndex(long value)protected voidsoProducerIndex(long value)protected abstract longwriteAcquire()Acquire an offset to write to.protected voidwriteAcquireState(long offset)protected voidwriteReference(long offset, java.lang.Object reference)Write a reference to the given positionprotected abstract voidwriteRelease(long offset)protected voidwriteReleaseState(long offset)-
Methods inherited from class org.jctools.channels.proxy.ProxyChannelRingBuffer
writeRelease
-
-
-
-
Field Detail
-
READ_RELEASE_INDICATOR
public static final int READ_RELEASE_INDICATOR
- See Also:
- Constant Field Values
-
READ_ACQUIRE_INDICATOR
public static final int READ_ACQUIRE_INDICATOR
- See Also:
- Constant Field Values
-
WRITE_RELEASE_INDICATOR
public static final int WRITE_RELEASE_INDICATOR
- See Also:
- Constant Field Values
-
WRITE_ACQUIRE_INDICATOR
public static final int WRITE_ACQUIRE_INDICATOR
- See Also:
- Constant Field Values
-
MESSAGE_INDICATOR_SIZE
public static final byte MESSAGE_INDICATOR_SIZE
- See Also:
- Constant Field Values
-
HEADER_SIZE
public static final int HEADER_SIZE
-
buffy
private final java.nio.ByteBuffer buffy
-
bufferAddress
protected final long bufferAddress
-
consumerIndexAddress
protected final long consumerIndexAddress
-
producerIndexAddress
protected final long producerIndexAddress
-
mask
protected final long mask
-
messageSize
protected final int messageSize
-
references
protected final java.lang.Object[] references
-
referenceMessageSize
protected final int referenceMessageSize
-
-
Constructor Detail
-
OffHeapFixedMessageSizeRingBuffer
public OffHeapFixedMessageSizeRingBuffer(int capacity, int primitiveMessageSize, int referenceMessageSize)
-
OffHeapFixedMessageSizeRingBuffer
protected OffHeapFixedMessageSizeRingBuffer(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- in messages, actual capacity will beprimitiveMessageSize-
-
-
Method Detail
-
getRequiredBufferSize
public static int getRequiredBufferSize(int capacity, int messageSize)
-
createReferenceArray
protected static java.lang.Object[] createReferenceArray(int capacity, int referenceMessageSize)
-
getRequiredArraySize
public static int getRequiredArraySize(int capacity, int primitiveMessageSize)
-
capacity
public final int capacity()
-
size
public final int size()
-
isEmpty
public final boolean isEmpty()
-
isReadReleased
protected final boolean isReadReleased(long offset)
-
writeReleaseState
protected final void writeReleaseState(long offset)
-
readReleaseState
protected final void readReleaseState(long offset)
-
writeAcquireState
protected final void writeAcquireState(long offset)
-
readAcquireState
protected final void readAcquireState(long offset)
-
offsetForIndex
protected final long offsetForIndex(long currentHead)
-
offsetForIndex
protected static long offsetForIndex(long bufferAddress, long mask, int messageSize, long currentHead)
-
relativeIndexForOffset
protected final long relativeIndexForOffset(long offset)
-
relativeIndexForOffset
protected static long relativeIndexForOffset(long bufferAddress, int messageSize, long offset)Computes an index relative to the buffer start for an offset. This does not recover the original index because that is a very hard problem.- Parameters:
bufferAddress-messageSize-offset-- Returns:
-
lpConsumerIndex
protected final long lpConsumerIndex()
-
lvConsumerIndex
protected final long lvConsumerIndex()
-
soConsumerIndex
protected final void soConsumerIndex(long value)
-
lpProducerIndex
protected final long lpProducerIndex()
-
lvProducerIndex
protected final long lvProducerIndex()
-
soProducerIndex
protected final void soProducerIndex(long value)
-
arrayIndexForCursor
protected final long arrayIndexForCursor(long currentHead)
-
arrayIndexForCursor
protected static long arrayIndexForCursor(long mask, int referenceMessageSize, long currentHead)
-
consumerReferenceArrayIndex
protected long consumerReferenceArrayIndex(long offset)
Description copied from class:ProxyChannelRingBufferGet the position index of the consumer in the reference array- Specified by:
consumerReferenceArrayIndexin classProxyChannelRingBuffer- Parameters:
offset- the current offset of the consumer returned fromProxyChannelRingBuffer.readAcquire()- Returns:
- the consumer index
-
producerReferenceArrayIndex
protected long producerReferenceArrayIndex(long offset)
Description copied from class:ProxyChannelRingBufferGet the position index of the producer in the reference array- Specified by:
producerReferenceArrayIndexin classProxyChannelRingBuffer- Parameters:
offset- the current offset of the producer returned fromProxyChannelRingBuffer.writeAcquire()- Returns:
- the producer index
-
writeReference
protected void writeReference(long offset, java.lang.Object reference)Write a reference to the given position- Specified by:
writeReferencein classProxyChannelRingBuffer- Parameters:
offset- index into the reference arrayreference-
-
readReference
protected java.lang.Object readReference(long offset)
Read a reference at the given position- Specified by:
readReferencein classProxyChannelRingBuffer- Parameters:
offset- index into the reference array- Returns:
-
readAcquire
protected abstract long readAcquire()
Description copied from class:ProxyChannelRingBufferAcquire an offset to read from- Specified by:
readAcquirein classProxyChannelRingBuffer- Returns:
- a base address for a message acquired to be read, or EOF if none is available
-
readRelease
protected abstract void readRelease(long offset)
Description copied from class:ProxyChannelRingBufferRelease the offset from reading- Specified by:
readReleasein classProxyChannelRingBuffer- Parameters:
offset- the base address of a message that we are done reading and can be overwritten now
-
writeAcquire
protected abstract 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 classProxyChannelRingBuffer- Returns:
- a base address for a message acquired to be written, or EOF if none is available
-
writeRelease
protected abstract void writeRelease(long offset)
- Parameters:
offset- the base address of a message that we are done writing and can be read now
-
-