org.agrona.ExpandableArrayBuffer Java Examples
The following examples show how to use
org.agrona.ExpandableArrayBuffer.
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: 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 #2
Source File: ClusterNodeTest.java From aeron with Apache License 2.0 | 6 votes |
@Test @Timeout(10) public void shouldScheduleEventInService() { final ExpandableArrayBuffer msgBuffer = new ExpandableArrayBuffer(); final String msg = "Hello World!"; msgBuffer.putStringWithoutLengthAscii(0, msg); final MutableInteger messageCount = new MutableInteger(); final EgressListener listener = (clusterSessionId, timestamp, buffer, offset, length, header) -> { final String expected = msg + "-scheduled"; assertEquals(expected, buffer.getStringWithoutLengthAscii(offset, length)); messageCount.value += 1; }; container = launchTimedService(); aeronCluster = connectToCluster(listener); offerMessage(msgBuffer, msg); awaitResponse(messageCount); ClusterTests.failOnClusterError(); }
Example #3
Source File: ClusterNodeTest.java From aeron with Apache License 2.0 | 6 votes |
@Test @Timeout(10) public void shouldEchoMessageViaServiceUsingDirectOffer() { final ExpandableArrayBuffer msgBuffer = new ExpandableArrayBuffer(); final String msg = "Hello World!"; msgBuffer.putStringWithoutLengthAscii(0, msg); final MutableInteger messageCount = new MutableInteger(); final EgressListener listener = (clusterSessionId, timestamp, buffer, offset, length, header) -> { assertEquals(msg, buffer.getStringWithoutLengthAscii(offset, length)); messageCount.value += 1; }; container = launchEchoService(); aeronCluster = connectToCluster(listener); offerMessage(msgBuffer, msg); awaitResponse(messageCount); ClusterTests.failOnClusterError(); }
Example #4
Source File: ClusterNodeTest.java From aeron with Apache License 2.0 | 6 votes |
@Test @Timeout(10) public void shouldSendResponseAfterServiceMessage() { final ExpandableArrayBuffer msgBuffer = new ExpandableArrayBuffer(); final String msg = "Hello World!"; msgBuffer.putStringWithoutLengthAscii(0, msg); final MutableInteger messageCount = new MutableInteger(); final EgressListener listener = (clusterSessionId, timestamp, buffer, offset, length, header) -> { assertEquals(msg, buffer.getStringWithoutLengthAscii(offset, length)); messageCount.value += 1; }; container = launchServiceMessageIngressService(); aeronCluster = connectToCluster(listener); offerMessage(msgBuffer, msg); awaitResponse(messageCount); ClusterTests.failOnClusterError(); }
Example #5
Source File: FixMessagePredicates.java From artio with Apache License 2.0 | 6 votes |
public static FixMessagePredicate whereHeader( final FixDictionary fixDictionary, final Predicate<SessionHeaderDecoder> matches) { final SessionHeaderDecoder header = fixDictionary.makeHeaderDecoder(); final ExpandableArrayBuffer buffer = new ExpandableArrayBuffer(1024); final AsciiBuffer asciiBuffer = new MutableAsciiBuffer(); return message -> { final int length = message.bodyLength(); buffer.checkLimit(length); message.getBody(buffer, 0, length); asciiBuffer.wrap(buffer); header.decode(asciiBuffer, 0, length); return matches.test(header); }; }
Example #6
Source File: ModelUtils.java From java-cme-mdp3-handler with GNU Lesser General Public License v3.0 | 6 votes |
public static ByteBuffer getMDInstrumentDefinitionFuture27(long sequence, int securityId){ short bufferOffset = 0; final MutableDirectBuffer mutableDirectBuffer = new ExpandableArrayBuffer(); MessageHeaderEncoder messageHeaderEncoder = new MessageHeaderEncoder(); MDInstrumentDefinitionFuture27Encoder definitionFuture27Encoder = new MDInstrumentDefinitionFuture27Encoder(); messageHeaderEncoder.wrap(mutableDirectBuffer, bufferOffset) .blockLength(definitionFuture27Encoder.sbeBlockLength()) .templateId(definitionFuture27Encoder.sbeTemplateId()) .schemaId(definitionFuture27Encoder.sbeSchemaId()) .version(definitionFuture27Encoder.sbeSchemaVersion()); bufferOffset += messageHeaderEncoder.encodedLength(); definitionFuture27Encoder.wrap(mutableDirectBuffer, bufferOffset) .securityID(securityId) .symbol("testSymbol"); definitionFuture27Encoder.noEventsCount(1) .next() .eventTime(System.currentTimeMillis()) .eventType(EventType.Activation); definitionFuture27Encoder.noMDFeedTypesCount(1) .next() .marketDepth((byte)10) .mDFeedType("GBX"); bufferOffset += definitionFuture27Encoder.encodedLength(); return packMessage(sequence, mutableDirectBuffer.byteArray(), bufferOffset); }
Example #7
Source File: TestNode.java From aeron with Apache License 2.0 | 6 votes |
public void onTakeSnapshot(final ExclusivePublication snapshotPublication) { final ExpandableArrayBuffer buffer = new ExpandableArrayBuffer(SNAPSHOT_MSG_LENGTH); buffer.putInt(0, messageCount); for (int i = 0; i < SNAPSHOT_FRAGMENT_COUNT; i++) { idleStrategy.reset(); while (snapshotPublication.offer(buffer, 0, SNAPSHOT_MSG_LENGTH) <= 0) { idleStrategy.idle(); } } wasSnapshotTaken = true; }
Example #8
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 #9
Source File: FileSender.java From aeron with Apache License 2.0 | 6 votes |
private static void sendFileCreate( final Publication publication, final long correlationId, final int length, final String filename) { final ExpandableArrayBuffer buffer = new ExpandableArrayBuffer(); buffer.putInt(VERSION_OFFSET, VERSION, LITTLE_ENDIAN); buffer.putInt(TYPE_OFFSET, FILE_CREATE_TYPE, LITTLE_ENDIAN); buffer.putLong(CORRELATION_ID_OFFSET, correlationId, LITTLE_ENDIAN); buffer.putLong(FILE_LENGTH_OFFSET, length, LITTLE_ENDIAN); final int msgLength = FILE_NAME_OFFSET + buffer.putStringUtf8(FILE_NAME_OFFSET, filename); long result; while ((result = publication.offer(buffer, 0, msgLength)) < 0) { checkResult(result); Thread.yield(); } }
Example #10
Source File: SingleNodeCluster.java From aeron with Apache License 2.0 | 6 votes |
public void onTimerEvent(final long correlationId, final long timestamp) { System.out.println("onTimerEvent " + correlationId); final ExpandableArrayBuffer buffer = new ExpandableArrayBuffer(); buffer.putInt(0, 1); cluster.forEachClientSession( (clientSession) -> { idleStrategy.reset(); while (clientSession.offer(buffer, 0, SIZE_OF_INT) < 0) { idleStrategy.idle(); } }); }
Example #11
Source File: ClusterCounters.java From aeron with Apache License 2.0 | 5 votes |
/** * Allocate a counter to represent the a component state within a cluster. * * @param aeron to allocate the counter. * @param name of the counter for the label. * @param typeId for the counter. * @param clusterId to which the allocated counter belongs. * @return the {@link Counter} for the commit position. */ public static Counter allocate(final Aeron aeron, final String name, final int typeId, final int clusterId) { final ExpandableArrayBuffer buffer = new ExpandableArrayBuffer(); int index = 0; buffer.putInt(index, clusterId); index += SIZE_OF_INT; index += buffer.putStringWithoutLengthAscii(index, name); index += buffer.putStringWithoutLengthAscii(index, " - clusterId="); index += buffer.putIntAscii(index, clusterId); return aeron.addCounter(typeId, buffer, 0, SIZE_OF_INT, buffer, SIZE_OF_INT, index - SIZE_OF_INT); }
Example #12
Source File: ArchiveCreator.java From aeron with Apache License 2.0 | 5 votes |
private static void offerToPosition(final Publication publication, final long minimumPosition) { final ExpandableArrayBuffer buffer = new ExpandableArrayBuffer(); for (int i = 0; publication.position() < minimumPosition; i++) { final int length = buffer.putStringWithoutLengthAscii(0, MESSAGE_PREFIX + i); while (publication.offer(buffer, 0, length) <= 0) { Thread.yield(); checkInterruptStatus(); } } }
Example #13
Source File: StartFromTruncatedRecordingLogTest.java From aeron with Apache License 2.0 | 5 votes |
private void sendMessages(final ExpandableArrayBuffer msgBuffer) { for (int i = 0; i < MESSAGE_COUNT; i++) { while (client.offer(msgBuffer, 0, ClusterTests.HELLO_WORLD_MSG.length()) < 0) { Tests.yield(); client.pollEgress(); } client.pollEgress(); } }
Example #14
Source File: StartFromTruncatedRecordingLogTest.java From aeron with Apache License 2.0 | 5 votes |
private void assertClusterIsFunctioningCorrectly() { awaitLeaderMemberId(); connectClient(); final ExpandableArrayBuffer msgBuffer = new ExpandableArrayBuffer(); msgBuffer.putStringWithoutLengthAscii(0, ClusterTests.HELLO_WORLD_MSG); final int initialCount = responseCount.get(); sendMessages(msgBuffer); awaitResponses(MESSAGE_COUNT + initialCount); closeClient(); }
Example #15
Source File: ClusterTests.java From aeron with Apache License 2.0 | 5 votes |
public static Thread startMessageThread(final TestCluster cluster, final long backoffIntervalNs) { final Thread thread = new Thread( () -> { final IdleStrategy idleStrategy = YieldingIdleStrategy.INSTANCE; final AeronCluster client = cluster.client(); final ExpandableArrayBuffer msgBuffer = cluster.msgBuffer(); msgBuffer.putStringWithoutLengthAscii(0, HELLO_WORLD_MSG); while (!Thread.interrupted()) { if (client.offer(msgBuffer, 0, HELLO_WORLD_MSG.length()) < 0) { LockSupport.parkNanos(backoffIntervalNs); } idleStrategy.idle(client.pollEgress()); } }); thread.setDaemon(true); thread.setName("message-thread"); thread.start(); return thread; }
Example #16
Source File: ClusterNodeTest.java From aeron with Apache License 2.0 | 5 votes |
private void offerMessage(final ExpandableArrayBuffer msgBuffer, final String msg) { while (aeronCluster.offer(msgBuffer, 0, msg.length()) < 0) { Tests.yield(); } }
Example #17
Source File: BufferAlignmentAgentTest.java From agrona with Apache License 2.0 | 5 votes |
@Test public void testExpandableBuffer() { final ExpandableArrayBuffer buffer = new ExpandableArrayBuffer(256); testAlignedReadMethods(buffer, HEAP_BUFFER_ALIGNMENT_OFFSET); testUnAlignedReadMethods(buffer, HEAP_BUFFER_ALIGNMENT_OFFSET); testAlignedWriteMethods(buffer, HEAP_BUFFER_ALIGNMENT_OFFSET); testUnAlignedWriteMethods(buffer, HEAP_BUFFER_ALIGNMENT_OFFSET); }
Example #18
Source File: ModelUtils.java From java-cme-mdp3-handler with GNU Lesser General Public License v3.0 | 5 votes |
public static ByteBuffer getMBOOnlyIncrementWith12TestEntries(long sequence, int securityId){ short bufferOffset = 0; final MutableDirectBuffer mutableDirectBuffer = new ExpandableArrayBuffer(); MessageHeaderEncoder messageHeaderEncoder = new MessageHeaderEncoder(); MDIncrementalRefreshOrderBook43Encoder incrementalRefreshOrderBook43Encoder = new MDIncrementalRefreshOrderBook43Encoder(); messageHeaderEncoder.wrap(mutableDirectBuffer, bufferOffset) .blockLength(incrementalRefreshOrderBook43Encoder.sbeBlockLength()) .templateId(incrementalRefreshOrderBook43Encoder.sbeTemplateId()) .schemaId(incrementalRefreshOrderBook43Encoder.sbeSchemaId()) .version(incrementalRefreshOrderBook43Encoder.sbeSchemaVersion()); bufferOffset += messageHeaderEncoder.encodedLength(); incrementalRefreshOrderBook43Encoder.wrap(mutableDirectBuffer, bufferOffset) .transactTime(System.currentTimeMillis()); MatchEventIndicatorEncoder matchEventIndicatorEncoder = incrementalRefreshOrderBook43Encoder.matchEventIndicator(); matchEventIndicatorEncoder.lastQuoteMsg(true); MDIncrementalRefreshOrderBook43Encoder.NoMDEntriesEncoder noMDEntriesEncoder = incrementalRefreshOrderBook43Encoder.noMDEntriesCount(12); noMDEntriesEncoder.next().orderID(9926951995L).mDOrderPriority(414).securityID(securityId).mDUpdateAction(MDUpdateAction.Delete).mDEntryType(MDEntryTypeBook.Bid).mDDisplayQty(23).mDEntryPx().mantissa(98682500000L); noMDEntriesEncoder.next().orderID(9926951993L).mDOrderPriority(412).securityID(securityId).mDUpdateAction(MDUpdateAction.Delete).mDEntryType(MDEntryTypeBook.Offer).mDDisplayQty(59).mDEntryPx().mantissa(98685000000L); noMDEntriesEncoder.next().orderID(9926951992L).mDOrderPriority(411).securityID(securityId).mDUpdateAction(MDUpdateAction.Delete).mDEntryType(MDEntryTypeBook.Bid).mDDisplayQty(12).mDEntryPx().mantissa(98692500000L); noMDEntriesEncoder.next().orderID(9926951997L).mDOrderPriority(416).securityID(securityId).mDUpdateAction(MDUpdateAction.Change).mDEntryType(MDEntryTypeBook.Offer).mDDisplayQty(49).mDEntryPx().mantissa(98677500000L); noMDEntriesEncoder.next().orderID(9926951996L).mDOrderPriority(415).securityID(securityId).mDUpdateAction(MDUpdateAction.New).mDEntryType(MDEntryTypeBook.Offer).mDDisplayQty(92).mDEntryPx().mantissa(98687500000L); noMDEntriesEncoder.next().orderID(9926952003L).mDOrderPriority(422).securityID(securityId).mDUpdateAction(MDUpdateAction.New).mDEntryType(MDEntryTypeBook.Offer).mDDisplayQty(88).mDEntryPx().mantissa(98672500000L); noMDEntriesEncoder.next().orderID(9926952002L).mDOrderPriority(421).securityID(securityId).mDUpdateAction(MDUpdateAction.New).mDEntryType(MDEntryTypeBook.Bid).mDDisplayQty(32).mDEntryPx().mantissa(98677500000L); noMDEntriesEncoder.next().orderID(9926952001L).mDOrderPriority(420).securityID(securityId).mDUpdateAction(MDUpdateAction.New).mDEntryType(MDEntryTypeBook.Bid).mDDisplayQty(99).mDEntryPx().mantissa(98702500000L); noMDEntriesEncoder.next().orderID(9926952000L).mDOrderPriority(419).securityID(securityId).mDUpdateAction(MDUpdateAction.Delete).mDEntryType(MDEntryTypeBook.Bid).mDDisplayQty(94).mDEntryPx().mantissa(98680000000L); noMDEntriesEncoder.next().orderID(9926952005L).mDOrderPriority(424).securityID(securityId).mDUpdateAction(MDUpdateAction.Change).mDEntryType(MDEntryTypeBook.Bid).mDDisplayQty(49).mDEntryPx().mantissa(98675000000L); noMDEntriesEncoder.next().orderID(9926952004L).mDOrderPriority(423).securityID(securityId).mDUpdateAction(MDUpdateAction.Change).mDEntryType(MDEntryTypeBook.Offer).mDDisplayQty(54).mDEntryPx().mantissa(98702500000L); noMDEntriesEncoder.next().orderID(9926951983L).mDOrderPriority(402).securityID(securityId).mDUpdateAction(MDUpdateAction.Delete).mDEntryType(MDEntryTypeBook.Offer).mDDisplayQty(16).mDEntryPx().mantissa(98670000000L); bufferOffset += incrementalRefreshOrderBook43Encoder.encodedLength(); return packMessage(sequence, mutableDirectBuffer.byteArray(), bufferOffset); }
Example #19
Source File: Common.java From aeron with Apache License 2.0 | 5 votes |
static void offerToPosition(final Publication publication, final String prefix, final long minimumPosition) { final ExpandableArrayBuffer buffer = new ExpandableArrayBuffer(); for (int i = 0; publication.position() < minimumPosition; i++) { final int length = buffer.putStringWithoutLengthAscii(0, prefix + i); while (publication.offer(buffer, 0, length) <= 0) { Tests.yield(); } } }
Example #20
Source File: Common.java From aeron with Apache License 2.0 | 5 votes |
static void offer(final Publication publication, final int count, final String prefix) { final ExpandableArrayBuffer buffer = new ExpandableArrayBuffer(); for (int i = 0; i < count; i++) { final int length = buffer.putStringWithoutLengthAscii(0, prefix + i); while (publication.offer(buffer, 0, length) <= 0) { Tests.yield(); } } }
Example #21
Source File: ExtendRecordingTest.java From aeron with Apache License 2.0 | 5 votes |
private static void offer( final Publication publication, final int startIndex, final int count, final String prefix) { final ExpandableArrayBuffer buffer = new ExpandableArrayBuffer(); for (int i = startIndex; i < (startIndex + count); i++) { final int length = buffer.putStringWithoutLengthAscii(0, prefix + i); while (publication.offer(buffer, 0, length) <= 0) { Tests.yield(); } } }
Example #22
Source File: FixMessagePredicates.java From artio with Apache License 2.0 | 5 votes |
public static FixMessagePredicate bodyMatches(final Pattern pattern) { final ExpandableArrayBuffer buffer = new ExpandableArrayBuffer(1024); final BufferAsciiSequence sequence = new BufferAsciiSequence(); return message -> { final int length = message.bodyLength(); buffer.checkLimit(length); message.getBody(buffer, 0, length); sequence.wrap(buffer, 0, length); return pattern.matcher(sequence).matches(); }; }
Example #23
Source File: ModelUtils.java From java-cme-mdp3-handler with GNU Lesser General Public License v3.0 | 5 votes |
public static ByteBuffer getMBOIncrementTestMessage(long sequence, int securityId, long orderID, long mDOrderPriority, short mDUpdateAction, byte mDEntryType, int mDDisplayQty, int mDEntryPx){ short bufferOffset = 0; final MutableDirectBuffer mutableDirectBuffer = new ExpandableArrayBuffer(); MessageHeaderEncoder messageHeaderEncoder = new MessageHeaderEncoder(); MDIncrementalRefreshOrderBook43Encoder incrementalRefreshOrderBook43Encoder = new MDIncrementalRefreshOrderBook43Encoder(); messageHeaderEncoder.wrap(mutableDirectBuffer, bufferOffset) .blockLength(incrementalRefreshOrderBook43Encoder.sbeBlockLength()) .templateId(incrementalRefreshOrderBook43Encoder.sbeTemplateId()) .schemaId(incrementalRefreshOrderBook43Encoder.sbeSchemaId()) .version(incrementalRefreshOrderBook43Encoder.sbeSchemaVersion()); bufferOffset += messageHeaderEncoder.encodedLength(); incrementalRefreshOrderBook43Encoder.wrap(mutableDirectBuffer, bufferOffset) .transactTime(System.currentTimeMillis()); MatchEventIndicatorEncoder matchEventIndicatorEncoder = incrementalRefreshOrderBook43Encoder.matchEventIndicator(); matchEventIndicatorEncoder.lastTradeMsg(true); incrementalRefreshOrderBook43Encoder.noMDEntriesCount(1) .next() .orderID(orderID) .mDOrderPriority(mDOrderPriority) .securityID(securityId) .mDUpdateAction(MDUpdateAction.get(mDUpdateAction)) .mDEntryType(MDEntryTypeBook.get(mDEntryType)) .mDDisplayQty(mDDisplayQty).mDEntryPx().mantissa(mDEntryPx); bufferOffset += incrementalRefreshOrderBook43Encoder.encodedLength(); return packMessage(sequence, mutableDirectBuffer.byteArray(), bufferOffset); }
Example #24
Source File: ModelUtils.java From java-cme-mdp3-handler with GNU Lesser General Public License v3.0 | 5 votes |
public static ByteBuffer getMBOSnapshotTestMessage(long sequence, int securityId, long lastMsgSeqNumProcessed, long noChunks, long currentChunk, long totNumReports){ short bufferOffset = 0; final MutableDirectBuffer mutableDirectBuffer = new ExpandableArrayBuffer(); MessageHeaderEncoder messageHeaderEncoder = new MessageHeaderEncoder(); SnapshotFullRefreshOrderBook44Encoder snapshotFullRefreshOrderBook44Encoder = new SnapshotFullRefreshOrderBook44Encoder(); messageHeaderEncoder.wrap(mutableDirectBuffer, bufferOffset) .blockLength(snapshotFullRefreshOrderBook44Encoder.sbeBlockLength()) .templateId(snapshotFullRefreshOrderBook44Encoder.sbeTemplateId()) .schemaId(snapshotFullRefreshOrderBook44Encoder.sbeSchemaId()) .version(snapshotFullRefreshOrderBook44Encoder.sbeSchemaVersion()); bufferOffset += messageHeaderEncoder.encodedLength(); snapshotFullRefreshOrderBook44Encoder.wrap(mutableDirectBuffer, bufferOffset) .totNumReports(totNumReports) .lastMsgSeqNumProcessed(lastMsgSeqNumProcessed) .noChunks(noChunks) .currentChunk(currentChunk) .securityID(securityId); SnapshotFullRefreshOrderBook44Encoder.NoMDEntriesEncoder noMDEntriesEncoder = snapshotFullRefreshOrderBook44Encoder.noMDEntriesCount(1) .next() .mDDisplayQty(1) .mDOrderPriority(10) .orderID(123); PRICEEncoder priceEncoder = noMDEntriesEncoder.mDEntryPx(); priceEncoder.mantissa(5); bufferOffset += snapshotFullRefreshOrderBook44Encoder.encodedLength(); return packMessage(sequence, mutableDirectBuffer.byteArray(), bufferOffset); }
Example #25
Source File: ModelUtils.java From java-cme-mdp3-handler with GNU Lesser General Public License v3.0 | 5 votes |
public static ByteBuffer getMBPWithMBOIncrementTestMessage(long sequence, int[] securityIds, short[] referenceIDs){ short bufferOffset = 0; final MutableDirectBuffer mutableDirectBuffer = new ExpandableArrayBuffer(); MessageHeaderEncoder messageHeaderEncoder = new MessageHeaderEncoder(); MDIncrementalRefreshBook32Encoder mdIncrementalRefreshBook32Encoder = new MDIncrementalRefreshBook32Encoder(); messageHeaderEncoder.wrap(mutableDirectBuffer, bufferOffset) .blockLength(mdIncrementalRefreshBook32Encoder.sbeBlockLength()) .templateId(mdIncrementalRefreshBook32Encoder.sbeTemplateId()) .schemaId(mdIncrementalRefreshBook32Encoder.sbeSchemaId()) .version(mdIncrementalRefreshBook32Encoder.sbeSchemaVersion()); bufferOffset += messageHeaderEncoder.encodedLength(); MDIncrementalRefreshBook32Encoder.NoMDEntriesEncoder noMDEntriesEncoder = mdIncrementalRefreshBook32Encoder.wrap(mutableDirectBuffer, bufferOffset) .transactTime(System.currentTimeMillis()) .noMDEntriesCount(securityIds.length); MatchEventIndicatorEncoder matchEventIndicatorEncoder = mdIncrementalRefreshBook32Encoder.matchEventIndicator(); matchEventIndicatorEncoder.lastTradeMsg(true); for (int i = 0; i < securityIds.length; i++) { noMDEntriesEncoder.next() .mDEntrySize(2) .mDEntryType(MDEntryTypeBook.Bid) .mDPriceLevel((short) 3) .rptSeq(4) .securityID(securityIds[i]); PRICENULLEncoder pricenullEncoder = noMDEntriesEncoder.mDEntryPx(); pricenullEncoder.mantissa(5); } if(referenceIDs != null){ MDIncrementalRefreshBook32Encoder.NoOrderIDEntriesEncoder noOrderIDEntriesEncoder = mdIncrementalRefreshBook32Encoder.noOrderIDEntriesCount(referenceIDs.length); for (int i = 0; i < referenceIDs.length; i++) { noOrderIDEntriesEncoder.next() .orderUpdateAction(OrderUpdateAction.New) .mDDisplayQty(213) .mDOrderPriority(324324) .orderID(3243324) .referenceID(referenceIDs[i]); } } bufferOffset += mdIncrementalRefreshBook32Encoder.encodedLength(); return packMessage(sequence, mutableDirectBuffer.byteArray(), bufferOffset); }
Example #26
Source File: ModelUtils.java From java-cme-mdp3-handler with GNU Lesser General Public License v3.0 | 5 votes |
public static ByteBuffer getMBPOnlyIncrementWith12TestEntries(int sequence, int securityId) { short bufferOffset = 0; final MutableDirectBuffer mutableDirectBuffer = new ExpandableArrayBuffer(); MessageHeaderEncoder messageHeaderEncoder = new MessageHeaderEncoder(); MDIncrementalRefreshBook32Encoder mdIncrementalRefreshBook32Encoder = new MDIncrementalRefreshBook32Encoder(); messageHeaderEncoder.wrap(mutableDirectBuffer, bufferOffset) .blockLength(mdIncrementalRefreshBook32Encoder.sbeBlockLength()) .templateId(mdIncrementalRefreshBook32Encoder.sbeTemplateId()) .schemaId(mdIncrementalRefreshBook32Encoder.sbeSchemaId()) .version(mdIncrementalRefreshBook32Encoder.sbeSchemaVersion()); bufferOffset += messageHeaderEncoder.encodedLength(); MDIncrementalRefreshBook32Encoder.NoMDEntriesEncoder noMDEntriesEncoder = mdIncrementalRefreshBook32Encoder.wrap(mutableDirectBuffer, bufferOffset) .transactTime(System.currentTimeMillis()).noMDEntriesCount(12); MatchEventIndicatorEncoder matchEventIndicatorEncoder = mdIncrementalRefreshBook32Encoder.matchEventIndicator(); matchEventIndicatorEncoder.lastTradeMsg(true); noMDEntriesEncoder.next().mDEntrySize(4 ).mDEntryType(MDEntryTypeBook.Bid ).mDPriceLevel((short) 1).rptSeq(1254).securityID(securityId).mDUpdateAction(MDUpdateAction.New).mDEntryPx().mantissa(98745000000L); noMDEntriesEncoder.next().mDEntrySize(1 ).mDEntryType(MDEntryTypeBook.Offer).mDPriceLevel((short) 1).rptSeq(1255).securityID(securityId).mDUpdateAction(MDUpdateAction.New).mDEntryPx().mantissa(987075000000L); noMDEntriesEncoder.next().mDEntrySize(45).mDEntryType(MDEntryTypeBook.Bid ).mDPriceLevel((short) 2).rptSeq(1256).securityID(securityId).mDUpdateAction(MDUpdateAction.New).mDEntryPx().mantissa(987125000000L); noMDEntriesEncoder.next().mDEntrySize(22).mDEntryType(MDEntryTypeBook.Offer).mDPriceLevel((short) 2).rptSeq(1257).securityID(securityId).mDUpdateAction(MDUpdateAction.New).mDEntryPx().mantissa(98745000000L); noMDEntriesEncoder.next().mDEntrySize(98).mDEntryType(MDEntryTypeBook.Bid ).mDPriceLevel((short) 3).rptSeq(1258).securityID(securityId).mDUpdateAction(MDUpdateAction.New).mDEntryPx().mantissa(98720000000L); noMDEntriesEncoder.next().mDEntrySize(43).mDEntryType(MDEntryTypeBook.Offer).mDPriceLevel((short) 3).rptSeq(1259).securityID(securityId).mDUpdateAction(MDUpdateAction.New).mDEntryPx().mantissa(98725000000L); noMDEntriesEncoder.next().mDEntrySize(12).mDEntryType(MDEntryTypeBook.Bid ).mDPriceLevel((short) 4).rptSeq(1260).securityID(securityId).mDUpdateAction(MDUpdateAction.New).mDEntryPx().mantissa(98715000000L); noMDEntriesEncoder.next().mDEntrySize(83).mDEntryType(MDEntryTypeBook.Offer).mDPriceLevel((short) 4).rptSeq(1261).securityID(securityId).mDUpdateAction(MDUpdateAction.New).mDEntryPx().mantissa(98670000000L); noMDEntriesEncoder.next().mDEntrySize(38).mDEntryType(MDEntryTypeBook.Bid ).mDPriceLevel((short) 5).rptSeq(1262).securityID(securityId).mDUpdateAction(MDUpdateAction.New).mDEntryPx().mantissa(98695000000L); noMDEntriesEncoder.next().mDEntrySize(99).mDEntryType(MDEntryTypeBook.Offer).mDPriceLevel((short) 5).rptSeq(1263).securityID(securityId).mDUpdateAction(MDUpdateAction.New).mDEntryPx().mantissa(98690000000L); noMDEntriesEncoder.next().mDEntrySize(1 ).mDEntryType(MDEntryTypeBook.Bid ).mDPriceLevel((short) 3).rptSeq(1264).securityID(securityId).mDUpdateAction(MDUpdateAction.Delete).mDEntryPx().mantissa(987025000000L); noMDEntriesEncoder.next().mDEntrySize(99).mDEntryType(MDEntryTypeBook.Offer).mDPriceLevel((short) 3).rptSeq(1265).securityID(securityId).mDUpdateAction(MDUpdateAction.Delete).mDEntryPx().mantissa(98677500000L); bufferOffset += mdIncrementalRefreshBook32Encoder.encodedLength(); return packMessage(sequence, mutableDirectBuffer.byteArray(), bufferOffset); }
Example #27
Source File: MultiClusteredServicesTest.java From aeron with Apache License 2.0 | 4 votes |
@Test @Timeout(20) public void shouldSupportMultipleServicesPerNode() { final List<TestCluster.NodeContext> nodeContexts = new ArrayList<>(); final List<TestCluster.ServiceContext> serviceContexts = new ArrayList<>(); final List<ClusteredMediaDriver> clusteredMediaDrivers = new ArrayList<>(); final List<ClusteredServiceContainer> clusteredServiceContainers = new ArrayList<>(); nodeContexts.add(TestCluster.nodeContext(0, true)); nodeContexts.add(TestCluster.nodeContext(1, true)); nodeContexts.add(TestCluster.nodeContext(2, true)); serviceContexts.add(TestCluster.serviceContext(0, 0, nodeContexts.get(0), ServiceA::new)); serviceContexts.add(TestCluster.serviceContext(0, 1, nodeContexts.get(0), ServiceB::new)); serviceContexts.add(TestCluster.serviceContext(1, 0, nodeContexts.get(1), ServiceA::new)); serviceContexts.add(TestCluster.serviceContext(1, 1, nodeContexts.get(1), ServiceB::new)); serviceContexts.add(TestCluster.serviceContext(2, 0, nodeContexts.get(2), ServiceA::new)); serviceContexts.add(TestCluster.serviceContext(2, 1, nodeContexts.get(2), ServiceB::new)); nodeContexts.forEach((context) -> clusteredMediaDrivers.add(ClusteredMediaDriver.launch( context.mediaDriverCtx, context.archiveCtx, context.consensusModuleCtx))); serviceContexts.forEach( (context) -> { context.serviceContainerCtx.aeronDirectoryName(context.aeronCtx.aeronDirectoryName()); clusteredServiceContainers.add(ClusteredServiceContainer.launch(context.serviceContainerCtx)); }); final String aeronDirName = CommonContext.getAeronDirectoryName(); final MediaDriver clientMediaDriver = MediaDriver.launch(new MediaDriver.Context() .threadingMode(ThreadingMode.SHARED) .dirDeleteOnStart(true) .aeronDirectoryName(aeronDirName)); final AeronCluster client = AeronCluster.connect(new AeronCluster.Context() .aeronDirectoryName(aeronDirName) .ingressChannel("aeron:udp") .ingressEndpoints(TestCluster.ingressEndpoints(0, 3))); try { final DirectBuffer buffer = new ExpandableArrayBuffer(100); while (client.offer(buffer, 0, 100) < 0) { Tests.yield(); } Tests.awaitValue(serviceAMessageCount, 3); Tests.awaitValue(serviceBMessageCount, 3); } finally { CloseHelper.closeAll(client, clientMediaDriver); CloseHelper.closeAll(clusteredMediaDrivers); CloseHelper.closeAll(clusteredServiceContainers); clientMediaDriver.context().deleteDirectory(); clusteredMediaDrivers.forEach((driver) -> driver.mediaDriver().context().deleteDirectory()); } }
Example #28
Source File: TestCluster.java From aeron with Apache License 2.0 | 4 votes |
ExpandableArrayBuffer msgBuffer() { return msgBuffer; }
Example #29
Source File: ModelUtils.java From java-cme-mdp3-handler with GNU Lesser General Public License v3.0 | 4 votes |
public static ByteBuffer getMBOWithMBPIncrementWith12TestEntries(int sequence, int securityId) { short bufferOffset = 0; final MutableDirectBuffer mutableDirectBuffer = new ExpandableArrayBuffer(); MessageHeaderEncoder messageHeaderEncoder = new MessageHeaderEncoder(); MDIncrementalRefreshBook32Encoder mdIncrementalRefreshBook32Encoder = new MDIncrementalRefreshBook32Encoder(); messageHeaderEncoder.wrap(mutableDirectBuffer, bufferOffset) .blockLength(mdIncrementalRefreshBook32Encoder.sbeBlockLength()) .templateId(mdIncrementalRefreshBook32Encoder.sbeTemplateId()) .schemaId(mdIncrementalRefreshBook32Encoder.sbeSchemaId()) .version(mdIncrementalRefreshBook32Encoder.sbeSchemaVersion()); bufferOffset += messageHeaderEncoder.encodedLength(); MDIncrementalRefreshBook32Encoder.NoMDEntriesEncoder noMDEntriesEncoder = mdIncrementalRefreshBook32Encoder.wrap(mutableDirectBuffer, bufferOffset) .transactTime(System.currentTimeMillis()).noMDEntriesCount(12); MatchEventIndicatorEncoder matchEventIndicatorEncoder = mdIncrementalRefreshBook32Encoder.matchEventIndicator(); matchEventIndicatorEncoder.lastTradeMsg(true); noMDEntriesEncoder.next().mDEntrySize(4 ).mDEntryType(MDEntryTypeBook.Bid ).mDPriceLevel((short) 1).rptSeq(1254).securityID(securityId).mDUpdateAction(MDUpdateAction.New).mDEntryPx().mantissa(98745000000L); noMDEntriesEncoder.next().mDEntrySize(1 ).mDEntryType(MDEntryTypeBook.Offer).mDPriceLevel((short) 1).rptSeq(1255).securityID(securityId).mDUpdateAction(MDUpdateAction.New).mDEntryPx().mantissa(987075000000L); noMDEntriesEncoder.next().mDEntrySize(45).mDEntryType(MDEntryTypeBook.Bid ).mDPriceLevel((short) 2).rptSeq(1256).securityID(securityId).mDUpdateAction(MDUpdateAction.New).mDEntryPx().mantissa(987125000000L); noMDEntriesEncoder.next().mDEntrySize(22).mDEntryType(MDEntryTypeBook.Offer).mDPriceLevel((short) 2).rptSeq(1257).securityID(securityId).mDUpdateAction(MDUpdateAction.New).mDEntryPx().mantissa(98745000000L); noMDEntriesEncoder.next().mDEntrySize(98).mDEntryType(MDEntryTypeBook.Bid ).mDPriceLevel((short) 3).rptSeq(1258).securityID(securityId).mDUpdateAction(MDUpdateAction.New).mDEntryPx().mantissa(98720000000L); noMDEntriesEncoder.next().mDEntrySize(43).mDEntryType(MDEntryTypeBook.Offer).mDPriceLevel((short) 3).rptSeq(1259).securityID(securityId).mDUpdateAction(MDUpdateAction.New).mDEntryPx().mantissa(98725000000L); noMDEntriesEncoder.next().mDEntrySize(12).mDEntryType(MDEntryTypeBook.Bid ).mDPriceLevel((short) 4).rptSeq(1260).securityID(securityId).mDUpdateAction(MDUpdateAction.New).mDEntryPx().mantissa(98715000000L); noMDEntriesEncoder.next().mDEntrySize(83).mDEntryType(MDEntryTypeBook.Offer).mDPriceLevel((short) 4).rptSeq(1261).securityID(securityId).mDUpdateAction(MDUpdateAction.New).mDEntryPx().mantissa(98670000000L); noMDEntriesEncoder.next().mDEntrySize(38).mDEntryType(MDEntryTypeBook.Bid ).mDPriceLevel((short) 5).rptSeq(1262).securityID(securityId).mDUpdateAction(MDUpdateAction.New).mDEntryPx().mantissa(98695000000L); noMDEntriesEncoder.next().mDEntrySize(99).mDEntryType(MDEntryTypeBook.Offer).mDPriceLevel((short) 5).rptSeq(1263).securityID(securityId).mDUpdateAction(MDUpdateAction.New).mDEntryPx().mantissa(98690000000L); noMDEntriesEncoder.next().mDEntrySize(1 ).mDEntryType(MDEntryTypeBook.Bid ).mDPriceLevel((short) 3).rptSeq(1264).securityID(securityId).mDUpdateAction(MDUpdateAction.Delete).mDEntryPx().mantissa(987025000000L); noMDEntriesEncoder.next().mDEntrySize(99).mDEntryType(MDEntryTypeBook.Offer).mDPriceLevel((short) 3).rptSeq(1265).securityID(securityId).mDUpdateAction(MDUpdateAction.Delete).mDEntryPx().mantissa(98677500000L); MDIncrementalRefreshBook32Encoder.NoOrderIDEntriesEncoder noOrderIDEntriesEncoder = mdIncrementalRefreshBook32Encoder.noOrderIDEntriesCount(12); noOrderIDEntriesEncoder.next().orderUpdateAction(OrderUpdateAction.New ).mDDisplayQty(61).mDOrderPriority(5394).orderID(9927057956L).referenceID((short)1); noOrderIDEntriesEncoder.next().orderUpdateAction(OrderUpdateAction.New ).mDDisplayQty(3 ).mDOrderPriority(5395).orderID(9927057957L).referenceID((short)2); noOrderIDEntriesEncoder.next().orderUpdateAction(OrderUpdateAction.New ).mDDisplayQty(7 ).mDOrderPriority(5396).orderID(9927057958L).referenceID((short)3); noOrderIDEntriesEncoder.next().orderUpdateAction(OrderUpdateAction.New ).mDDisplayQty(44).mDOrderPriority(5397).orderID(9927057959L).referenceID((short)4); noOrderIDEntriesEncoder.next().orderUpdateAction(OrderUpdateAction.New ).mDDisplayQty(55).mDOrderPriority(5398).orderID(9927057960L).referenceID((short)5); noOrderIDEntriesEncoder.next().orderUpdateAction(OrderUpdateAction.New ).mDDisplayQty(68).mDOrderPriority(5399).orderID(9927057961L).referenceID((short)6); noOrderIDEntriesEncoder.next().orderUpdateAction(OrderUpdateAction.New ).mDDisplayQty(70).mDOrderPriority(5400).orderID(9927057962L).referenceID((short)7); noOrderIDEntriesEncoder.next().orderUpdateAction(OrderUpdateAction.New ).mDDisplayQty(56).mDOrderPriority(5401).orderID(9927057963L).referenceID((short)8); noOrderIDEntriesEncoder.next().orderUpdateAction(OrderUpdateAction.New ).mDDisplayQty(6 ).mDOrderPriority(5402).orderID(9927057964L).referenceID((short)9); noOrderIDEntriesEncoder.next().orderUpdateAction(OrderUpdateAction.New ).mDDisplayQty(20).mDOrderPriority(5403).orderID(9927057965L).referenceID((short)10); noOrderIDEntriesEncoder.next().orderUpdateAction(OrderUpdateAction.Delete).mDDisplayQty(9 ).mDOrderPriority(5404).orderID(9927057966L).referenceID((short)11); noOrderIDEntriesEncoder.next().orderUpdateAction(OrderUpdateAction.Delete).mDDisplayQty(29).mDOrderPriority(5405).orderID(9927057967L).referenceID((short)12); bufferOffset += mdIncrementalRefreshBook32Encoder.encodedLength(); return packMessage(sequence, mutableDirectBuffer.byteArray(), bufferOffset); }