io.aeron.logbuffer.Header Java Examples

The following examples show how to use io.aeron.logbuffer.Header. 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: BenchClient.java    From rpc-bench with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("PMD.UnusedFormalParameter")
private void onMessage(final DirectBuffer buffer, final int offset,
                       final int length, final Header header) {
  final int msgOffset = MessageHeaderDecoder.ENCODED_LENGTH + offset;
  HDR_D.wrap(buffer, offset);
  switch (HDR_D.templateId()) {
    case PongDecoder.TEMPLATE_ID:
      onPong(buffer, msgOffset, HDR_D.blockLength(), HDR_D.version());
      break;
    case PriceDecoder.TEMPLATE_ID:
      onPrice(buffer, msgOffset, HDR_D.blockLength(), HDR_D.version());
      break;
    default:
      throw new IllegalStateException("Unknown message template");
  }
}
 
Example #2
Source File: EngineProtocolSubscription.java    From artio with Apache License 2.0 6 votes vote down vote up
private Action onLibraryConnect(
    final DirectBuffer buffer,
    final int offset,
    final int blockLength,
    final int version,
    final Header header)
{
    libraryConnect.wrap(buffer, offset, blockLength, version);
    final int libraryId = libraryConnect.libraryId();
    final String libraryName = libraryConnect.libraryName();

    return handler.onLibraryConnect(
        libraryId,
        libraryName,
        libraryConnect.correlationId(),
        header.sessionId());
}
 
Example #3
Source File: EngineProtocolSubscription.java    From artio with Apache License 2.0 6 votes vote down vote up
private Action onRequestDisconnect(
    final DirectBuffer buffer,
    final int offset,
    final int blockLength,
    final int version,
    final Header header)
{
    requestDisconnect.wrap(buffer, offset, blockLength, version);
    final int libraryId = requestDisconnect.libraryId();
    final Action action = handler.onApplicationHeartbeat(libraryId, header.sessionId());
    if (action != null)
    {
        return action; // Continue processing messages, but not this message.
    }
    return handler.onRequestDisconnect(
        libraryId,
        requestDisconnect.connection(),
        requestDisconnect.reason());
}
 
Example #4
Source File: EngineProtocolSubscription.java    From artio with Apache License 2.0 6 votes vote down vote up
private Action onFollowerSessionRequest(
    final DirectBuffer buffer,
    final int offset,
    final int blockLength,
    final int version,
    final Header header)
{
    followerSessionRequest.wrap(buffer, offset, blockLength, version);
    final int libraryId = followerSessionRequest.libraryId();
    final Action action = handler.onApplicationHeartbeat(libraryId, header.sessionId());
    if (action != null)
    {
        return action; // Continue processing messages, but not this message.
    }
    final int messageLength = followerSessionRequest.headerLength();
    return handler.onFollowerSessionRequest(
        libraryId,
        followerSessionRequest.correlationId(),
        buffer,
        offset + FOLLOWER_SESSION_REQUEST_LENGTH,
        messageLength,
        header);
}
 
Example #5
Source File: EngineProtocolSubscription.java    From artio with Apache License 2.0 6 votes vote down vote up
private Action onRequestSession(
    final DirectBuffer buffer,
    final int offset,
    final int blockLength,
    final int version,
    final Header header)
{
    requestSession.wrap(buffer, offset, blockLength, version);
    final int libraryId = requestSession.libraryId();
    final Action action = handler.onApplicationHeartbeat(libraryId, header.sessionId());
    if (action != null)
    {
        return action; // Continue processing messages but not this message.
    }

    return handler.onRequestSession(
        libraryId,
        requestSession.sessionId(),
        requestSession.correlationId(),
        requestSession.lastReceivedSequenceNumber(),
        requestSession.sequenceIndex());
}
 
Example #6
Source File: BasicAuctionClusterClient.java    From aeron with Apache License 2.0 6 votes vote down vote up
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 #7
Source File: EngineProtocolSubscription.java    From artio with Apache License 2.0 6 votes vote down vote up
private Action onReplayMessages(
    final DirectBuffer buffer,
    final int offset,
    final int blockLength,
    final int version,
    final Header header)
{
    replayMessages.wrap(buffer, offset, blockLength, version);
    final int libraryId = replayMessages.libraryId();
    final Action action = handler.onApplicationHeartbeat(libraryId, header.sessionId());
    if (action != null)
    {
        return action; // Continue processing messages, but not this message.
    }
    return handler.onReplayMessages(
        libraryId,
        replayMessages.session(),
        replayMessages.correlationId(),
        replayMessages.replayFromSequenceNumber(),
        replayMessages.replayToSequenceIndex(),
        replayMessages.replayToSequenceNumber(),
        replayMessages.replayToSequenceIndex(),
        replayMessages.latestReplyArrivalTimeInMs());
}
 
Example #8
Source File: EngineEndPointHandler.java    From artio with Apache License 2.0 6 votes vote down vote up
Action onInitiateConnection(
int libraryId,
int port,
String host,
String senderCompId,
String senderSubId,
String senderLocationId,
String targetCompId,
String targetSubId,
String targetLocationId,
SequenceNumberType sequenceNumberType,
int requestedInitialSequenceNumber,
int requestedInitialSentSequenceNumber,
boolean resetSequenceNumber,
boolean closedResendInterval,
int resendRequestChunkSize,
boolean sendRedundantResendRequests,
boolean enableLastMsgSeqNumProcessed,
String username,
String password,
Class<? extends FixDictionary> fixDictionary,
int heartbeatIntervalInS,
long correlationId,
Header header);
 
Example #9
Source File: ILink3MessageTracker.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)
{
    messageHeaderDecoder.wrap(buffer, offset);

    if (messageHeaderDecoder.templateId() == ILinkMessageDecoder.TEMPLATE_ID)
    {
        final Action action = messageHandler.onFragment(buffer, offset, length, header);
        if (action != ABORT)
        {
            count++;
        }

        return action;
    }

    return CONTINUE;
}
 
Example #10
Source File: ImageFragmentAssembler.java    From aeron with Apache License 2.0 6 votes vote down vote up
private void handleFragment(
    final DirectBuffer buffer, final int offset, final int length, final Header header, final byte flags)
{
    if ((flags & BEGIN_FRAG_FLAG) == BEGIN_FRAG_FLAG)
    {
        builder.reset().append(buffer, offset, length);
    }
    else if (builder.limit() > 0)
    {
        builder.append(buffer, offset, length);

        if ((flags & END_FRAG_FLAG) == END_FRAG_FLAG)
        {
            final int msgLength = builder.limit();
            delegate.onFragment(builder.buffer(), 0, msgLength, header);
            builder.reset();
        }
    }
}
 
Example #11
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 #12
Source File: BaseTransport.java    From nd4j with Apache License 2.0 6 votes vote down vote up
/**
 * This message handler is responsible for receiving messages on Shard side
 *
 * @param buffer
 * @param offset
 * @param length
 * @param header
 */
protected void shardMessageHandler(DirectBuffer buffer, int offset, int length, Header header) {
    /**
     * All incoming messages here are supposed to be unicast messages.
     */
    // TODO: implement fragmentation handler here PROBABLY. Or forbid messages > MTU?
    //log.info("shardMessageHandler message request incoming...");
    byte[] data = new byte[length];
    buffer.getBytes(offset, data);

    VoidMessage message = VoidMessage.fromBytes(data);
    if (message.getMessageType() == 7) {
        // if that's vector request message - it's special case, we don't send it to other shards yet
        //log.info("Shortcut for vector request");
        messages.add(message);
    } else {
        // and send it away to other Shards
        publicationForShards.offer(buffer, offset, length);
    }
}
 
Example #13
Source File: BaseTransport.java    From deeplearning4j with Apache License 2.0 6 votes vote down vote up
/**
 * This message handler is responsible for receiving messages on Shard side
 *
 * @param buffer
 * @param offset
 * @param length
 * @param header
 */
protected void shardMessageHandler(DirectBuffer buffer, int offset, int length, Header header) {
    /**
     * All incoming messages here are supposed to be unicast messages.
     */
    // TODO: implement fragmentation handler here PROBABLY. Or forbid messages > MTU?
    //log.info("shardMessageHandler message request incoming...");
    byte[] data = new byte[length];
    buffer.getBytes(offset, data);

    VoidMessage message = VoidMessage.fromBytes(data);
    if (message.getMessageType() == 7) {
        // if that's vector request message - it's special case, we don't send it to other shards yet
        //log.info("Shortcut for vector request");
        messages.add(message);
    } else {
        // and send it away to other Shards
        publicationForShards.offer(buffer, offset, length);
    }
}
 
Example #14
Source File: AeronUdpTransport.java    From deeplearning4j with Apache License 2.0 6 votes vote down vote up
/**
 * This method converts aeron buffer into VoidMessage and puts into temp queue for further processing
 *
 * @param buffer
 * @param offset
 * @param length
 * @param header
 */
protected void jointMessageHandler(DirectBuffer buffer, int offset, int length, Header header) {
    byte[] data = new byte[length];
    buffer.getBytes(offset, data);

    // deserialize message
    val message = VoidMessage.fromBytes(data);

    // we're checking if this is known connection or not, and add it if not
    if (!remoteConnections.containsKey(message.getOriginatorId()))
        addConnection(message.getOriginatorId());

    log.debug("Got [{}] message from [{}]", message.getClass().getSimpleName(), message.getOriginatorId());

    // we're just putting deserialized message into the buffer
    try {
        messageQueue.put(message);
    } catch (InterruptedException e) {
        // :(
        throw new RuntimeException(e);
    }
}
 
Example #15
Source File: SubscriptionTest.java    From aeron with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldReadData()
{
    subscription.addImage(imageOneMock);

    when(imageOneMock.poll(any(FragmentHandler.class), anyInt())).then(
        (invocation) ->
        {
            final FragmentHandler handler = (FragmentHandler)invocation.getArguments()[0];
            handler.onFragment(atomicReadBuffer, HEADER_LENGTH, READ_BUFFER_CAPACITY - HEADER_LENGTH, header);

            return 1;
        });

    assertEquals(1, subscription.poll(fragmentHandler, FRAGMENT_COUNT_LIMIT));
    verify(fragmentHandler).onFragment(
        eq(atomicReadBuffer),
        eq(HEADER_LENGTH),
        eq(READ_BUFFER_CAPACITY - HEADER_LENGTH),
        any(Header.class));
}
 
Example #16
Source File: ControlledMessageTest.java    From aeron 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)
{
    ++fragmentCount;

    Action action = Action.CONTINUE;

    if (fragmentCount == 3)
    {
        action = Action.ABORT;
    }
    else if (fragmentCount == 5)
    {
        action = Action.BREAK;
    }

    if (Action.ABORT != action)
    {
        collectedBuffer.putBytes(limit, buffer, offset, length);
        limit += length;
    }

    return action;
}
 
Example #17
Source File: ArchiveTest.java    From aeron with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unused")
private void validateFragment(final DirectBuffer buffer, final int offset, final int length, final Header header)
{
    assertEquals(messageLengths[messageCount] - HEADER_LENGTH, length);
    assertEquals(messageCount, buffer.getInt(offset));
    assertEquals((byte)'z', buffer.getByte(offset + 4));

    remaining -= BitUtil.align(messageLengths[messageCount], FrameDescriptor.FRAME_ALIGNMENT);
    messageCount++;
}
 
Example #18
Source File: FragmentAssemblerTest.java    From aeron with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldAssembleFourPartMessage()
{
    when(header.flags())
        .thenReturn(FrameDescriptor.BEGIN_FRAG_FLAG)
        .thenReturn((byte)0)
        .thenReturn((byte)0)
        .thenReturn(FrameDescriptor.END_FRAG_FLAG);

    final UnsafeBuffer srcBuffer = new UnsafeBuffer(new byte[1024]);
    final int offset = 0;
    final int length = srcBuffer.capacity() / 4;

    for (int i = 0; i < 4; i++)
    {
        srcBuffer.setMemory(i * length, length, (byte)(65 + i));
    }

    adapter.onFragment(srcBuffer, offset, length, header);
    adapter.onFragment(srcBuffer, offset + length, length, header);
    adapter.onFragment(srcBuffer, offset + (length * 2), length, header);
    adapter.onFragment(srcBuffer, offset + (length * 3), length, header);

    final ArgumentCaptor<UnsafeBuffer> bufferArg = ArgumentCaptor.forClass(UnsafeBuffer.class);
    final ArgumentCaptor<Header> headerArg = ArgumentCaptor.forClass(Header.class);

    verify(delegateFragmentHandler, times(1)).onFragment(
        bufferArg.capture(), eq(offset), eq(length * 4), headerArg.capture());

    final UnsafeBuffer capturedBuffer = bufferArg.getValue();
    for (int i = 0; i < srcBuffer.capacity(); i++)
    {
        assertEquals(srcBuffer.getByte(i), capturedBuffer.getByte(i), "same at i=" + i);
    }

    final Header capturedHeader = headerArg.getValue();
    assertEquals(SESSION_ID, capturedHeader.sessionId());
    assertEquals(FrameDescriptor.END_FRAG_FLAG, capturedHeader.flags());
}
 
Example #19
Source File: MultiDestinationSubscriptionTest.java    From aeron with Apache License 2.0 5 votes vote down vote up
private void verifyFragments(final FragmentHandler fragmentHandler, final int numMessagesToSend)
{
    verify(fragmentHandler, times(numMessagesToSend)).onFragment(
        any(DirectBuffer.class),
        anyInt(),
        eq(MESSAGE_LENGTH),
        any(Header.class));
}
 
Example #20
Source File: MultiDestinationCastTest.java    From aeron with Apache License 2.0 5 votes vote down vote up
private void verifyFragments(final FragmentHandler fragmentHandler, final int numMessagesToSend)
{
    verify(fragmentHandler, times(numMessagesToSend)).onFragment(
        any(DirectBuffer.class),
        anyInt(),
        eq(MESSAGE_LENGTH),
        any(Header.class));
}
 
Example #21
Source File: PubAndSubTest.java    From aeron with Apache License 2.0 5 votes vote down vote up
@ParameterizedTest
@MethodSource("channels")
@Timeout(10)
public void shouldContinueAfterBufferRollover(final String channel)
{
    final int termBufferLength = 64 * 1024;
    final int numMessagesInTermBuffer = 64;
    final int messageLength = (termBufferLength / numMessagesInTermBuffer) - HEADER_LENGTH;
    final int numMessagesToSend = numMessagesInTermBuffer + 1;

    context.publicationTermBufferLength(termBufferLength);

    launch(channel);

    for (int i = 0; i < numMessagesToSend; i++)
    {
        while (publication.offer(buffer, 0, messageLength) < 0L)
        {
            Tests.yield();
        }

        pollForFragment();
    }

    verify(fragmentHandler, times(numMessagesToSend)).onFragment(
        any(DirectBuffer.class),
        anyInt(),
        eq(messageLength),
        any(Header.class));
}
 
Example #22
Source File: MultiModuleSharedDriverTest.java    From aeron with Apache License 2.0 5 votes vote down vote up
public void onSessionMessage(
    final ClientSession session,
    final long timestamp,
    final DirectBuffer buffer,
    final int offset,
    final int length,
    final Header header)
{
    idleStrategy.reset();
    while (session.offer(buffer, offset, length) < 0)
    {
        idleStrategy.idle();
    }
}
 
Example #23
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 #24
Source File: AeronIpcBenchmark.java    From benchmarks with Apache License 2.0 5 votes vote down vote up
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 #25
Source File: LiveRecordingMessageTransceiver.java    From benchmarks with Apache License 2.0 5 votes vote down vote up
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 #26
Source File: EngineProtocolSubscription.java    From artio with Apache License 2.0 5 votes vote down vote up
private Action onReleaseSession(
    final DirectBuffer buffer,
    final int offset,
    final int blockLength,
    final int version,
    final Header header)
{
    releaseSession.wrap(buffer, offset, blockLength, version);
    final int libraryId = releaseSession.libraryId();
    final Action action = handler.onApplicationHeartbeat(libraryId, header.sessionId());
    if (action != null)
    {
        return action; // Continue processing messages, but not this message.
    }
    return handler.onReleaseSession(
        libraryId,
        releaseSession.connection(),
        releaseSession.sessionId(),
        releaseSession.correlationId(),
        releaseSession.state(),
        releaseSession.awaitingResend() == AwaitingResend.YES,
        releaseSession.heartbeatIntervalInMs(),
        releaseSession.lastSentSequenceNumber(),
        releaseSession.lastReceivedSequenceNumber(),
        releaseSession.username(),
        releaseSession.password(),
        header);
}
 
Example #27
Source File: FixArchivePrinter.java    From artio with Apache License 2.0 5 votes vote down vote up
private static void print(
    final FixMessageDecoder message,
    final DirectBuffer buffer,
    final int offset,
    final int length,
    final Header header)
{
    System.out.println(message.body());
}
 
Example #28
Source File: EmbeddedReplayThroughput.java    From aeron with Apache License 2.0 5 votes vote down vote up
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 #29
Source File: AeronExclusiveIpcBenchmark.java    From benchmarks with Apache License 2.0 5 votes vote down vote up
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 #30
Source File: SequenceNumberIndexWriter.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 length,
    final Header header)
{
    final int streamId = header.streamId();
    if (streamId == this.streamId)
    {
        onFragment(buffer, srcOffset, length, header, NULL_RECORDING_ID);
    }
}