@Test public void tryClaimReturnsOffsetAtWhichMessageBodyCanBeWritten() { final int msgTypeId = MSG_TYPE_ID; final int length = 333; final int recordLength = HEADER_LENGTH + length; final int alignedRecordLength = align(recordLength, ALIGNMENT); final int index = ringBuffer.tryClaim(msgTypeId, length); assertEquals(HEADER_LENGTH, index); final InOrder inOrder = inOrder(buffer); inOrder.verify(buffer).putLong(alignedRecordLength, 0L); inOrder.verify(buffer).putLongOrdered(TAIL_COUNTER_INDEX, alignedRecordLength); inOrder.verify(buffer).putInt(typeOffset(0), msgTypeId); inOrder.verify(buffer).putInt(lengthOffset(0), -recordLength); }
public int tryClaim(final int msgTypeId, final int length) { checkTypeId(msgTypeId); checkMsgLength(length); final AtomicBuffer buffer = this.buffer; final int recordLength = length + HEADER_LENGTH; final int recordIndex = claimCapacity(buffer, recordLength); if (INSUFFICIENT_CAPACITY == recordIndex) { return recordIndex; } buffer.putInt(typeOffset(recordIndex), msgTypeId); buffer.putInt(lengthOffset(recordIndex), -recordLength); return encodedMsgOffset(recordIndex); }
OneToOneRingBuffer implements RingBuffer { public int tryClaim(final int msgTypeId, final int length) { checkTypeId(msgTypeId); checkMsgLength(length); final AtomicBuffer buffer = this.buffer; final int recordLength = length + HEADER_LENGTH; final int recordIndex = claimCapacity(buffer, recordLength); if (INSUFFICIENT_CAPACITY == recordIndex) { return recordIndex; } buffer.putInt(typeOffset(recordIndex), msgTypeId); buffer.putInt(lengthOffset(recordIndex), -recordLength); return encodedMsgOffset(recordIndex); } }
OneToOneRingBuffer implements RingBuffer { public int tryClaim(final int msgTypeId, final int length) { checkTypeId(msgTypeId); checkMsgLength(length); final AtomicBuffer buffer = this.buffer; final int recordLength = length + HEADER_LENGTH; final int recordIndex = claimCapacity(buffer, recordLength); if (INSUFFICIENT_CAPACITY == recordIndex) { return recordIndex; } buffer.putInt(typeOffset(recordIndex), msgTypeId); buffer.putInt(lengthOffset(recordIndex), -recordLength); return encodedMsgOffset(recordIndex); } OneToOneRingBuffer(final AtomicBuffer buffer); }
OneToOneRingBuffer implements RingBuffer { public int tryClaim(final int msgTypeId, final int length) { checkTypeId(msgTypeId); checkMsgLength(length); final AtomicBuffer buffer = this.buffer; final int recordLength = length + HEADER_LENGTH; final int recordIndex = claimCapacity(buffer, recordLength); if (INSUFFICIENT_CAPACITY == recordIndex) { return recordIndex; } buffer.putInt(typeOffset(recordIndex), msgTypeId); buffer.putInt(lengthOffset(recordIndex), -recordLength); return encodedMsgOffset(recordIndex); } OneToOneRingBuffer(final AtomicBuffer buffer); int capacity(); boolean write(final int msgTypeId, final DirectBuffer srcBuffer, final int offset, final int length); int read(final MessageHandler handler); int read(final MessageHandler handler, final int messageCountLimit); int maxMsgLength(); long nextCorrelationId(); AtomicBuffer buffer(); void consumerHeartbeatTime(final long time); long consumerHeartbeatTime(); long producerPosition(); long consumerPosition(); int size(); boolean unblock(); int tryClaim(final int msgTypeId, final int length); void commit(final int index); void abort(final int index); }
OneToOneRingBuffer implements RingBuffer { public int tryClaim(final int msgTypeId, final int length) { checkTypeId(msgTypeId); checkMsgLength(length); final AtomicBuffer buffer = this.buffer; final int recordLength = length + HEADER_LENGTH; final int recordIndex = claimCapacity(buffer, recordLength); if (INSUFFICIENT_CAPACITY == recordIndex) { return recordIndex; } buffer.putInt(typeOffset(recordIndex), msgTypeId); buffer.putInt(lengthOffset(recordIndex), -recordLength); return encodedMsgOffset(recordIndex); } OneToOneRingBuffer(final AtomicBuffer buffer); int capacity(); boolean write(final int msgTypeId, final DirectBuffer srcBuffer, final int offset, final int length); int read(final MessageHandler handler); int read(final MessageHandler handler, final int messageCountLimit); int maxMsgLength(); long nextCorrelationId(); AtomicBuffer buffer(); void consumerHeartbeatTime(final long time); long consumerHeartbeatTime(); long producerPosition(); long consumerPosition(); int size(); boolean unblock(); int tryClaim(final int msgTypeId, final int length); void commit(final int index); void abort(final int index);  }