Java Code Examples for org.agrona.DirectBuffer#getLong()
The following examples show how to use
org.agrona.DirectBuffer#getLong() .
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: IdExtractor.java From artio with Apache License 2.0 | 6 votes |
public void onEncoding( final Token fieldToken, final DirectBuffer buffer, final int bufferIndex, final Token typeToken, final int actingVersion) { switch (fieldToken.name()) { case "libraryId": libraryId = buffer.getInt(bufferIndex); break; case "correlationId": case "connectCorrelationId": correlationId = buffer.getLong(bufferIndex); break; } }
Example 2
Source File: RecordingPos.java From aeron with Apache License 2.0 | 6 votes |
/** * Find the active counter id for a stream based on the recording id. * * @param countersReader to search within. * @param recordingId for the active recording. * @return the counter id if found otherwise {@link CountersReader#NULL_COUNTER_ID}. */ public static int findCounterIdByRecording(final CountersReader countersReader, final long recordingId) { final DirectBuffer buffer = countersReader.metaDataBuffer(); for (int i = 0, size = countersReader.maxCounterId(); i < size; i++) { if (countersReader.getCounterState(i) == RECORD_ALLOCATED && countersReader.getCounterTypeId(i) == RECORDING_POSITION_TYPE_ID) { if (buffer.getLong(CountersReader.metaDataOffset(i) + KEY_OFFSET + RECORDING_ID_OFFSET) == recordingId) { return i; } } } return NULL_COUNTER_ID; }
Example 3
Source File: BufferAlignmentAgentTest.java From agrona with Apache License 2.0 | 6 votes |
private void testUnAlignedReadMethods(final DirectBuffer buffer, final int offset) { buffer.getLong(offset); // assert that buffer[offset] is 8-bytes aligned assertUnaligned(offset + SIZE_OF_INT, buffer::getLong); assertUnaligned(offset + SIZE_OF_INT, (i) -> buffer.getLong(i, BIG_ENDIAN)); assertUnaligned(offset + SIZE_OF_FLOAT, buffer::getDouble); assertUnaligned(offset + SIZE_OF_FLOAT, (i) -> buffer.getDouble(i, BIG_ENDIAN)); assertUnaligned(offset + SIZE_OF_SHORT, buffer::getInt); assertUnaligned(offset + SIZE_OF_SHORT, (i) -> buffer.getInt(i, BIG_ENDIAN)); assertUnaligned(offset + SIZE_OF_SHORT, buffer::getFloat); assertUnaligned(offset + SIZE_OF_SHORT, (i) -> buffer.getFloat(i, BIG_ENDIAN)); assertUnaligned(offset + SIZE_OF_BYTE, buffer::getShort); assertUnaligned(offset + SIZE_OF_BYTE, (i) -> buffer.getShort(i, BIG_ENDIAN)); assertUnaligned(offset + SIZE_OF_BYTE, buffer::getChar); assertUnaligned(offset + SIZE_OF_BYTE, (i) -> buffer.getChar(i, BIG_ENDIAN)); assertUnaligned(offset + SIZE_OF_SHORT, buffer::getStringUtf8); assertUnaligned(offset + SIZE_OF_SHORT, (i) -> buffer.getStringUtf8(i, BIG_ENDIAN)); assertUnaligned(offset + SIZE_OF_SHORT, buffer::getStringAscii); assertUnaligned(offset + SIZE_OF_SHORT, (i) -> buffer.getStringAscii(i, BIG_ENDIAN)); }
Example 4
Source File: HeartbeatTimestamp.java From aeron with Apache License 2.0 | 6 votes |
/** * Find the active counter id for a heartbeat timestamp. * * @param countersReader to search within. * @param counterTypeId to match on. * @param registrationId for the active client. * @return the counter id if found otherwise {@link CountersReader#NULL_COUNTER_ID}. */ public static int findCounterIdByRegistrationId( final CountersReader countersReader, final int counterTypeId, final long registrationId) { final DirectBuffer buffer = countersReader.metaDataBuffer(); for (int i = 0, size = countersReader.maxCounterId(); i < size; i++) { if (countersReader.getCounterState(i) == RECORD_ALLOCATED && countersReader.getCounterTypeId(i) == counterTypeId) { final int recordOffset = CountersReader.metaDataOffset(i); if (buffer.getLong(recordOffset + KEY_OFFSET + REGISTRATION_ID_OFFSET) == registrationId) { return i; } } } return NULL_COUNTER_ID; }
Example 5
Source File: BasicAuctionClusterClient.java From aeron with Apache License 2.0 | 6 votes |
public void onMessage( final long clusterSessionId, final long timestamp, final DirectBuffer buffer, final int offset, final int length, final Header header) { final long correlationId = buffer.getLong(offset + CORRELATION_ID_OFFSET); final long customerId = buffer.getLong(offset + CUSTOMER_ID_OFFSET); final long currentPrice = buffer.getLong(offset + PRICE_OFFSET); final boolean bidSucceed = 0 != buffer.getByte(offset + BID_SUCCEEDED_OFFSET); lastBidSeen = currentPrice; printOutput( "SessionMessage(" + clusterSessionId + ", " + correlationId + "," + customerId + ", " + currentPrice + ", " + bidSucceed + ")"); }
Example 6
Source File: LiveRecordingMessageTransceiver.java From benchmarks with Apache License 2.0 | 5 votes |
public ControlledFragmentHandler.Action onFragment( final DirectBuffer buffer, final int offset, final int length, final Header header) { if (recordingPositionConsumed == recordingPosition) { return ABORT; } final long timestamp = buffer.getLong(offset, LITTLE_ENDIAN); final long checksum = buffer.getLong(offset + length - SIZE_OF_LONG, LITTLE_ENDIAN); onMessageReceived(timestamp, checksum); recordingPositionConsumed += align(length, FRAME_ALIGNMENT); return COMMIT; }
Example 7
Source File: BufferAlignmentAgentTest.java From agrona with Apache License 2.0 | 5 votes |
private void testAlignedReadMethods(final DirectBuffer buffer, final int offset) { buffer.getLong(offset + SIZE_OF_LONG); buffer.getLong(offset + SIZE_OF_LONG, BIG_ENDIAN); buffer.getDouble(offset + SIZE_OF_DOUBLE); buffer.getDouble(offset + SIZE_OF_DOUBLE, BIG_ENDIAN); buffer.getInt(offset + SIZE_OF_INT); buffer.getInt(offset + SIZE_OF_INT, BIG_ENDIAN); buffer.getFloat(offset + SIZE_OF_FLOAT); buffer.getFloat(offset + SIZE_OF_FLOAT, BIG_ENDIAN); buffer.getShort(offset + SIZE_OF_SHORT); buffer.getShort(offset + SIZE_OF_SHORT, BIG_ENDIAN); buffer.getChar(offset + SIZE_OF_CHAR); buffer.getChar(offset + SIZE_OF_CHAR, BIG_ENDIAN); buffer.getByte(offset + SIZE_OF_BYTE); buffer.getByte(offset + SIZE_OF_BYTE); buffer.getStringUtf8(offset + SIZE_OF_INT); buffer.getStringUtf8(offset + SIZE_OF_INT, BIG_ENDIAN); buffer.getStringAscii(offset + SIZE_OF_INT); buffer.getStringAscii(offset + SIZE_OF_INT, BIG_ENDIAN); // string size is not read for these method => no need for 4-bytes // alignment buffer.getStringUtf8(offset + SIZE_OF_BYTE, 7); buffer.getStringWithoutLengthUtf8(offset + SIZE_OF_BYTE, 7); buffer.getStringAscii(offset + SIZE_OF_BYTE, 7); buffer.getStringWithoutLengthAscii(offset + SIZE_OF_BYTE, 7); }
Example 8
Source File: BasicAuctionClusteredService.java From aeron with Apache License 2.0 | 5 votes |
public void onSessionMessage( final ClientSession session, final long timestamp, final DirectBuffer buffer, final int offset, final int length, final Header header) { final long correlationId = buffer.getLong(offset + CORRELATION_ID_OFFSET); // <1> final long customerId = buffer.getLong(offset + CUSTOMER_ID_OFFSET); final long price = buffer.getLong(offset + PRICE_OFFSET); final boolean bidSucceeded = auction.attemptBid(price, customerId); // <2> if (null != session) // <3> { egressMessageBuffer.putLong(CORRELATION_ID_OFFSET, correlationId); // <4> egressMessageBuffer.putLong(CUSTOMER_ID_OFFSET, auction.getCurrentWinningCustomerId()); egressMessageBuffer.putLong(PRICE_OFFSET, auction.getBestPrice()); egressMessageBuffer.putByte(BID_SUCCEEDED_OFFSET, bidSucceeded ? (byte)1 : (byte)0); while (session.offer(egressMessageBuffer, 0, EGRESS_MESSAGE_LENGTH) < 0) // <5> { idleStrategy.idle(); // <6> } } }
Example 9
Source File: EmbeddedPingPong.java From aeron with Apache License 2.0 | 5 votes |
@SuppressWarnings("unused") private static void pongHandler(final DirectBuffer buffer, final int offset, final int length, final Header header) { final long pingTimestamp = buffer.getLong(offset); final long rttNs = System.nanoTime() - pingTimestamp; HISTOGRAM.recordValue(rttNs); }
Example 10
Source File: Ping.java From aeron with Apache License 2.0 | 5 votes |
private static void pongHandler(final DirectBuffer buffer, final int offset, final int length, final Header header) { final long pingTimestamp = buffer.getLong(offset); final long rttNs = System.nanoTime() - pingTimestamp; HISTOGRAM.recordValue(rttNs); }
Example 11
Source File: EmbeddedReplayThroughput.java From aeron with Apache License 2.0 | 5 votes |
void onMessage(final DirectBuffer buffer, final int offset, final int length, final Header header) { final long count = buffer.getLong(offset); if (count != messageCount) { throw new IllegalStateException("invalid message count=" + count + " @ " + messageCount); } messageCount++; }
Example 12
Source File: IndexedReplicatedRecording.java From aeron with Apache License 2.0 | 5 votes |
public Action onFragment(final DirectBuffer buffer, final int offset, final int length, final Header header) { final long currentPosition = lastMessagePosition; final long index = buffer.getLong(offset + MESSAGE_INDEX_OFFSET, ByteOrder.LITTLE_ENDIAN); if (index != nextMessageIndex) { throw new IllegalStateException("invalid index: expected=" + nextMessageIndex + " actual=" + index); } if (0 == batchIndex) { final long timestamp = buffer.getLong(offset + TIMESTAMP_OFFSET, ByteOrder.LITTLE_ENDIAN); timestamps.addLong(timestamp); timestampPositions.addLong(currentPosition); indexBuffer.putLong(MESSAGE_INDEX_OFFSET, nextMessageIndex, ByteOrder.LITTLE_ENDIAN); indexBuffer.putLong(TIMESTAMP_OFFSET, timestamp, ByteOrder.LITTLE_ENDIAN); } final int positionOffset = HEADER_LENGTH + (batchIndex * SIZE_OF_LONG); indexBuffer.putLong(positionOffset, currentPosition, ByteOrder.LITTLE_ENDIAN); if (++batchIndex >= BATCH_SIZE) { if (publication.offer(indexBuffer, 0, INDEX_BUFFER_CAPACITY) <= 0) { --batchIndex; return Action.ABORT; } batchIndex = 0; } messagePositions.addLong(currentPosition); lastMessagePosition = header.position(); ++nextMessageIndex; return Action.CONTINUE; }
Example 13
Source File: HeartbeatTimestamp.java From aeron with Apache License 2.0 | 5 votes |
/** * Is the counter active for usage? Checks to see if reclaimed or reused and matches registration id. * * @param countersReader to search within. * @param counterId to test. * @param counterTypeId to validate type. * @param registrationId for the entity. * @return true if still valid otherwise false. */ public static boolean isActive( final CountersReader countersReader, final int counterId, final int counterTypeId, final long registrationId) { final DirectBuffer buffer = countersReader.metaDataBuffer(); final int recordOffset = CountersReader.metaDataOffset(counterId); return countersReader.getCounterTypeId(counterId) == counterTypeId && buffer.getLong(recordOffset + KEY_OFFSET + REGISTRATION_ID_OFFSET) == registrationId && countersReader.getCounterState(counterId) == RECORD_ALLOCATED; }
Example 14
Source File: MemoryOrderingTest.java From aeron with Apache License 2.0 | 5 votes |
public void onFragment(final DirectBuffer buffer, final int offset, final int length, final Header header) { final long messageValue = buffer.getLong(offset); final long expectedValue = previousValue + 1; if (messageValue != expectedValue) { final long messageValueSecondRead = buffer.getLong(offset); final String msg = "Issue at message number transition: " + previousValue + " -> " + messageValue; System.out.println(msg + "\n" + "offset: " + offset + "\n" + "length: " + length + "\n" + "expected bytes: " + byteString(expectedValue) + "\n" + "received bytes: " + byteString(messageValue) + "\n" + "expected bits: " + Long.toBinaryString(expectedValue) + "\n" + "received bits: " + Long.toBinaryString(messageValue) + "\n" + "messageValue on second read: " + messageValueSecondRead + "\n" + "messageValue on third read: " + buffer.getLong(offset)); failedMessage = msg; } previousValue = messageValue; messageNum++; }
Example 15
Source File: RecordingPos.java From aeron with Apache License 2.0 | 5 votes |
/** * Is the recording counter still active. * * @param counters to search within. * @param counterId to search for. * @param recordingId to confirm it is still the same value. * @return true if the counter is still active otherwise false. */ public static boolean isActive(final CountersReader counters, final int counterId, final long recordingId) { final DirectBuffer buffer = counters.metaDataBuffer(); final int recordOffset = CountersReader.metaDataOffset(counterId); return counters.getCounterTypeId(counterId) == RECORDING_POSITION_TYPE_ID && buffer.getLong(recordOffset + KEY_OFFSET + RECORDING_ID_OFFSET) == recordingId && counters.getCounterState(counterId) == RECORD_ALLOCATED; }
Example 16
Source File: RecordingPos.java From aeron with Apache License 2.0 | 5 votes |
/** * Get the recording id for a given counter id. * * @param countersReader to search within. * @param counterId for the active recording. * @return the counter id if found otherwise {@link #NULL_RECORDING_ID}. */ public static long getRecordingId(final CountersReader countersReader, final int counterId) { final DirectBuffer buffer = countersReader.metaDataBuffer(); if (countersReader.getCounterState(counterId) == RECORD_ALLOCATED && countersReader.getCounterTypeId(counterId) == RECORDING_POSITION_TYPE_ID) { return buffer.getLong(CountersReader.metaDataOffset(counterId) + KEY_OFFSET + RECORDING_ID_OFFSET); } return NULL_RECORDING_ID; }
Example 17
Source File: CncFileDescriptor.java From aeron with Apache License 2.0 | 2 votes |
/** * Get the process PID hosting the driver. * * @param metaDataBuffer for the CnC file. * @return the process PID hosting the driver. */ public static long pid(final DirectBuffer metaDataBuffer) { return metaDataBuffer.getLong(pidOffset(0)); }
Example 18
Source File: CncFileDescriptor.java From aeron with Apache License 2.0 | 2 votes |
/** * Get the start timestamp in milliseconds for the media driver. * * @param metaDataBuffer for the CnC file. * @return the start timestamp in milliseconds for the media driver. */ public static long startTimestampMs(final DirectBuffer metaDataBuffer) { return metaDataBuffer.getLong(startTimestampOffset(0)); }
Example 19
Source File: CncFileDescriptor.java From aeron with Apache License 2.0 | 2 votes |
/** * Get the timeout in nanoseconds for tracking client liveness and inter-service timeout. * * @param metaDataBuffer for the CnC file. * @return the timeout in milliseconds for tracking client liveness. */ public static long clientLivenessTimeoutNs(final DirectBuffer metaDataBuffer) { return metaDataBuffer.getLong(clientLivenessTimeoutOffset(0)); }