Java Code Examples for org.agrona.DirectBuffer#getInt()
The following examples show how to use
org.agrona.DirectBuffer#getInt() .
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 session id. * * @param countersReader to search within. * @param sessionId for the active recording. * @return the counter id if found otherwise {@link CountersReader#NULL_COUNTER_ID}. */ public static int findCounterIdBySession(final CountersReader countersReader, final int sessionId) { 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.getInt(CountersReader.metaDataOffset(i) + KEY_OFFSET + SESSION_ID_OFFSET) == sessionId) { return i; } } } return NULL_COUNTER_ID; }
Example 3
Source File: SamplesUtil.java From aeron with Apache License 2.0 | 6 votes |
/** * Map an existing CnC file. * * @param cncFileVersion to set as value of file. * @return the {@link CountersReader} over the CnC file. */ public static CountersReader mapCounters(final MutableInteger cncFileVersion) { final File cncFile = CommonContext.newDefaultCncFile(); System.out.println("Command `n Control file " + cncFile); final MappedByteBuffer cncByteBuffer = mapExistingFileReadOnly(cncFile); final DirectBuffer cncMetaData = createMetaDataBuffer(cncByteBuffer); final int cncVersion = cncMetaData.getInt(cncVersionOffset(0)); cncFileVersion.set(cncVersion); checkVersion(cncVersion); return new CountersReader( createCountersMetaDataBuffer(cncByteBuffer, cncMetaData), createCountersValuesBuffer(cncByteBuffer, cncMetaData)); }
Example 4
Source File: SamplesUtil.java From aeron with Apache License 2.0 | 6 votes |
/** * Map an existing CnC file. * * @return the {@link CountersReader} over the CnC file. */ public static CountersReader mapCounters() { final File cncFile = CommonContext.newDefaultCncFile(); System.out.println("Command `n Control file " + cncFile); final MappedByteBuffer cncByteBuffer = mapExistingFileReadOnly(cncFile); final DirectBuffer cncMetaData = createMetaDataBuffer(cncByteBuffer); final int cncVersion = cncMetaData.getInt(cncVersionOffset(0)); checkVersion(cncVersion); return new CountersReader( createCountersMetaDataBuffer(cncByteBuffer, cncMetaData), createCountersValuesBuffer(cncByteBuffer, cncMetaData)); }
Example 5
Source File: CncFileReader.java From aeron with Apache License 2.0 | 6 votes |
private CncFileReader(final MappedByteBuffer cncByteBuffer) { this.cncByteBuffer = cncByteBuffer; final DirectBuffer cncMetaDataBuffer = createMetaDataBuffer(cncByteBuffer); final int cncVersion = cncMetaDataBuffer.getInt(cncVersionOffset(0)); try { checkVersion(cncVersion); } catch (final AeronException e) { IoUtil.unmap(cncByteBuffer); throw e; } this.cncVersion = cncVersion; this.cncSemanticVersion = SemanticVersion.toString(cncVersion); this.toDriverBuffer = CncFileDescriptor.createToDriverBuffer(cncByteBuffer, cncMetaDataBuffer); this.countersReader = new CountersReader( createCountersMetaDataBuffer(cncByteBuffer, cncMetaDataBuffer), createCountersValuesBuffer(cncByteBuffer, cncMetaDataBuffer)); }
Example 6
Source File: CncFileDescriptor.java From aeron with Apache License 2.0 | 5 votes |
/** * Create the buffer which wraps the section in the CnC file for the counter values. * * @param buffer for the CnC file. * @param metaDataBuffer within the CnC file. * @return a buffer which wraps the section in the CnC file for the counter values. */ public static UnsafeBuffer createCountersValuesBuffer(final ByteBuffer buffer, final DirectBuffer metaDataBuffer) { final int offset = END_OF_METADATA_OFFSET + metaDataBuffer.getInt(toDriverBufferLengthOffset(0)) + metaDataBuffer.getInt(toClientsBufferLengthOffset(0)) + metaDataBuffer.getInt(countersMetaDataBufferLengthOffset(0)); return new UnsafeBuffer(buffer, offset, metaDataBuffer.getInt(countersValuesBufferLengthOffset(0))); }
Example 7
Source File: AeronStat.java From nd4j with Apache License 2.0 | 5 votes |
public static CountersReader mapCounters() { final File cncFile = CommonContext.newDefaultCncFile(); System.out.println("Command `n Control file " + cncFile); final MappedByteBuffer cncByteBuffer = IoUtil.mapExistingFile(cncFile, "cnc"); final DirectBuffer cncMetaData = createMetaDataBuffer(cncByteBuffer); final int cncVersion = cncMetaData.getInt(cncVersionOffset(0)); if (CncFileDescriptor.CNC_VERSION != cncVersion) { throw new IllegalStateException("CnC version not supported: file version=" + cncVersion); } return new CountersReader(createCountersMetaDataBuffer(cncByteBuffer, cncMetaData), createCountersValuesBuffer(cncByteBuffer, cncMetaData)); }
Example 8
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 9
Source File: FileReceiver.java From aeron with Apache License 2.0 | 5 votes |
@SuppressWarnings("unused") public void onFragment(final DirectBuffer buffer, final int offset, final int length, final Header header) { final int version = buffer.getInt(offset + VERSION_OFFSET, LITTLE_ENDIAN); if (VERSION != version) { throw new IllegalArgumentException("unsupported version " + version + " expected " + VERSION); } final int messageType = buffer.getInt(offset + TYPE_OFFSET, LITTLE_ENDIAN); switch (messageType) { case FILE_CREATE_TYPE: createFile( buffer.getLong(offset + CORRELATION_ID_OFFSET, LITTLE_ENDIAN), buffer.getLong(offset + FILE_LENGTH_OFFSET, LITTLE_ENDIAN), buffer.getStringUtf8(offset + FILE_NAME_OFFSET, LITTLE_ENDIAN)); break; case FILE_CHUNK_TYPE: fileChunk( buffer.getLong(offset + CORRELATION_ID_OFFSET, LITTLE_ENDIAN), buffer.getLong(offset + CHUNK_OFFSET_OFFSET, LITTLE_ENDIAN), buffer.getLong(offset + CHUNK_LENGTH_OFFSET, LITTLE_ENDIAN), buffer, offset); break; default: throw new IllegalArgumentException("unknown message type: " + messageType); } }
Example 10
Source File: CommonContext.java From aeron with Apache License 2.0 | 5 votes |
/** * Get an {@link AtomicBuffer} which wraps the error log in the CnC file. * * @param cncByteBuffer which contains the error log. * @return an {@link AtomicBuffer} which wraps the error log in the CnC file. */ public static AtomicBuffer errorLogBuffer(final ByteBuffer cncByteBuffer) { final DirectBuffer cncMetaDataBuffer = CncFileDescriptor.createMetaDataBuffer(cncByteBuffer); final int cncVersion = cncMetaDataBuffer.getInt(cncVersionOffset(0)); CncFileDescriptor.checkVersion(cncVersion); return CncFileDescriptor.createErrorLogBuffer(cncByteBuffer, cncMetaDataBuffer); }
Example 11
Source File: Types.java From simple-binary-encoding with Apache License 2.0 | 5 votes |
/** * Get an integer value from a buffer at a given index for a {@link PrimitiveType}. * * @param buffer from which to read. * @param index at which he integer should be read. * @param type of the integer encoded in the buffer. * @param byteOrder of the integer in the buffer. * @return the value of the encoded integer. */ public static int getInt( final DirectBuffer buffer, final int index, final PrimitiveType type, final ByteOrder byteOrder) { switch (type) { case INT8: return buffer.getByte(index); case UINT8: return (short)(buffer.getByte(index) & 0xFF); case INT16: return buffer.getShort(index, byteOrder); case UINT16: return buffer.getShort(index, byteOrder) & 0xFFFF; case INT32: return buffer.getInt(index, byteOrder); case UINT32: final int value = buffer.getInt(index, byteOrder); if (value < 0) { throw new IllegalStateException( "UINT32 type should not be greater than Integer.MAX_VALUE: value=" + value); } return value; default: throw new IllegalArgumentException("Unsupported type: " + type); } }
Example 12
Source File: CncFileDescriptor.java From aeron with Apache License 2.0 | 5 votes |
/** * Create the buffer which wraps the section in the CnC file for the counters metadata. * * @param buffer for the CnC file. * @param metaDataBuffer within the CnC file. * @return a buffer which wraps the section in the CnC file for the counters metadata. */ public static UnsafeBuffer createCountersMetaDataBuffer(final ByteBuffer buffer, final DirectBuffer metaDataBuffer) { final int offset = END_OF_METADATA_OFFSET + metaDataBuffer.getInt(toDriverBufferLengthOffset(0)) + metaDataBuffer.getInt(toClientsBufferLengthOffset(0)); return new UnsafeBuffer(buffer, offset, metaDataBuffer.getInt(countersMetaDataBufferLengthOffset(0))); }
Example 13
Source File: ClusterTool.java From aeron with Apache License 2.0 | 5 votes |
private static void printDriverErrors(final PrintStream out, final String aeronDirectory) { out.println("Aeron driver error log (directory: " + aeronDirectory + "):"); final File cncFile = new File(aeronDirectory, CncFileDescriptor.CNC_FILE); final MappedByteBuffer cncByteBuffer = IoUtil.mapExistingFile(cncFile, FileChannel.MapMode.READ_ONLY, "cnc"); final DirectBuffer cncMetaDataBuffer = CncFileDescriptor.createMetaDataBuffer(cncByteBuffer); final int cncVersion = cncMetaDataBuffer.getInt(CncFileDescriptor.cncVersionOffset(0)); CncFileDescriptor.checkVersion(cncVersion); CommonContext.printErrorLog(CncFileDescriptor.createErrorLogBuffer(cncByteBuffer, cncMetaDataBuffer), out); }
Example 14
Source File: AeronIpcBenchmark.java From benchmarks with Apache License 2.0 | 5 votes |
public void onFragment(final DirectBuffer buffer, final int offset, final int length, final Header header) { final int value = buffer.getInt(offset); if (value >= 0) { final Queue<Integer> responseQueue = responseQueues[value]; while (!responseQueue.offer(SENTINEL)) { ThreadHints.onSpinWait(); } } }
Example 15
Source File: AeronExclusiveIpcBenchmark.java From benchmarks with Apache License 2.0 | 5 votes |
public void onFragment(final DirectBuffer buffer, final int offset, final int length, final Header header) { final int value = buffer.getInt(offset); if (value >= 0) { final Queue<Integer> responseQueue = responseQueues[value]; while (!responseQueue.offer(SENTINEL)) { ThreadHints.onSpinWait(); } } }
Example 16
Source File: ILink3Offsets.java From artio with Apache License 2.0 | 5 votes |
public int seqNum(final int templateId, final DirectBuffer buffer, final int messageOffset) { final int seqNumOffset = seqNumOffset(templateId); if (seqNumOffset == MISSING_OFFSET) { return MISSING_OFFSET; } return buffer.getInt(messageOffset + seqNumOffset, LITTLE_ENDIAN); }
Example 17
Source File: CursorParamTest.java From lmdbjava with Apache License 2.0 | 4 votes |
@Override public int get(final DirectBuffer buff) { return buff.getInt(0); }
Example 18
Source File: DriverTool.java From aeron with Apache License 2.0 | 4 votes |
public static void main(final String[] args) { boolean printPidOnly = false; boolean terminateDriver = false; if (0 != args.length) { checkForHelp(args); if (args[0].equals("pid")) { printPidOnly = true; } else if (args[0].equals("terminate")) { terminateDriver = true; } } final File cncFile = CommonContext.newDefaultCncFile(); final MappedByteBuffer cncByteBuffer = IoUtil.mapExistingFile(cncFile, "cnc"); final DirectBuffer cncMetaData = createMetaDataBuffer(cncByteBuffer); final int cncVersion = cncMetaData.getInt(cncVersionOffset(0)); checkVersion(cncVersion); final ManyToOneRingBuffer toDriver = new ManyToOneRingBuffer(createToDriverBuffer(cncByteBuffer, cncMetaData)); if (printPidOnly) { System.out.println(pid(cncMetaData)); } else if (terminateDriver) { final DriverProxy driverProxy = new DriverProxy(toDriver, toDriver.nextCorrelationId()); if (!driverProxy.terminateDriver(null, 0, 0)) { throw new AeronException("could not send termination request."); } } else { System.out.println("Command `n Control file: " + cncFile); System.out.format("Version: %d, PID: %d%n", cncVersion, pid(cncMetaData)); printDateActivityAndStartTimestamps(startTimestampMs(cncMetaData), toDriver.consumerHeartbeatTime()); } }
Example 19
Source File: CncFileDescriptor.java From aeron with Apache License 2.0 | 3 votes |
/** * Create the buffer which wraps the section in the CnC file for the broadcast buffer from the driver to clients. * * @param buffer for the CnC file. * @param metaDataBuffer within the CnC file. * @return a buffer which wraps the section in the CnC file for the broadcast buffer from the driver to clients. */ public static UnsafeBuffer createToClientsBuffer(final ByteBuffer buffer, final DirectBuffer metaDataBuffer) { final int offset = END_OF_METADATA_OFFSET + metaDataBuffer.getInt(toDriverBufferLengthOffset(0)); return new UnsafeBuffer(buffer, offset, metaDataBuffer.getInt(toClientsBufferLengthOffset(0))); }
Example 20
Source File: CncFileDescriptor.java From aeron with Apache License 2.0 | 2 votes |
/** * Create the buffer which wraps the area in the CnC file for the command buffer from clients to the driver. * * @param buffer for the CnC file. * @param metaDataBuffer within the CnC file. * @return a buffer which wraps the section in the CnC file for the command buffer from clients to the driver. */ public static UnsafeBuffer createToDriverBuffer(final ByteBuffer buffer, final DirectBuffer metaDataBuffer) { return new UnsafeBuffer(buffer, END_OF_METADATA_OFFSET, metaDataBuffer.getInt(toDriverBufferLengthOffset(0))); }