Java Code Examples for io.aeron.logbuffer.Header#position()

The following examples show how to use io.aeron.logbuffer.Header#position() . 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: Indexer.java    From artio with Apache License 2.0 6 votes vote down vote up
public Action onFragment(final DirectBuffer buffer, final int offset, final int length, final Header header)
{
    final int streamId = header.streamId();
    final int aeronSessionId = header.sessionId();
    final long endPosition = header.position();
    DebugLogger.log(
        LogTag.INDEX,
        indexingFormatter,
        endPosition,
        streamId,
        aeronSessionId);

    for (int i = 0, size = indices.size(); i < size; i++)
    {
        final Index index = indices.get(i);
        index.onFragment(buffer, offset, length, header);
    }

    return CONTINUE;
}
 
Example 2
Source File: ILinkSequenceNumberExtractor.java    From artio with Apache License 2.0 5 votes vote down vote up
public void onFragment(
    final DirectBuffer buffer,
    final int srcOffset,
    final int srcLength,
    final Header header)
{
    final long endPosition = header.position();

    if ((header.flags() & BEGIN_AND_END_FLAGS) == BEGIN_AND_END_FLAGS)
    {
        int offset = srcOffset;
        messageHeader.wrap(buffer, offset);

        offset += messageHeader.encodedLength();
        final int actingBlockLength = messageHeader.blockLength();
        final int version = messageHeader.version();
        final int templateId = messageHeader.templateId();


        switch (templateId)
        {
            case ILinkMessageDecoder.TEMPLATE_ID:
            {
                final int totalLength = BitUtil.align(srcLength, FRAME_ALIGNMENT);

                onILinkMessage(
                    buffer, endPosition, offset, actingBlockLength, version, totalLength, header.sessionId());
                break;
            }

            case ILinkConnectDecoder.TEMPLATE_ID:
            {
                iLinkConnect.wrap(buffer, offset, actingBlockLength, version);
                connectionIdToILinkUuid.put(iLinkConnect.connection(), iLinkConnect.uuid());
                break;
            }
        }
    }
}
 
Example 3
Source File: Indexer.java    From artio with Apache License 2.0 5 votes vote down vote up
private Action quiesceFragment(final DirectBuffer buffer, final int offset, final int length, final Header header)
{
    if (completedPosition(header.sessionId()) <= header.position())
    {
        return onFragment(buffer, offset, length, header);
    }

    return CONTINUE;
}
 
Example 4
Source File: IndexedReplicatedRecording.java    From aeron with Apache License 2.0 5 votes vote down vote up
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 5
Source File: SequenceNumberIndexWriter.java    From artio with Apache License 2.0 4 votes vote down vote up
private void onFragment(
    final DirectBuffer buffer,
    final int srcOffset,
    final int length,
    final Header header,
    final long recordingId)
{
    final long endPosition = header.position();
    final int aeronSessionId = header.sessionId();

    int offset = srcOffset;
    messageHeader.wrap(buffer, offset);

    offset += messageHeader.encodedLength();
    final int actingBlockLength = messageHeader.blockLength();
    final int version = messageHeader.version();
    final int templateId = messageHeader.templateId();

    if ((header.flags() & BEGIN_FLAG) == BEGIN_FLAG)
    {
        switch (templateId)
        {
            case FixMessageEncoder.TEMPLATE_ID:
            {
                if (!onFixMessage(buffer, offset, actingBlockLength, version, endPosition))
                {
                    return;
                }
                break;
            }

            case ResetSessionIdsDecoder.TEMPLATE_ID:
            {
                resetSequenceNumbers();
                break;
            }

            case ResetSequenceNumberDecoder.TEMPLATE_ID:
            {
                resetSequenceNumber.wrap(buffer, offset, actingBlockLength, version);
                resetSequenceNumber(resetSequenceNumber.session(), endPosition);
                break;
            }

            case WriteMetaDataDecoder.TEMPLATE_ID:
            {
                writeMetaData.wrap(buffer, offset, actingBlockLength, version);
                onWriteMetaData();
                break;
            }

            case RedactSequenceUpdateDecoder.TEMPLATE_ID:
            {
                redactSequenceUpdate.wrap(buffer, offset, actingBlockLength, version);
                onRedactSequenceUpdate();
                break;
            }

            default:
            {
                iLinkSequenceNumberExtractor.onFragment(buffer, srcOffset, length, header);
                break;
            }
        }
    }

    checkTermRoll(buffer, srcOffset, endPosition, length);
    positionWriter.update(aeronSessionId, templateId, endPosition, recordingId);
}