Java Code Examples for org.agrona.concurrent.UnsafeBuffer#getLong()

The following examples show how to use org.agrona.concurrent.UnsafeBuffer#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: Catalog.java    From aeron with Apache License 2.0 5 votes vote down vote up
private static boolean isEmptyPage(final UnsafeBuffer buffer, final int pageStart, final int endOffset)
{
    for (int i = pageStart, pageEnd = min(pageStart + PAGE_SIZE, endOffset); i < pageEnd; i += SIZE_OF_LONG)
    {
        if (0L != buffer.getLong(i))
        {
            return false;
        }
    }

    return true;
}
 
Example 2
Source File: RecordingLog.java    From aeron with Apache License 2.0 5 votes vote down vote up
private void captureEntriesFromBuffer(
    final ByteBuffer byteBuffer, final UnsafeBuffer buffer, final ArrayList<Entry> entries)
{
    for (int i = 0, length = byteBuffer.limit(); i < length; i += ENTRY_LENGTH)
    {
        final int entryType = buffer.getInt(i + ENTRY_TYPE_OFFSET);

        if (NULL_VALUE != entryType)
        {
            final int type = entryType & ~ENTRY_TYPE_INVALID_FLAG;
            final boolean isValid = (entryType & ENTRY_TYPE_INVALID_FLAG) == 0;

            final Entry entry = new Entry(
                buffer.getLong(i + RECORDING_ID_OFFSET, LITTLE_ENDIAN),
                buffer.getLong(i + LEADERSHIP_TERM_ID_OFFSET, LITTLE_ENDIAN),
                buffer.getLong(i + TERM_BASE_LOG_POSITION_OFFSET, LITTLE_ENDIAN),
                buffer.getLong(i + LOG_POSITION_OFFSET, LITTLE_ENDIAN),
                buffer.getLong(i + TIMESTAMP_OFFSET, LITTLE_ENDIAN),
                buffer.getInt(i + SERVICE_ID_OFFSET, LITTLE_ENDIAN),
                type,
                isValid,
                nextEntryIndex);

            entries.add(entry);

            if (isValidTerm(entry))
            {
                cacheIndexByLeadershipTermIdMap.put(entry.leadershipTermId, entries.size() - 1);
            }

            if (ENTRY_TYPE_SNAPSHOT == entry.type && !entry.isValid)
            {
                invalidSnapshots.add(entries.size() - 1);
            }
        }

        ++nextEntryIndex;
    }
}
 
Example 3
Source File: RecordingReader.java    From aeron with Apache License 2.0 4 votes vote down vote up
int poll(final SimpleFragmentHandler fragmentHandler, final int fragmentLimit)
{
    int fragments = 0;

    while (replayPosition < replayLimit && fragments < fragmentLimit)
    {
        if (termOffset == termLength)
        {
            nextTerm();
        }

        final int frameOffset = termOffset;
        final UnsafeBuffer termBuffer = this.termBuffer;
        final int frameLength = FrameDescriptor.frameLength(termBuffer, frameOffset);
        if (frameLength <= 0)
        {
            isDone = true;
            closeRecordingSegment();
            break;
        }

        final int frameType = FrameDescriptor.frameType(termBuffer, frameOffset);
        final byte flags = FrameDescriptor.frameFlags(termBuffer, frameOffset);
        final long reservedValue = termBuffer.getLong(frameOffset + RESERVED_VALUE_OFFSET, LITTLE_ENDIAN);

        final int alignedLength = BitUtil.align(frameLength, FRAME_ALIGNMENT);
        final int dataOffset = frameOffset + DataHeaderFlyweight.HEADER_LENGTH;
        final int dataLength = frameLength - DataHeaderFlyweight.HEADER_LENGTH;

        fragmentHandler.onFragment(termBuffer, dataOffset, dataLength, frameType, flags, reservedValue);

        replayPosition += alignedLength;
        termOffset += alignedLength;
        fragments++;

        if (replayPosition >= replayLimit)
        {
            isDone = true;
            closeRecordingSegment();
            break;
        }
    }

    return fragments;
}
 
Example 4
Source File: DataHeaderFlyweight.java    From aeron with Apache License 2.0 2 votes vote down vote up
/**
 * Get the reserved value field from the header.
 *
 * @param termBuffer  container the header.
 * @param frameOffset in the buffer where the header starts.
 * @return the reserved value field from the header.
 */
public static long reservedValue(final UnsafeBuffer termBuffer, final int frameOffset)
{
    return termBuffer.getLong(frameOffset + RESERVED_VALUE_OFFSET, LITTLE_ENDIAN);
}
 
Example 5
Source File: LogBufferDescriptor.java    From aeron with Apache License 2.0 2 votes vote down vote up
/**
 * Get the value of the correlation ID for this log relating to the command which created it.
 *
 * @param metadataBuffer containing the meta data.
 * @return the value of the correlation ID used for this log.
 */
public static long correlationId(final UnsafeBuffer metadataBuffer)
{
    return metadataBuffer.getLong(LOG_CORRELATION_ID_OFFSET);
}
 
Example 6
Source File: LogBufferDescriptor.java    From aeron with Apache License 2.0 2 votes vote down vote up
/**
 * Get the raw value of the tail for the given partition.
 *
 * @param metadataBuffer containing the tail counters.
 * @param partitionIndex for the tail counter.
 * @return the raw value of the tail for the current active partition.
 */
public static long rawTail(final UnsafeBuffer metadataBuffer, final int partitionIndex)
{
    return metadataBuffer.getLong(TERM_TAIL_COUNTERS_OFFSET + (SIZE_OF_LONG * partitionIndex));
}