org.agrona.MutableDirectBuffer Java Examples
The following examples show how to use
org.agrona.MutableDirectBuffer.
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: MDInstrumentDefinitionOption41Encoder.java From java-cme-mdp3-handler with GNU Lesser General Public License v3.0 | 6 votes |
public void wrap( final MDInstrumentDefinitionOption41Encoder parentMessage, final MutableDirectBuffer buffer, final int count) { if (count < 0 || count > 254) { throw new IllegalArgumentException("count outside allowed range: count=" + count); } this.parentMessage = parentMessage; this.buffer = buffer; dimensions.wrap(buffer, parentMessage.limit()); dimensions.blockLength((int)24); dimensions.numInGroup((short)count); index = -1; this.count = count; parentMessage.limit(parentMessage.limit() + HEADER_SIZE); }
Example #2
Source File: GatewayPublication.java From artio with Apache License 2.0 | 6 votes |
public long saveWriteMetaDataReply( final int libraryId, final long replyToId, final MetaDataStatus status) { final long position = claim(WRITE_META_DATA_REPLY_LENGTH); if (position < 0) { return position; } final MutableDirectBuffer buffer = bufferClaim.buffer(); final int offset = bufferClaim.offset(); writeMetaDataReply .wrapAndApplyHeader(buffer, offset, header) .libraryId(libraryId) .replyToId(replyToId) .status(status); bufferClaim.commit(); logSbeMessage(GATEWAY_MESSAGE, writeMetaDataReply); return position; }
Example #3
Source File: ExclusiveTermAppenderTest.java From aeron with Apache License 2.0 | 6 votes |
@Test void appendBlock() { final int termId = 43; final int termOffset = 128; final MutableDirectBuffer buffer = mock(MutableDirectBuffer.class); final int offset = 16; final int length = 1024; final int lengthOfFirstFrame = 148; when(buffer.getInt(offset, LITTLE_ENDIAN)).thenReturn(lengthOfFirstFrame); final int resultOffset = termAppender.appendBlock(termId, termOffset, buffer, offset, length); assertEquals(termOffset + length, resultOffset); final long rawTail = rawTail(metadataBuffer, 0); assertEquals(termId, termId(rawTail)); assertEquals(termOffset + length, termOffset(rawTail)); final InOrder inOrder = inOrder(termBuffer, buffer); inOrder.verify(buffer).getInt(offset, LITTLE_ENDIAN); inOrder.verify(buffer).putInt(offset, 0, LITTLE_ENDIAN); inOrder.verify(termBuffer).putBytes(termOffset, buffer, offset, length); inOrder.verify(termBuffer).putIntOrdered(termOffset, lengthOfFirstFrame); inOrder.verifyNoMoreInteractions(); }
Example #4
Source File: DriverEventDissector.java From aeron with Apache License 2.0 | 6 votes |
static void dissectUntetheredSubscriptionStateChange( final MutableDirectBuffer buffer, final int offset, final StringBuilder builder) { int absoluteOffset = offset; absoluteOffset += dissectLogHeader( CONTEXT, UNTETHERED_SUBSCRIPTION_STATE_CHANGE, buffer, absoluteOffset, builder); builder.append(": subscriptionId=").append(buffer.getLong(absoluteOffset, LITTLE_ENDIAN)); absoluteOffset += SIZE_OF_LONG; builder.append(", streamId=").append(buffer.getInt(absoluteOffset, LITTLE_ENDIAN)); absoluteOffset += SIZE_OF_INT; builder.append(", sessionId=").append(buffer.getInt(absoluteOffset, LITTLE_ENDIAN)); absoluteOffset += SIZE_OF_INT; builder.append(", "); buffer.getStringAscii(absoluteOffset, builder); }
Example #5
Source File: EncoderGenerator.java From artio with Apache License 2.0 | 6 votes |
protected void generateAggregateFile(final Aggregate aggregate, final AggregateType aggregateType) { final String className = encoderClassName(aggregate.name()); outputManager.withOutput( className, (out) -> { out.append(fileHeader(thisPackage)); if (REQUIRED_SESSION_CODECS.contains(className)) { out.append(importFor("uk.co.real_logic.artio.builder.Abstract" + className)); } generateImports( "Encoder", aggregateType, out, DirectBuffer.class, MutableDirectBuffer.class, UnsafeBuffer.class, AsciiSequenceView.class); generateAggregateClass(aggregate, aggregateType, className, out); }); }
Example #6
Source File: ArchiveEventDissector.java From aeron with Apache License 2.0 | 6 votes |
static void dissectReplaySessionError( final MutableDirectBuffer buffer, final int offset, final StringBuilder builder) { int absoluteOffset = offset; absoluteOffset += dissectLogHeader(CONTEXT, REPLAY_SESSION_ERROR, buffer, absoluteOffset, builder); final long sessionId = buffer.getLong(absoluteOffset, LITTLE_ENDIAN); absoluteOffset += SIZE_OF_LONG; final long recordingId = buffer.getLong(absoluteOffset, LITTLE_ENDIAN); absoluteOffset += SIZE_OF_LONG; builder.append(": sessionId=").append(sessionId); builder.append(", recordingId=").append(recordingId); builder.append(", errorMessage="); buffer.getStringAscii(absoluteOffset, builder); }
Example #7
Source File: MDInstrumentDefinitionFuture27Encoder.java From java-cme-mdp3-handler with GNU Lesser General Public License v3.0 | 6 votes |
public void wrap( final MDInstrumentDefinitionFuture27Encoder parentMessage, final MutableDirectBuffer buffer, final int count) { if (count < 0 || count > 254) { throw new IllegalArgumentException("count outside allowed range: count=" + count); } this.parentMessage = parentMessage; this.buffer = buffer; dimensions.wrap(buffer, parentMessage.limit()); dimensions.blockLength((int)9); dimensions.numInGroup((short)count); index = -1; this.count = count; parentMessage.limit(parentMessage.limit() + HEADER_SIZE); }
Example #8
Source File: MDInstrumentDefinitionOption41Encoder.java From java-cme-mdp3-handler with GNU Lesser General Public License v3.0 | 6 votes |
public void wrap( final MDInstrumentDefinitionOption41Encoder parentMessage, final MutableDirectBuffer buffer, final int count) { if (count < 0 || count > 254) { throw new IllegalArgumentException("count outside allowed range: count=" + count); } this.parentMessage = parentMessage; this.buffer = buffer; dimensions.wrap(buffer, parentMessage.limit()); dimensions.blockLength((int)9); dimensions.numInGroup((short)count); index = -1; this.count = count; parentMessage.limit(parentMessage.limit() + HEADER_SIZE); }
Example #9
Source File: MDInstrumentDefinitionSpread29Encoder.java From java-cme-mdp3-handler with GNU Lesser General Public License v3.0 | 6 votes |
public void wrap( final MDInstrumentDefinitionSpread29Encoder parentMessage, final MutableDirectBuffer buffer, final int count) { if (count < 0 || count > 254) { throw new IllegalArgumentException("count outside allowed range: count=" + count); } this.parentMessage = parentMessage; this.buffer = buffer; dimensions.wrap(buffer, parentMessage.limit()); dimensions.blockLength((int)9); dimensions.numInGroup((short)count); index = -1; this.count = count; parentMessage.limit(parentMessage.limit() + HEADER_SIZE); }
Example #10
Source File: MDInstrumentDefinitionOption41Encoder.java From java-cme-mdp3-handler with GNU Lesser General Public License v3.0 | 6 votes |
public void wrap( final MDInstrumentDefinitionOption41Encoder parentMessage, final MutableDirectBuffer buffer, final int count) { if (count < 0 || count > 254) { throw new IllegalArgumentException("count outside allowed range: count=" + count); } this.parentMessage = parentMessage; this.buffer = buffer; dimensions.wrap(buffer, parentMessage.limit()); dimensions.blockLength((int)4); dimensions.numInGroup((short)count); index = -1; this.count = count; parentMessage.limit(parentMessage.limit() + HEADER_SIZE); }
Example #11
Source File: MDInstrumentDefinitionSpread29Encoder.java From java-cme-mdp3-handler with GNU Lesser General Public License v3.0 | 6 votes |
public void wrap( final MDInstrumentDefinitionSpread29Encoder parentMessage, final MutableDirectBuffer buffer, final int count) { if (count < 0 || count > 254) { throw new IllegalArgumentException("count outside allowed range: count=" + count); } this.parentMessage = parentMessage; this.buffer = buffer; dimensions.wrap(buffer, parentMessage.limit()); dimensions.blockLength((int)4); dimensions.numInGroup((short)count); index = -1; this.count = count; parentMessage.limit(parentMessage.limit() + HEADER_SIZE); }
Example #12
Source File: StaticInfoEncoder.java From deeplearning4j with Apache License 2.0 | 6 votes |
public void wrap(final StaticInfoEncoder parentMessage, final MutableDirectBuffer buffer, final int count) { if (count < 0 || count > 65534) { throw new IllegalArgumentException("count outside allowed range: count=" + count); } this.parentMessage = parentMessage; this.buffer = buffer; actingVersion = SCHEMA_VERSION; dimensions.wrap(buffer, parentMessage.limit()); dimensions.blockLength((int) 0); dimensions.numInGroup((int) count); index = -1; this.count = count; blockLength = 0; parentMessage.limit(parentMessage.limit() + HEADER_SIZE); }
Example #13
Source File: GatewayPublication.java From artio with Apache License 2.0 | 6 votes |
public long saveError(final GatewayError errorType, final int libraryId, final long replyToId, final String message) { final byte[] messageBytes = bytes(message); final int length = header.encodedLength() + BLOCK_LENGTH + messageHeaderLength() + messageBytes.length; final long position = claim(length); if (position < 0) { return position; } final MutableDirectBuffer buffer = bufferClaim.buffer(); final int offset = bufferClaim.offset(); error.wrapAndApplyHeader(buffer, offset, header) .errorType(errorType) .libraryId(libraryId) .replyToId(replyToId) .putMessage(messageBytes, 0, messageBytes.length); bufferClaim.commit(); logSbeMessage(GATEWAY_MESSAGE, error); return position; }
Example #14
Source File: ChannelReset4Encoder.java From java-cme-mdp3-handler with GNU Lesser General Public License v3.0 | 6 votes |
public void wrap( final ChannelReset4Encoder parentMessage, final MutableDirectBuffer buffer, final int count) { if (count < 0 || count > 254) { throw new IllegalArgumentException("count outside allowed range: count=" + count); } this.parentMessage = parentMessage; this.buffer = buffer; dimensions.wrap(buffer, parentMessage.limit()); dimensions.blockLength((int)2); dimensions.numInGroup((short)count); index = -1; this.count = count; parentMessage.limit(parentMessage.limit() + HEADER_SIZE); }
Example #15
Source File: GatewayPublication.java From artio with Apache License 2.0 | 6 votes |
public long saveResetSessionIds() { final long position = claim(HEADER_LENGTH); if (position < 0) { return position; } final MutableDirectBuffer buffer = bufferClaim.buffer(); final int offset = bufferClaim.offset(); resetSessionIds.wrapAndApplyHeader(buffer, offset, header); bufferClaim.commit(); logSbeMessage(GATEWAY_MESSAGE, resetSessionIds); return position; }
Example #16
Source File: UnsafeBufferTest.java From agrona with Apache License 2.0 | 6 votes |
@ParameterizedTest @MethodSource("valuesAndLengths") public void shouldPutNaturalFromEnd(final int[] valueAndLength) { final MutableDirectBuffer buffer = new UnsafeBuffer(new byte[8 * 1024]); final int value = valueAndLength[0]; final int length = valueAndLength[1]; final int start = buffer.putNaturalIntAsciiFromEnd(value, length); final String message = "for " + Arrays.toString(valueAndLength); assertEquals(0, start, message); assertEquals( String.valueOf(value), buffer.getStringWithoutLengthAscii(0, length), message); }
Example #17
Source File: ModelUtils.java From java-cme-mdp3-handler with GNU Lesser General Public License v3.0 | 6 votes |
public static ByteBuffer getLogin(long sequence){ short bufferOffset = 0; final MutableDirectBuffer mutableDirectBuffer = new ExpandableArrayBuffer(); MessageHeaderEncoder messageHeaderEncoder = new MessageHeaderEncoder(); AdminLogin15Encoder loginEncoder = new AdminLogin15Encoder(); messageHeaderEncoder.wrap(mutableDirectBuffer, bufferOffset) .blockLength(loginEncoder.sbeBlockLength()) .templateId(loginEncoder.sbeTemplateId()) .schemaId(loginEncoder.sbeSchemaId()) .version(loginEncoder.sbeSchemaVersion()); bufferOffset += messageHeaderEncoder.encodedLength(); loginEncoder.wrap(mutableDirectBuffer, bufferOffset); loginEncoder.heartBtInt((byte)2); bufferOffset += loginEncoder.encodedLength(); return packMessage(sequence, mutableDirectBuffer.byteArray(), bufferOffset); }
Example #18
Source File: ReplaySessionTest.java From aeron with Apache License 2.0 | 6 votes |
private void mockPublication(final ExclusivePublication replay, final UnsafeBuffer termBuffer) { when(replay.offerBlock(any(MutableDirectBuffer.class), anyInt(), anyInt())).then( (invocation) -> { final MutableDirectBuffer buffer = invocation.getArgument(0); final int offset = invocation.getArgument(1); final int length = invocation.getArgument(2); termBuffer.putBytes(offerBlockOffset, buffer, offset, length); messageCounter++; offerBlockOffset += length; return (long)length; }); when(replay.appendPadding(anyInt())).then( (invocation) -> { final int claimedSize = invocation.getArgument(0); messageCounter++; return (long)claimedSize; }); }
Example #19
Source File: SenderAndTargetSessionIdStrategy.java From artio with Apache License 2.0 | 6 votes |
public int save(final CompositeKey compositeKey, final MutableDirectBuffer buffer, final int offset) { requireNonNull(compositeKey, "compositeKey"); requireNonNull(buffer, "buffer"); final String localCompId = compositeKey.localCompId(); final String remoteCompId = compositeKey.remoteCompId(); final int length = localCompId.length() + remoteCompId.length() + BLOCK_AND_LENGTH_FIELDS_LENGTH; if (buffer.capacity() < offset + length) { return INSUFFICIENT_SPACE; } keyEncoder.wrap(buffer, offset); keyEncoder.localCompId(localCompId); keyEncoder.remoteCompId(remoteCompId); return length; }
Example #20
Source File: ModelUtils.java From java-cme-mdp3-handler with GNU Lesser General Public License v3.0 | 6 votes |
public static ByteBuffer getMBPSnapshotTestMessage(long sequence, int securityId, long lastMsgSeqNumProcessed, long totNumReports){ short bufferOffset = 0; final MutableDirectBuffer mutableDirectBuffer = new ExpandableArrayBuffer(); MessageHeaderEncoder messageHeaderEncoder = new MessageHeaderEncoder(); SnapshotFullRefresh38Encoder snapshotFullRefresh38Encoder = new SnapshotFullRefresh38Encoder(); messageHeaderEncoder.wrap(mutableDirectBuffer, bufferOffset) .blockLength(snapshotFullRefresh38Encoder.sbeBlockLength()) .templateId(snapshotFullRefresh38Encoder.sbeTemplateId()) .schemaId(snapshotFullRefresh38Encoder.sbeSchemaId()) .version(snapshotFullRefresh38Encoder.sbeSchemaVersion()); bufferOffset += messageHeaderEncoder.encodedLength(); snapshotFullRefresh38Encoder.wrap(mutableDirectBuffer, bufferOffset) .totNumReports(totNumReports) .lastMsgSeqNumProcessed(lastMsgSeqNumProcessed) .securityID(securityId); SnapshotFullRefresh38Encoder.NoMDEntriesEncoder noMDEntriesEncoder = snapshotFullRefresh38Encoder.noMDEntriesCount(1) .next() .mDEntrySize(10) .mDPriceLevel((byte)1); PRICENULLEncoder pricenullEncoder = noMDEntriesEncoder.mDEntryPx(); pricenullEncoder.mantissa(5); bufferOffset += snapshotFullRefresh38Encoder.encodedLength(); return packMessage(sequence, mutableDirectBuffer.byteArray(), bufferOffset); }
Example #21
Source File: GatewayPublication.java From artio with Apache License 2.0 | 6 votes |
public long saveRequestDisconnect(final int libraryId, final long connectionId, final DisconnectReason reason) { final long position = claim(header.encodedLength() + RequestDisconnectEncoder.BLOCK_LENGTH); if (position < 0) { return position; } final MutableDirectBuffer buffer = bufferClaim.buffer(); final int offset = bufferClaim.offset(); requestDisconnect .wrapAndApplyHeader(buffer, offset, header) .libraryId(libraryId) .connection(connectionId) .reason(reason); bufferClaim.commit(); logSbeMessage(GATEWAY_MESSAGE, requestDisconnect); return position; }
Example #22
Source File: GatewayPublication.java From artio with Apache License 2.0 | 6 votes |
public long saveMidConnectionDisconnect(final int libraryId, final long correlationId) { final long position = claim(MID_CONNECTION_DISCONNECT_LENGTH); if (position < 0) { return position; } final MutableDirectBuffer buffer = bufferClaim.buffer(); final int offset = bufferClaim.offset(); midConnectionDisconnect .wrapAndApplyHeader(buffer, offset, header) .libraryId(libraryId) .correlationId(correlationId); bufferClaim.commit(); logSbeMessage(GATEWAY_MESSAGE, midConnectionDisconnect); return position; }
Example #23
Source File: MessageHeaderEncoder.java From java-cme-mdp3-handler with GNU Lesser General Public License v3.0 | 5 votes |
public MessageHeaderEncoder wrap(final MutableDirectBuffer buffer, final int offset) { this.buffer = buffer; this.offset = offset; return this; }
Example #24
Source File: GatewayPublication.java From artio with Apache License 2.0 | 5 votes |
public long saveControlNotification( final int libraryId, final InitialAcceptedSessionOwner initialAcceptedSessionOwner, final List<ConnectedSessionInfo> sessions) { final int sessionsCount = sessions.size(); final long position = claim(CONTROL_NOTIFICATION_LENGTH + sessionsCount * SessionsEncoder.sbeBlockLength()); if (position < 0) { return position; } final MutableDirectBuffer buffer = bufferClaim.buffer(); final int offset = bufferClaim.offset(); controlNotification .wrapAndApplyHeader(buffer, offset, header) .libraryId(libraryId) .initialAcceptedSessionOwner(initialAcceptedSessionOwner); final SessionsEncoder sessionsEncoder = controlNotification.sessionsCount(sessionsCount); for (int i = 0; i < sessionsCount; i++) { final long sessionId = sessions.get(i).sessionId(); sessionsEncoder.next().sessionId(sessionId); } bufferClaim.commit(); logSbeMessage(GATEWAY_MESSAGE, controlNotification); return position; }
Example #25
Source File: GatewayPublication.java From artio with Apache License 2.0 | 5 votes |
public long saveReplayMessages( final int libraryId, final long sessionId, final long correlationId, final int replayFromSequenceNumber, final int replayFromSequenceIndex, final int replayToSequenceNumber, final int replayToSequenceIndex, final long latestReplyArrivalTimeInMs) { final long position = claim(REPLAY_MESSAGES_LENGTH); if (position < 0) { return position; } final MutableDirectBuffer buffer = bufferClaim.buffer(); final int offset = bufferClaim.offset(); replayMessages .wrapAndApplyHeader(buffer, offset, header) .libraryId(libraryId) .session(sessionId) .correlationId(correlationId) .replayFromSequenceNumber(replayFromSequenceNumber) .replayFromSequenceIndex(replayFromSequenceIndex) .replayToSequenceNumber(replayToSequenceNumber) .replayToSequenceIndex(replayToSequenceIndex) .latestReplyArrivalTimeInMs(latestReplyArrivalTimeInMs); bufferClaim.commit(); logSbeMessage(GATEWAY_MESSAGE, replayMessages); return position; }
Example #26
Source File: TokenCodecDecoder.java From simple-binary-encoding with Apache License 2.0 | 5 votes |
public int getEpoch(final MutableDirectBuffer dst, final int dstOffset, final int length) { final int headerLength = 2; final int limit = parentMessage.limit(); final int dataLength = (buffer.getShort(limit, java.nio.ByteOrder.LITTLE_ENDIAN) & 0xFFFF); final int bytesCopied = Math.min(length, dataLength); parentMessage.limit(limit + headerLength + dataLength); buffer.getBytes(limit + headerLength, dst, dstOffset, bytesCopied); return bytesCopied; }
Example #27
Source File: GatewayPublication.java From artio with Apache License 2.0 | 5 votes |
public long saveInitiateILinkConnection( final int libraryId, final int port, final long correlationId, final boolean reEstablishLastSession, final String host, final String accessKeyId) { final byte[] hostBytes = bytes(host); final byte[] accessKeyIdBytes = bytes(accessKeyId); final long position = claim(INITIATE_ILINK_LENGTH + hostBytes.length + accessKeyIdBytes.length); if (position < 0) { return position; } final MutableDirectBuffer buffer = bufferClaim.buffer(); final int offset = bufferClaim.offset(); initiateILinkConnection .wrapAndApplyHeader(buffer, offset, header) .libraryId(libraryId) .port(port) .correlationId(correlationId) .reestablishConnection(toBool(reEstablishLastSession)) .putHost(hostBytes, 0, hostBytes.length) .putAccessKeyId(accessKeyIdBytes, 0, accessKeyIdBytes.length); bufferClaim.commit(); logSbeMessage(GATEWAY_MESSAGE, initiateILinkConnection); return position; }
Example #28
Source File: TokenCodecDecoder.java From simple-binary-encoding with Apache License 2.0 | 5 votes |
public int getCharacterEncoding(final MutableDirectBuffer dst, final int dstOffset, final int length) { final int headerLength = 2; final int limit = parentMessage.limit(); final int dataLength = (buffer.getShort(limit, java.nio.ByteOrder.LITTLE_ENDIAN) & 0xFFFF); final int bytesCopied = Math.min(length, dataLength); parentMessage.limit(limit + headerLength + dataLength); buffer.getBytes(limit + headerLength, dst, dstOffset, bytesCopied); return bytesCopied; }
Example #29
Source File: TokenCodecEncoder.java From simple-binary-encoding with Apache License 2.0 | 5 votes |
public TokenCodecEncoder wrapAndApplyHeader( final MutableDirectBuffer buffer, final int offset, final MessageHeaderEncoder headerEncoder) { headerEncoder .wrap(buffer, offset) .blockLength(BLOCK_LENGTH) .templateId(TEMPLATE_ID) .schemaId(SCHEMA_ID) .version(SCHEMA_VERSION); return wrap(buffer, offset + MessageHeaderEncoder.ENCODED_LENGTH); }
Example #30
Source File: GatewayPublication.java From artio with Apache License 2.0 | 5 votes |
public long saveValidResendRequest( final long sessionId, final long connectionId, final long beginSequenceNumber, final long endSequenceNumber, final int sequenceIndex, final DirectBuffer bodyBuffer, final int bodyOffset, final int bodyLength) { final long position = claim(VALID_RESEND_REQUEST_LENGTH + bodyLength); if (position < 0) { return position; } final MutableDirectBuffer buffer = bufferClaim.buffer(); final int offset = bufferClaim.offset(); validResendRequest .wrapAndApplyHeader(buffer, offset, header) .session(sessionId) .connection(connectionId) .beginSequenceNumber(beginSequenceNumber) .endSequenceNumber(endSequenceNumber) .sequenceIndex(sequenceIndex) .putBody(bodyBuffer, bodyOffset, bodyLength); bufferClaim.commit(); logSbeMessage(GATEWAY_MESSAGE, validResendRequest); return position; }