Java Code Examples for io.aeron.logbuffer.BufferClaim#commit()
The following examples show how to use
io.aeron.logbuffer.BufferClaim#commit() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ILink3SenderEndPoint.java From artio with Apache License 2.0 | 6 votes |
public Action onReplayComplete(final long connectionId) { final BufferClaim bufferClaim = this.bufferClaim; final long position = inboundPublication.tryClaim(REPLAY_COMPLETE_LENGTH, bufferClaim); if (Pressure.isBackPressured(position)) { return ABORT; } replayComplete .wrapAndApplyHeader(bufferClaim.buffer(), bufferClaim.offset(), messageHeader) .connection(connectionId) .libraryId(libraryId); bufferClaim.commit(); return CONTINUE; }
Example 2
Source File: BufferClaimMessageTest.java From aeron with Apache License 2.0 | 5 votes |
@ParameterizedTest @MethodSource("channels") @Timeout(10) public void shouldTransferReservedValue(final String channel) { final BufferClaim bufferClaim = new BufferClaim(); try (Subscription subscription = aeron.addSubscription(channel, STREAM_ID); Publication publication = aeron.addPublication(channel, STREAM_ID)) { while (publication.tryClaim(MESSAGE_LENGTH, bufferClaim) < 0L) { Tests.yield(); } final long reservedValue = System.currentTimeMillis(); bufferClaim.reservedValue(reservedValue); bufferClaim.commit(); final MutableBoolean done = new MutableBoolean(); while (!done.get()) { final int fragments = subscription.poll( (buffer, offset, length, header) -> { assertEquals(MESSAGE_LENGTH, length); assertEquals(reservedValue, header.reservedValue()); done.value = true; }, FRAGMENT_COUNT_LIMIT); if (0 == fragments) { Tests.yield(); } } } }
Example 3
Source File: FileSender.java From aeron with Apache License 2.0 | 5 votes |
private static void sendChunk( final Publication publication, final BufferClaim bufferClaim, final long correlationId, final UnsafeBuffer fileBuffer, final int chunkOffset, final int chunkLength) { long result; while ((result = publication.tryClaim(CHUNK_PAYLOAD_OFFSET + chunkLength, bufferClaim)) < 0) { checkResult(result); Thread.yield(); } final MutableDirectBuffer buffer = bufferClaim.buffer(); final int offset = bufferClaim.offset(); buffer.putInt(offset + VERSION_OFFSET, VERSION, LITTLE_ENDIAN); buffer.putInt(offset + TYPE_OFFSET, FILE_CHUNK_TYPE, LITTLE_ENDIAN); buffer.putLong(offset + CORRELATION_ID_OFFSET, correlationId, LITTLE_ENDIAN); buffer.putLong(offset + CHUNK_OFFSET_OFFSET, chunkOffset, LITTLE_ENDIAN); buffer.putLong(offset + CHUNK_LENGTH_OFFSET, chunkLength, LITTLE_ENDIAN); buffer.putBytes(offset + CHUNK_PAYLOAD_OFFSET, fileBuffer, chunkOffset, chunkLength); bufferClaim.commit(); }
Example 4
Source File: EmbeddedExclusiveBufferClaimIpcThroughput.java From aeron with Apache License 2.0 | 5 votes |
public void run() { final IdleStrategy idleStrategy = SampleConfiguration.newIdleStrategy(); final AtomicBoolean running = this.running; final Publication publication = this.publication; final BufferClaim bufferClaim = new BufferClaim(); long backPressureCount = 0; long totalMessageCount = 0; outputResults: while (running.get()) { for (int i = 0; i < BURST_LENGTH; i++) { idleStrategy.reset(); while (publication.tryClaim(MESSAGE_LENGTH, bufferClaim) <= 0) { ++backPressureCount; if (!running.get()) { break outputResults; } idleStrategy.idle(); } final int offset = bufferClaim.offset(); bufferClaim.buffer().putInt(offset, i); // Example field write // Real app would write whatever fields are required via a flyweight like SBE bufferClaim.commit(); ++totalMessageCount; } } final double backPressureRatio = backPressureCount / (double)totalMessageCount; System.out.format("Publisher back pressure ratio: %f%n", backPressureRatio); }
Example 5
Source File: EmbeddedBufferClaimIpcThroughput.java From aeron with Apache License 2.0 | 5 votes |
public void run() { final IdleStrategy idleStrategy = SampleConfiguration.newIdleStrategy(); final AtomicBoolean running = this.running; final Publication publication = this.publication; final BufferClaim bufferClaim = new BufferClaim(); long backPressureCount = 0; long totalMessageCount = 0; outputResults: while (running.get()) { for (int i = 0; i < BURST_LENGTH; i++) { idleStrategy.reset(); while (publication.tryClaim(MESSAGE_LENGTH, bufferClaim) <= 0) { ++backPressureCount; if (!running.get()) { break outputResults; } idleStrategy.idle(); } final int offset = bufferClaim.offset(); bufferClaim.buffer().putInt(offset, i); // Example field write // Real app would write whatever fields are required via a flyweight like SBE bufferClaim.commit(); ++totalMessageCount; } } final double backPressureRatio = backPressureCount / (double)totalMessageCount; System.out.format("Publisher back pressure ratio: %f%n", backPressureRatio); }