use of org.agrona.concurrent.UnsafeBuffer in project Aeron by real-logic.
the class NetworkPublication method resend.
public void resend(final int termId, final int termOffset, final int length) {
final long senderPosition = this.senderPosition.get();
final long resendPosition = computePosition(termId, termOffset, positionBitsToShift, initialTermId);
if (resendPosition < senderPosition && resendPosition >= (senderPosition - rawLog.termLength())) {
final int activeIndex = indexByPosition(resendPosition, positionBitsToShift);
final UnsafeBuffer termBuffer = termBuffers[activeIndex];
final ByteBuffer sendBuffer = sendBuffers[activeIndex];
int remainingBytes = length;
int bytesSent = 0;
int offset = termOffset;
do {
offset += bytesSent;
final long scanOutcome = scanForAvailability(termBuffer, offset, mtuLength);
final int available = available(scanOutcome);
if (available <= 0) {
break;
}
sendBuffer.limit(offset + available).position(offset);
if (available != channelEndpoint.send(sendBuffer)) {
shortSends.increment();
break;
}
bytesSent = available + padding(scanOutcome);
remainingBytes -= bytesSent;
} while (remainingBytes > 0);
retransmitsSent.orderedIncrement();
}
}
use of org.agrona.concurrent.UnsafeBuffer in project Aeron by real-logic.
the class TermAppenderTest method shouldAppendFrameToEmptyLog.
@Test
public void shouldAppendFrameToEmptyLog() {
final int headerLength = DEFAULT_HEADER.capacity();
final UnsafeBuffer buffer = new UnsafeBuffer(new byte[128]);
final int msgLength = 20;
final int frameLength = msgLength + headerLength;
final int alignedFrameLength = align(frameLength, FRAME_ALIGNMENT);
final int tail = 0;
logMetaDataBuffer.putLong(TERM_TAIL_COUNTER_OFFSET, pack(TERM_ID, tail));
assertThat(termAppender.appendUnfragmentedMessage(headerWriter, buffer, 0, msgLength, RVS), is((long) alignedFrameLength));
assertThat(rawTailVolatile(logMetaDataBuffer, PARTITION_INDEX), is(pack(TERM_ID, tail + alignedFrameLength)));
final InOrder inOrder = inOrder(termBuffer, headerWriter);
inOrder.verify(headerWriter, times(1)).write(termBuffer, tail, frameLength, TERM_ID);
inOrder.verify(termBuffer, times(1)).putBytes(headerLength, buffer, 0, msgLength);
inOrder.verify(termBuffer, times(1)).putLong(tail + RESERVED_VALUE_OFFSET, RV, LITTLE_ENDIAN);
inOrder.verify(termBuffer, times(1)).putIntOrdered(tail, frameLength);
}
use of org.agrona.concurrent.UnsafeBuffer in project Aeron by real-logic.
the class TermAppenderTest method shouldPadLogAndTripWhenAppendingWithInsufficientRemainingCapacity.
@Test
public void shouldPadLogAndTripWhenAppendingWithInsufficientRemainingCapacity() {
final int msgLength = 120;
final int headerLength = DEFAULT_HEADER.capacity();
final int requiredFrameSize = align(headerLength + msgLength, FRAME_ALIGNMENT);
final int tailValue = TERM_BUFFER_LENGTH - align(msgLength, FRAME_ALIGNMENT);
final UnsafeBuffer buffer = new UnsafeBuffer(new byte[128]);
final int frameLength = TERM_BUFFER_LENGTH - tailValue;
logMetaDataBuffer.putLong(TERM_TAIL_COUNTER_OFFSET, pack(TERM_ID, tailValue));
final long expectResult = pack(TERM_ID, TRIPPED);
assertThat(termAppender.appendUnfragmentedMessage(headerWriter, buffer, 0, msgLength, RVS), is(expectResult));
assertThat(rawTailVolatile(logMetaDataBuffer, PARTITION_INDEX), is(pack(TERM_ID, tailValue + requiredFrameSize)));
final InOrder inOrder = inOrder(termBuffer, headerWriter);
inOrder.verify(headerWriter, times(1)).write(termBuffer, tailValue, frameLength, TERM_ID);
inOrder.verify(termBuffer, times(1)).putShort(typeOffset(tailValue), (short) PADDING_FRAME_TYPE, LITTLE_ENDIAN);
inOrder.verify(termBuffer, times(1)).putIntOrdered(tailValue, frameLength);
}
use of org.agrona.concurrent.UnsafeBuffer in project Aeron by real-logic.
the class TermRebuilderTest method shouldFillSingleGap.
@Test
public void shouldFillSingleGap() {
final int frameLength = 50;
final int alignedFrameLength = BitUtil.align(frameLength, FRAME_ALIGNMENT);
final int srcOffset = 0;
final int tail = alignedFrameLength;
final int termOffset = tail;
final UnsafeBuffer packet = new UnsafeBuffer(ByteBuffer.allocateDirect(alignedFrameLength));
TermRebuilder.insert(termBuffer, termOffset, packet, alignedFrameLength);
verify(termBuffer).putBytes(tail + HEADER_LENGTH, packet, srcOffset + HEADER_LENGTH, alignedFrameLength - HEADER_LENGTH);
}
use of org.agrona.concurrent.UnsafeBuffer in project Aeron by real-logic.
the class TermRebuilderTest method shouldFillAfterAGap.
@Test
public void shouldFillAfterAGap() {
final int frameLength = 50;
final int alignedFrameLength = BitUtil.align(frameLength, FRAME_ALIGNMENT);
final int srcOffset = 0;
final UnsafeBuffer packet = new UnsafeBuffer(ByteBuffer.allocateDirect(alignedFrameLength));
final int termOffset = alignedFrameLength * 2;
TermRebuilder.insert(termBuffer, termOffset, packet, alignedFrameLength);
verify(termBuffer).putBytes((alignedFrameLength * 2) + HEADER_LENGTH, packet, srcOffset + HEADER_LENGTH, alignedFrameLength - HEADER_LENGTH);
}
Aggregations