Java Code Examples for io.aeron.logbuffer.BufferClaim#putBytes()
The following examples show how to use
io.aeron.logbuffer.BufferClaim#putBytes() .
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: ClusteredServiceAgent.java From aeron with Apache License 2.0 | 5 votes |
long tryClaim( final long clusterSessionId, final Publication publication, final int length, final BufferClaim bufferClaim) { if (role != Cluster.Role.LEADER) { final int maxPayloadLength = headerBuffer.capacity() - SESSION_HEADER_LENGTH; if (length > maxPayloadLength) { throw new IllegalArgumentException( "claim exceeds maxPayloadLength of " + maxPayloadLength + ", length=" + length); } bufferClaim.wrap(headerBuffer, 0, length + SESSION_HEADER_LENGTH); return ClientSession.MOCKED_OFFER; } if (null == publication) { return Publication.NOT_CONNECTED; } final long offset = publication.tryClaim(length + SESSION_HEADER_LENGTH, bufferClaim); if (offset > 0) { sessionMessageHeaderEncoder .clusterSessionId(clusterSessionId) .timestamp(clusterTime); bufferClaim.putBytes(headerBuffer, 0, SESSION_HEADER_LENGTH); } return offset; }
Example 2
Source File: ConsensusModuleProxy.java From aeron with Apache License 2.0 | 5 votes |
public long tryClaim(final int length, final BufferClaim bufferClaim, final DirectBuffer sessionHeader) { final long result = publication.tryClaim(length, bufferClaim); if (result > 0) { bufferClaim.putBytes(sessionHeader, 0, AeronCluster.SESSION_HEADER_LENGTH); } return result; }
Example 3
Source File: AeronCluster.java From aeron with Apache License 2.0 | 3 votes |
/** * Try to claim a range in the publication log into which a message can be written with zero copy semantics. * Once the message has been written then {@link BufferClaim#commit()} should be called thus making it available. * <p> * On successful claim, the Cluster ingress header will be written to the start of the claimed buffer section. * Clients <b>MUST</b> write into the claimed buffer region at offset + {@link AeronCluster#SESSION_HEADER_LENGTH}. * <pre>{@code * final DirectBuffer srcBuffer = acquireMessage(); * * if (aeronCluster.tryClaim(length, bufferClaim) > 0L) * { * try * { * final MutableDirectBuffer buffer = bufferClaim.buffer(); * final int offset = bufferClaim.offset(); * // ensure that data is written at the correct offset * buffer.putBytes(offset + AeronCluster.SESSION_HEADER_LENGTH, srcBuffer, 0, length); * } * finally * { * bufferClaim.commit(); * } * } * }</pre> * * @param length of the range to claim in bytes. The additional bytes for the session header will be added. * @param bufferClaim to be populated if the claim succeeds. * @return The new stream position, otherwise a negative error value as specified in * {@link io.aeron.Publication#tryClaim(int, BufferClaim)}. * @throws IllegalArgumentException if the length is greater than {@link io.aeron.Publication#maxPayloadLength()}. * @see Publication#tryClaim(int, BufferClaim) * @see BufferClaim#commit() * @see BufferClaim#abort() */ public long tryClaim(final int length, final BufferClaim bufferClaim) { final long offset = publication.tryClaim(length + SESSION_HEADER_LENGTH, bufferClaim); if (offset > 0) { bufferClaim.putBytes(headerBuffer, 0, SESSION_HEADER_LENGTH); } return offset; }