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


Java UnsafeBuffer.putLong方法代码示例

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


在下文中一共展示了UnsafeBuffer.putLong方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: sendEcho

import org.agrona.concurrent.UnsafeBuffer; //导入方法依赖的package包/类
void sendEcho(final long echoTimestamp)
{
    final RingBuffer outputBuffer = outputBufferPool.outputRingBuffers().iterator().next(); // FIXME: refactoring to avoid this API

    final UnsafeBuffer dataBuffer = outgoingDataMessage.dataBuffer();
    final int dataOffset = outgoingDataMessage.dataBufferOffset();

    //echoBuffer.putLong(0, echoTimestamp);
    dataBuffer.putLong(dataOffset, echoTimestamp);

    /*while (!outputBuffer.write(MessageTypes.APPLICATION_MSG_ID, echoBuffer, 0, MESSAGE_LENGTH))
    {
        idleStrategy.idle(0);
    }*/
    while (!outputBuffer.write(MessageTypes.APPLICATION_MSG_ID, dataBuffer, 0, dataBuffer.capacity()))
    {
        idleStrategy.idle(0);
    }

    //System.out.println("SENT echoTimestamp=" + echoTimestamp);
    //UNSAFE.putOrderedLong(this, TIMESTAMP_OFFSET, 0);
    //timestampQueue.add(echoTimestamp);
}
 
开发者ID:canepat,项目名称:Helios,代码行数:24,代码来源:EchoGatewayHandler.java

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

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

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

示例6: appendUnfragmentedMessage

import org.agrona.concurrent.UnsafeBuffer; //导入方法依赖的package包/类
/**
 * Append an unfragmented message to the the term buffer.
 *
 * @param termId                for the current term.
 * @param termOffset            in the term at which to append.
 * @param header                for writing the default header.
 * @param srcBuffer             containing the message.
 * @param srcOffset             at which the message begins.
 * @param length                of the message in the source buffer.
 * @param reservedValueSupplier {@link ReservedValueSupplier} for the frame.
 * @return the resulting offset of the term after the append on success otherwise {@link #FAILED}.
 */
public int appendUnfragmentedMessage(
    final int termId,
    final int termOffset,
    final HeaderWriter header,
    final DirectBuffer srcBuffer,
    final int srcOffset,
    final int length,
    final ReservedValueSupplier reservedValueSupplier)
{
    final int frameLength = length + HEADER_LENGTH;
    final int alignedLength = align(frameLength, FRAME_ALIGNMENT);
    final UnsafeBuffer termBuffer = this.termBuffer;
    final int termLength = termBuffer.capacity();

    int resultingOffset = termOffset + alignedLength;
    putRawTailOrdered(termId, resultingOffset);

    if (resultingOffset > termLength)
    {
        resultingOffset = handleEndOfLogCondition(termBuffer, termOffset, header, termLength, termId);
    }
    else
    {
        header.write(termBuffer, termOffset, frameLength, termId);
        termBuffer.putBytes(termOffset + HEADER_LENGTH, srcBuffer, srcOffset, length);

        if (null != reservedValueSupplier)
        {
            final long reservedValue = reservedValueSupplier.get(termBuffer, termOffset, frameLength);
            termBuffer.putLong(termOffset + RESERVED_VALUE_OFFSET, reservedValue, LITTLE_ENDIAN);
        }

        frameLengthOrdered(termBuffer, termOffset, frameLength);
    }

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

示例7: insert

import org.agrona.concurrent.UnsafeBuffer; //导入方法依赖的package包/类
/**
 * Insert a packet of frames into the log at the appropriate termOffset as indicated by the term termOffset header.
 * <p>
 * If the packet has already been inserted then this is a noop.
 *
 * @param termBuffer into which the packet should be inserted.
 * @param termOffset in the term at which the packet should be inserted.
 * @param packet     containing a sequence of frames.
 * @param length     of the sequence of frames in bytes.
 */
public static void insert(
    final UnsafeBuffer termBuffer, final int termOffset, final UnsafeBuffer packet, final int length)
{
    if (0 == termBuffer.getInt(termOffset))
    {
        termBuffer.putBytes(termOffset + HEADER_LENGTH, packet, HEADER_LENGTH, length - HEADER_LENGTH);

        termBuffer.putLong(termOffset + 24, packet.getLong(24));
        termBuffer.putLong(termOffset + 16, packet.getLong(16));
        termBuffer.putLong(termOffset + 8, packet.getLong(8));

        termBuffer.putLongOrdered(termOffset, packet.getLong(0));
    }
}
 
开发者ID:real-logic,项目名称:aeron,代码行数:25,代码来源:TermRebuilder.java

示例8: appendFragmentedMessage

import org.agrona.concurrent.UnsafeBuffer; //导入方法依赖的package包/类
/**
 * Append a fragmented message to the the term buffer.
 * The message will be split up into fragments of MTU length minus header.
 *
 * @param termId                for the current term.
 * @param termOffset            in the term at which to append.
 * @param header                for writing the default header.
 * @param srcBuffer             containing the message.
 * @param srcOffset             at which the message begins.
 * @param length                of the message in the source buffer.
 * @param maxPayloadLength      that the message will be fragmented into.
 * @param reservedValueSupplier {@link ReservedValueSupplier} for the frame.
 * @return the resulting offset of the term after the append on success otherwise {@link #FAILED}.
 */
public int appendFragmentedMessage(
    final int termId,
    final int termOffset,
    final HeaderWriter header,
    final DirectBuffer srcBuffer,
    final int srcOffset,
    final int length,
    final int maxPayloadLength,
    final ReservedValueSupplier reservedValueSupplier)
{
    final int numMaxPayloads = length / maxPayloadLength;
    final int remainingPayload = length % maxPayloadLength;
    final int lastFrameLength = remainingPayload > 0 ? align(remainingPayload + HEADER_LENGTH, FRAME_ALIGNMENT) : 0;
    final int requiredLength = (numMaxPayloads * (maxPayloadLength + HEADER_LENGTH)) + lastFrameLength;
    final UnsafeBuffer termBuffer = this.termBuffer;
    final int termLength = termBuffer.capacity();

    int resultingOffset = termOffset + requiredLength;
    putRawTailOrdered(termId, resultingOffset);

    if (resultingOffset > termLength)
    {
        resultingOffset = handleEndOfLogCondition(termBuffer, termOffset, header, termLength, termId);
    }
    else
    {
        int frameOffset = termOffset;
        byte flags = BEGIN_FRAG_FLAG;
        int remaining = length;
        do
        {
            final int bytesToWrite = Math.min(remaining, maxPayloadLength);
            final int frameLength = bytesToWrite + HEADER_LENGTH;
            final int alignedLength = align(frameLength, FRAME_ALIGNMENT);

            header.write(termBuffer, frameOffset, frameLength, termId);
            termBuffer.putBytes(
                frameOffset + HEADER_LENGTH,
                srcBuffer,
                srcOffset + (length - remaining),
                bytesToWrite);

            if (remaining <= maxPayloadLength)
            {
                flags |= END_FRAG_FLAG;
            }

            frameFlags(termBuffer, frameOffset, flags);

            if (null != reservedValueSupplier)
            {
                final long reservedValue = reservedValueSupplier.get(termBuffer, frameOffset, frameLength);
                termBuffer.putLong(frameOffset + RESERVED_VALUE_OFFSET, reservedValue, LITTLE_ENDIAN);
            }

            frameLengthOrdered(termBuffer, frameOffset, frameLength);

            flags = 0;
            frameOffset += alignedLength;
            remaining -= bytesToWrite;
        }
        while (remaining > 0);
    }

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

示例9: correlationId

import org.agrona.concurrent.UnsafeBuffer; //导入方法依赖的package包/类
/**
 * Set the correlation ID used for this log relating to the command which created it.
 *
 * @param logMetaDataBuffer containing the meta data.
 * @param id                value to be set.
 */
public static void correlationId(final UnsafeBuffer logMetaDataBuffer, final long id)
{
    logMetaDataBuffer.putLong(LOG_CORRELATION_ID_OFFSET, id);
}
 
开发者ID:real-logic,项目名称:aeron,代码行数:11,代码来源:LogBufferDescriptor.java

示例10: initialiseTailWithTermId

import org.agrona.concurrent.UnsafeBuffer; //导入方法依赖的package包/类
/**
 * Set the initial value for the termId in the upper bits of the tail counter.
 *
 * @param logMetaData    contain the tail counter.
 * @param partitionIndex to be initialised.
 * @param termId         to be set.
 */
public static void initialiseTailWithTermId(
    final UnsafeBuffer logMetaData, final int partitionIndex, final int termId)
{
    logMetaData.putLong(TERM_TAIL_COUNTERS_OFFSET + (partitionIndex * SIZE_OF_LONG), packTail(termId, 0));
}
 
开发者ID:real-logic,项目名称:aeron,代码行数:13,代码来源:LogBufferDescriptor.java


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