当前位置: 首页>>代码示例>>Java>>正文


Java UnsafeBuffer.putShort方法代码示例

本文整理汇总了Java中org.agrona.concurrent.UnsafeBuffer.putShort方法的典型用法代码示例。如果您正苦于以下问题:Java UnsafeBuffer.putShort方法的具体用法?Java UnsafeBuffer.putShort怎么用?Java UnsafeBuffer.putShort使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.agrona.concurrent.UnsafeBuffer的用法示例。


在下文中一共展示了UnsafeBuffer.putShort方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createDefaultHeader

import org.agrona.concurrent.UnsafeBuffer; //导入方法依赖的package包/类
/**
 * Return an initialised default Data Frame Header.
 *
 * @param sessionId for the header
 * @param streamId  for the header
 * @param termId    for the header
 * @return byte array containing the header
 */
public static UnsafeBuffer createDefaultHeader(final int sessionId, final int streamId, final int termId)
{
    final UnsafeBuffer buffer =
        new UnsafeBuffer(BufferUtil.allocateDirectAligned(HEADER_LENGTH, FrameDescriptor.FRAME_ALIGNMENT));

    buffer.putByte(VERSION_FIELD_OFFSET, CURRENT_VERSION);
    buffer.putByte(FLAGS_FIELD_OFFSET, (byte)BEGIN_AND_END_FLAGS);
    buffer.putShort(TYPE_FIELD_OFFSET, (short)HDR_TYPE_DATA, LITTLE_ENDIAN);
    buffer.putInt(SESSION_ID_FIELD_OFFSET, sessionId, LITTLE_ENDIAN);
    buffer.putInt(STREAM_ID_FIELD_OFFSET, streamId, LITTLE_ENDIAN);
    buffer.putInt(TERM_ID_FIELD_OFFSET, termId, LITTLE_ENDIAN);
    buffer.putLong(RESERVED_VALUE_OFFSET, DEFAULT_RESERVE_VALUE);

    return buffer;
}
 
开发者ID:real-logic,项目名称:aeron,代码行数:24,代码来源:DataHeaderFlyweight.java

示例2: shouldInsertLastFrameIntoBuffer

import org.agrona.concurrent.UnsafeBuffer; //导入方法依赖的package包/类
@Test
public void shouldInsertLastFrameIntoBuffer()
{
    final int frameLength = BitUtil.align(256, FRAME_ALIGNMENT);
    final int srcOffset = 0;
    final int tail = TERM_BUFFER_CAPACITY - frameLength;
    final int termOffset = tail;
    final UnsafeBuffer packet = new UnsafeBuffer(ByteBuffer.allocateDirect(frameLength));
    packet.putShort(typeOffset(srcOffset), (short)PADDING_FRAME_TYPE, LITTLE_ENDIAN);
    packet.putInt(srcOffset, frameLength, LITTLE_ENDIAN);

    TermRebuilder.insert(termBuffer, termOffset, packet, frameLength);

    verify(termBuffer).putBytes(
        tail + HEADER_LENGTH, packet, srcOffset + HEADER_LENGTH, frameLength - HEADER_LENGTH);
}
 
开发者ID:real-logic,项目名称:aeron,代码行数:17,代码来源:TermRebuilderTest.java

示例3: NodeRunner

import org.agrona.concurrent.UnsafeBuffer; //导入方法依赖的package包/类
NodeRunner(final int nodeId, final int... otherNodes)
{
    final File logFileDir = new File(logFileDir((short)nodeId));
    if (logFileDir.exists())
    {
        IoUtil.delete(logFileDir, true);
    }

    this.handler = new NodeHandler(nodeId);
    this.frameDropper = new FrameDropper(nodeId);

    final int termBufferLength = 1024 * 1024;
    final MediaDriver.Context context = new MediaDriver.Context()
        .threadingMode(SHARED)
        .sharedIdleStrategy(new YieldingIdleStrategy())
        .receiveChannelEndpointSupplier(frameDropper.newReceiveChannelEndpointSupplier())
        .sendChannelEndpointSupplier(frameDropper.newSendChannelEndpointSupplier())
        .dirDeleteOnStart(true)
        .aeronDirectoryName(AERON_DIR_PROP_DEFAULT + nodeId)
        .publicationTermBufferLength(termBufferLength)
        .ipcTermBufferLength(termBufferLength);

    final IntHashSet otherNodeIds = new IntHashSet(40);
    for (final int node : otherNodes)
    {
        otherNodeIds.add(node);
    }

    mediaDriver = MediaDriver.launch(context);
    aeron = Aeron.connect(new Aeron.Context().aeronDirectoryName(context.aeronDirectoryName()));

    final StreamIdentifier dataStream = new StreamIdentifier(AERON_CHANNEL, DEFAULT_DATA_STREAM_ID);
    final ArchiveMetaData metaData = AbstractReplicationTest.archiveMetaData((short)nodeId);
    final ArchiveReader archiveReader = new ArchiveReader(
        metaData, DEFAULT_LOGGER_CACHE_NUM_SETS, DEFAULT_LOGGER_CACHE_SET_SIZE, dataStream, NO_FILTER);
    final Archiver archiver = new Archiver(
        metaData, DEFAULT_LOGGER_CACHE_NUM_SETS, DEFAULT_LOGGER_CACHE_SET_SIZE, dataStream, nodeId + "-",
        completionPosition);
    final UnsafeBuffer nodeState = new UnsafeBuffer(new byte[SIZE_OF_SHORT]);
    nodeState.putShort(0, (short)nodeId);

    final ClusterConfiguration configuration = new ClusterConfiguration()
        .nodeId((short)nodeId)
        .aeron(aeron)
        .otherNodes(otherNodeIds)
        .timeoutIntervalInMs(TIMEOUT_IN_MS)
        .failCounter(mock(AtomicCounter.class))
        .aeronChannel(AERON_CHANNEL)
        .archiver(archiver)
        .archiveReaderSupplier(() -> archiveReader)
        .nodeState(nodeState)
        .nodeStateHandler(new NodeIdStasher())
        .nodeHandler(stashingNodeHandler)
        .idleStrategy(new YieldingIdleStrategy());

    clusterAgent = new ClusterAgent(configuration, System.currentTimeMillis());
    subscription = clusterAgent.clusterStreams().subscription(1, "nodeRunner");
    publication = clusterAgent.clusterStreams().publication(1, "nodeRunner");
}
 
开发者ID:real-logic,项目名称:artio,代码行数:60,代码来源:NodeRunner.java

示例4: frameType

import org.agrona.concurrent.UnsafeBuffer; //导入方法依赖的package包/类
/**
 * Write the type field for a frame.
 *
 * @param buffer     containing the frame.
 * @param termOffset at which a frame begins.
 * @param type       type value for the frame.
 */
public static void frameType(final UnsafeBuffer buffer, final int termOffset, final int type)
{
    buffer.putShort(typeOffset(termOffset), (short)type, LITTLE_ENDIAN);
}
 
开发者ID:real-logic,项目名称:aeron,代码行数:12,代码来源:FrameDescriptor.java


注:本文中的org.agrona.concurrent.UnsafeBuffer.putShort方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。