io.aeron.logbuffer.Header.sessionId()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(9.0k)|赞(0)|评价(0)|浏览(110)

本文整理了Java中io.aeron.logbuffer.Header.sessionId()方法的一些代码示例,展示了Header.sessionId()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Header.sessionId()方法的具体详情如下:
包路径:io.aeron.logbuffer.Header
类名称:Header
方法名:sessionId

Header.sessionId介绍

[英]The session ID to which the frame belongs.
[中]帧所属的会话ID。

代码示例

代码示例来源:origin: real-logic/aeron

/**
 * Return a reusable, parametrised {@link FragmentHandler} that prints to stdout
 *
 * @param streamId to show when printing
 * @return subscription data handler function that prints the message contents
 */
public static FragmentHandler printStringMessage(final int streamId)
{
  return (buffer, offset, length, header) ->
  {
    final byte[] data = new byte[length];
    buffer.getBytes(offset, data);
    System.out.println(String.format(
      "Message to stream %d from session %d (%d@%d) <<%s>>",
      streamId, header.sessionId(), length, offset, new String(data)));
  };
}

代码示例来源:origin: real-logic/aeron

/**
   * Return a reusable, parameterised {@link FragmentHandler} that prints to stdout for the second stream (STREAM + 1)
   *
   * @param streamId to show when printing
   * @return subscription data handler function that prints the message contents
   */
  public static FragmentHandler reassembledStringMessage2(final int streamId)
  {
    return (buffer, offset, length, header) ->
    {
      final byte[] data = new byte[length];
      buffer.getBytes(offset, data);

      System.out.format(
        "message to stream %d from session %x term id %x term offset %d (%d@%d)%n",
        streamId, header.sessionId(), header.termId(), header.termOffset(), length, offset);

      if (length != 9000)
      {
        System.out.format(
          "Received message was not assembled properly; received length was %d, but was expecting 9000%n",
          length);
      }
    };
  }
}

代码示例来源:origin: real-logic/aeron

/**
 * Return a reusable, parameterized {@link FragmentHandler} that prints to stdout for the first stream(STREAM)
 *
 * @param streamId to show when printing
 * @return subscription data handler function that prints the message contents
 */
public static FragmentHandler reassembledStringMessage1(final int streamId)
{
  return (buffer, offset, length, header) ->
  {
    final byte[] data = new byte[length];
    buffer.getBytes(offset, data);
    System.out.format(
      "message to stream %d from session %x term id %x term offset %d (%d@%d)%n",
      streamId, header.sessionId(), header.termId(), header.termOffset(), length, offset);
    if (length != 10000)
    {
      System.out.format(
        "Received message was not assembled properly;" +
        " received length was %d, but was expecting 10000%n",
        length);
    }
  };
}

代码示例来源:origin: real-logic/aeron

new String(data), streamId, header.sessionId(),
header.termId(), header.termOffset(), length, offset));

代码示例来源:origin: real-logic/aeron

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)
  {
    final BufferBuilder builder = getBufferBuilder(header.sessionId());
    builder.reset().append(buffer, offset, length);
  }
  else
  {
    final BufferBuilder builder = builderBySessionIdMap.get(header.sessionId());
    if (null != builder && 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();
      }
    }
  }
}

代码示例来源:origin: real-logic/aeron

@Test
public void shouldAssembleTwoPartMessage()
{
  when(header.flags())
    .thenReturn(FrameDescriptor.BEGIN_FRAG_FLAG)
    .thenReturn(FrameDescriptor.END_FRAG_FLAG);
  final UnsafeBuffer srcBuffer = new UnsafeBuffer(new byte[1024]);
  final int offset = 0;
  final int length = srcBuffer.capacity() / 2;
  srcBuffer.setMemory(0, length, (byte)65);
  srcBuffer.setMemory(length, length, (byte)66);
  adapter.onFragment(srcBuffer, offset, length, header);
  adapter.onFragment(srcBuffer, length, 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 * 2), headerArg.capture());
  final UnsafeBuffer capturedBuffer = bufferArg.getValue();
  for (int i = 0; i < srcBuffer.capacity(); i++)
  {
    assertThat("same at i=" + i, capturedBuffer.getByte(i), is(srcBuffer.getByte(i)));
  }
  final Header capturedHeader = headerArg.getValue();
  assertThat(capturedHeader.sessionId(), is(SESSION_ID));
  assertThat(capturedHeader.flags(), is(FrameDescriptor.END_FRAG_FLAG));
}

代码示例来源:origin: real-logic/aeron

assertThat(capturedHeader.sessionId(), is(SESSION_ID));
assertThat(capturedHeader.flags(), is(FrameDescriptor.END_FRAG_FLAG));

代码示例来源:origin: real-logic/aeron

assertThat(header.termId(), is(ACTIVE_TERM_ID));
assertThat(header.streamId(), is(STREAM_ID));
assertThat(header.sessionId(), is(SESSION_ID));
assertThat(header.termOffset(), is(0));
assertThat(header.frameLength(), is(DataHeaderFlyweight.HEADER_LENGTH + FAKE_PAYLOAD.length));

代码示例来源:origin: real-logic/aeron

final BufferBuilder builder = getBufferBuilder(header.sessionId());
builder.reset().append(buffer, offset, length);
final BufferBuilder builder = builderBySessionIdMap.get(header.sessionId());
if (null != builder && builder.limit() != 0)

代码示例来源:origin: real-logic/aeron

assertThat(header.termId(), is(ACTIVE_TERM_ID));
assertThat(header.streamId(), is(STREAM_ID));
assertThat(header.sessionId(), is(SESSION_ID));
assertThat(header.termOffset(), is(initialTermOffset));
assertThat(header.frameLength(), is(DataHeaderFlyweight.HEADER_LENGTH + FAKE_PAYLOAD.length));

代码示例来源:origin: real-logic/aeron

assertThat(header.termId(), is(ACTIVE_TERM_ID));
assertThat(header.streamId(), is(STREAM_ID));
assertThat(header.sessionId(), is(SESSION_ID));
assertThat(header.termOffset(), is(0));
assertThat(header.frameLength(), is(DataHeaderFlyweight.HEADER_LENGTH + FAKE_PAYLOAD.length));

代码示例来源:origin: real-logic/aeron

assertThat(header.termId(), is(ACTIVE_TERM_ID));
assertThat(header.streamId(), is(STREAM_ID));
assertThat(header.sessionId(), is(SESSION_ID));
assertThat(header.termOffset(), is(0));
assertThat(header.frameLength(), is(DataHeaderFlyweight.HEADER_LENGTH + FAKE_PAYLOAD.length));

代码示例来源:origin: org.nd4j/nd4j-aeron

/**
 * Return a reusable, parameterized {@link FragmentHandler} that prints to stdout
 *
 * @param streamId to show when printing
 * @return subscription data handler function that prints the message contents
 */
public static FragmentHandler printStringMessage(final int streamId) {
  return (buffer, offset, length, header) -> {
    final byte[] data = new byte[length];
    buffer.getBytes(offset, data);
    System.out.println(String.format("Message to stream %d from session %d (%d@%d) <<%s>>", streamId,
            header.sessionId(), length, offset, new String(data)));
  };
}

代码示例来源:origin: real-logic/artio

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;
}

代码示例来源:origin: real-logic/artio

private Action onApplicationHeartbeat(
  final DirectBuffer buffer,
  final int offset,
  final int blockLength,
  final int version,
  final Header header)
{
  applicationHeartbeat.wrap(buffer, offset, blockLength, version);
  handler.onApplicationHeartbeat(applicationHeartbeat.libraryId(), header.sessionId());
  return CONTINUE;
}

代码示例来源:origin: real-logic/artio

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,
    "Indexing @ %d from [%d, %d]%n",
    endPosition,
    streamId,
    aeronSessionId);
  for (int i = 0, size = indices.size(); i < size; i++)
  {
    indices.get(i).onFragment(buffer, offset, length, header);
  }
  return CONTINUE;
}

代码示例来源:origin: real-logic/artio

private void setupHeader()
{
  when(header.sessionId()).thenReturn(AERON_SESSION_ID);
  when(header.position()).thenReturn(POSITION);
}

代码示例来源:origin: real-logic/artio

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());
}

代码示例来源:origin: real-logic/artio

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());
  }
}

代码示例来源:origin: real-logic/artio

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());
}

相关文章