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


Java UnsafeBuffer.putInt方法代码示例

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


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

示例1: run

import org.agrona.concurrent.UnsafeBuffer; //导入方法依赖的package包/类
@Override
public void run()
{
    final IdleStrategy idleStrategy = new BusySpinIdleStrategy();
    final UnsafeBuffer buffer = new UnsafeBuffer(DirectBufferAllocator.allocateCacheAligned(MESSAGE_LENGTH));

    for (int messageNumber = 1; messageNumber <= numMessages; messageNumber++)
    {
        final long timestamp = System.nanoTime();

        buffer.putInt(0, messageNumber);
        buffer.putLong(4, timestamp);

        while (!inputRingBuffer.write(MessageTypes.APPLICATION_MSG_ID, buffer, 0, MESSAGE_LENGTH))
        {
            idleStrategy.idle(0);
        }
    }
}
 
开发者ID:canepat,项目名称:Helios,代码行数:20,代码来源:JournalTest.java

示例2: 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

示例3: fillMetaData

import org.agrona.concurrent.UnsafeBuffer; //导入方法依赖的package包/类
public static void fillMetaData(
    final UnsafeBuffer cncMetaDataBuffer,
    final int toDriverBufferLength,
    final int toClientsBufferLength,
    final int counterMetaDataBufferLength,
    final int counterValuesBufferLength,
    final long clientLivenessTimeout,
    final int errorLogBufferLength)
{
    cncMetaDataBuffer.putInt(toDriverBufferLengthOffset(0), toDriverBufferLength);
    cncMetaDataBuffer.putInt(toClientsBufferLengthOffset(0), toClientsBufferLength);
    cncMetaDataBuffer.putInt(countersMetaDataBufferLengthOffset(0), counterMetaDataBufferLength);
    cncMetaDataBuffer.putInt(countersValuesBufferLengthOffset(0), counterValuesBufferLength);
    cncMetaDataBuffer.putInt(errorLogBufferLengthOffset(0), errorLogBufferLength);
    cncMetaDataBuffer.putLong(clientLivenessTimeoutOffset(0), clientLivenessTimeout);
}
 
开发者ID:real-logic,项目名称:aeron,代码行数:17,代码来源:CncFileDescriptor.java

示例4: shouldInsertIntoEmptyBuffer

import org.agrona.concurrent.UnsafeBuffer; //导入方法依赖的package包/类
@Test
public void shouldInsertIntoEmptyBuffer()
{
    final UnsafeBuffer packet = new UnsafeBuffer(ByteBuffer.allocateDirect(256));
    final int termOffset = 0;
    final int srcOffset = 0;
    final int length = 256;
    packet.putInt(srcOffset, length, LITTLE_ENDIAN);

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

    final InOrder inOrder = inOrder(termBuffer);
    inOrder.verify(termBuffer).putBytes(
        termOffset + HEADER_LENGTH, packet, srcOffset + HEADER_LENGTH, length - HEADER_LENGTH);
    inOrder.verify(termBuffer).putLong(termOffset + 24, packet.getLong(24));
    inOrder.verify(termBuffer).putLong(termOffset + 16, packet.getLong(16));
    inOrder.verify(termBuffer).putLong(termOffset + 8, packet.getLong(8));
    inOrder.verify(termBuffer).putLongOrdered(termOffset, packet.getLong(0));
}
 
开发者ID:real-logic,项目名称:aeron,代码行数:20,代码来源:TermRebuilderTest.java

示例5: 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

示例6: run

import org.agrona.concurrent.UnsafeBuffer; //导入方法依赖的package包/类
public void run()
{
    try
    {
        barrier.await();
    }
    catch (final Exception ignore)
    {
    }

    final int length = BitUtil.SIZE_OF_INT * 2;
    final int repsValueOffset = BitUtil.SIZE_OF_INT;
    final UnsafeBuffer srcBuffer = new UnsafeBuffer(new byte[1024]);

    srcBuffer.putInt(0, producerId);

    for (int i = 0; i < reps; i++)
    {
        srcBuffer.putInt(repsValueOffset, i);

        while (!ringBuffer.write(MSG_TYPE_ID, srcBuffer, 0, length))
        {
            Thread.yield();
        }
    }
}
 
开发者ID:real-logic,项目名称:agrona,代码行数:27,代码来源:ManyToOneRingBufferConcurrentTest.java

示例7: allocate

import org.agrona.concurrent.UnsafeBuffer; //导入方法依赖的package包/类
public static Counter allocate(
    final Aeron aeron,
    final UnsafeBuffer tempBuffer,
    final long recordingId,
    final long controlSessionId,
    final long correlationId,
    final int sessionId,
    final int streamId,
    final String strippedChannel)
{
    tempBuffer.putLong(RECORDING_ID_OFFSET, recordingId);
    tempBuffer.putLong(CONTROL_SESSION_ID_OFFSET, controlSessionId);
    tempBuffer.putLong(CORRELATION_ID_OFFSET, correlationId);
    tempBuffer.putInt(SESSION_ID_OFFSET, sessionId);
    tempBuffer.putInt(STREAM_ID_OFFSET, streamId);

    int labelLength = 0;
    labelLength += tempBuffer.putStringWithoutLengthAscii(KEY_LENGTH, NAME + ": ");
    labelLength += tempBuffer.putLongAscii(KEY_LENGTH + labelLength, recordingId);
    labelLength += tempBuffer.putStringWithoutLengthAscii(KEY_LENGTH + labelLength, " ");
    labelLength += tempBuffer.putIntAscii(KEY_LENGTH + labelLength, sessionId);
    labelLength += tempBuffer.putStringWithoutLengthAscii(KEY_LENGTH + labelLength, " ");
    labelLength += tempBuffer.putIntAscii(KEY_LENGTH + labelLength, streamId);
    labelLength += tempBuffer.putStringWithoutLengthAscii(KEY_LENGTH + labelLength, " ");
    labelLength += tempBuffer.putStringWithoutLengthAscii(
        KEY_LENGTH + labelLength, strippedChannel, 0, MAX_LABEL_LENGTH - labelLength);

    return aeron.addCounter(
        RECORDING_POSITION_TYPE_ID,
        tempBuffer,
        0,
        KEY_LENGTH,
        tempBuffer,
        KEY_LENGTH,
        labelLength);
}
 
开发者ID:real-logic,项目名称:aeron,代码行数:37,代码来源:RecordingPos.java

示例8: storeDefaultFrameHeader

import org.agrona.concurrent.UnsafeBuffer; //导入方法依赖的package包/类
/**
 * Store the default frame header to the log meta data buffer.
 *
 * @param logMetaDataBuffer into which the default headers should be stored.
 * @param defaultHeader     to be stored.
 * @throws IllegalArgumentException if the defaultHeader is larger than {@link #LOG_DEFAULT_FRAME_HEADER_MAX_LENGTH}
 */
public static void storeDefaultFrameHeader(final UnsafeBuffer logMetaDataBuffer, final DirectBuffer defaultHeader)
{
    if (defaultHeader.capacity() != HEADER_LENGTH)
    {
        throw new IllegalArgumentException(
            "Default header length not equal to HEADER_LENGTH: length=" + defaultHeader.capacity());
    }

    logMetaDataBuffer.putInt(LOG_DEFAULT_FRAME_HEADER_LENGTH_OFFSET, HEADER_LENGTH);
    logMetaDataBuffer.putBytes(LOG_DEFAULT_FRAME_HEADER_OFFSET, defaultHeader, 0, HEADER_LENGTH);
}
 
开发者ID:real-logic,项目名称:aeron,代码行数:19,代码来源:LogBufferDescriptor.java

示例9: frameTermOffset

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

示例10: frameTermId

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

示例11: activeTermCount

import org.agrona.concurrent.UnsafeBuffer; //导入方法依赖的package包/类
/**
 * Set the value of the current active partition index for the producer.
 *
 * @param logMetaDataBuffer containing the meta data.
 * @param termCount         value of the active term count used by the producer of this log.
 */
public static void activeTermCount(final UnsafeBuffer logMetaDataBuffer, final int termCount)
{
    logMetaDataBuffer.putInt(LOG_ACTIVE_TERM_COUNT_OFFSET, termCount);
}
 
开发者ID:real-logic,项目名称:aeron,代码行数:11,代码来源:LogBufferDescriptor.java


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