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


Java UnsafeBuffer.putBytes方法代码示例

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


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

示例1: shouldAppendOneBufferWithoutResizing

import org.agrona.concurrent.UnsafeBuffer; //导入方法依赖的package包/类
@Test
public void shouldAppendOneBufferWithoutResizing()
{
    final UnsafeBuffer srcBuffer = new UnsafeBuffer(new byte[MIN_ALLOCATED_CAPACITY]);
    final byte[] bytes = "Hello World".getBytes(StandardCharsets.UTF_8);
    srcBuffer.putBytes(0, bytes, 0, bytes.length);

    bufferBuilder.append(srcBuffer, 0, bytes.length);

    final byte[] temp = new byte[bytes.length];
    bufferBuilder.buffer().getBytes(0, temp, 0, bytes.length);

    assertThat(bufferBuilder.limit(), is(bytes.length));
    assertThat(bufferBuilder.capacity(), is(MIN_ALLOCATED_CAPACITY));
    assertArrayEquals(temp, bytes);
}
 
开发者ID:real-logic,项目名称:aeron,代码行数:17,代码来源:BufferBuilderTest.java

示例2: shouldAppendTwoBuffersWithoutResizing

import org.agrona.concurrent.UnsafeBuffer; //导入方法依赖的package包/类
@Test
public void shouldAppendTwoBuffersWithoutResizing()
{
    final UnsafeBuffer srcBuffer = new UnsafeBuffer(new byte[MIN_ALLOCATED_CAPACITY]);
    final byte[] bytes = "1111111122222222".getBytes(StandardCharsets.UTF_8);
    srcBuffer.putBytes(0, bytes, 0, bytes.length);

    bufferBuilder.append(srcBuffer, 0, bytes.length / 2);
    bufferBuilder.append(srcBuffer, bytes.length / 2, bytes.length / 2);

    final byte[] temp = new byte[bytes.length];
    bufferBuilder.buffer().getBytes(0, temp, 0, bytes.length);

    assertThat(bufferBuilder.limit(), is(bytes.length));
    assertThat(bufferBuilder.capacity(), is(MIN_ALLOCATED_CAPACITY));
    assertArrayEquals(temp, bytes);
}
 
开发者ID:real-logic,项目名称:aeron,代码行数:18,代码来源:BufferBuilderTest.java

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

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

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

示例6: shouldSendSetupFrameAfterReceivingStatusMessageWithSetupBit

import org.agrona.concurrent.UnsafeBuffer; //导入方法依赖的package包/类
@Test
    public void shouldSendSetupFrameAfterReceivingStatusMessageWithSetupBit()
    {
        final StatusMessageFlyweight msg = mock(StatusMessageFlyweight.class);
        when(msg.consumptionTermId()).thenReturn(INITIAL_TERM_ID);
        when(msg.consumptionTermOffset()).thenReturn(0);
        when(msg.receiverWindowLength()).thenReturn(ALIGNED_FRAME_LENGTH);

        publication.onStatusMessage(msg, rcvAddress);
//        publication.senderPositionLimit(
//            flowControl.onStatusMessage(INITIAL_TERM_ID, 0, ALIGNED_FRAME_LENGTH, rcvAddress));

        final UnsafeBuffer buffer = new UnsafeBuffer(ByteBuffer.allocateDirect(PAYLOAD.length));
        buffer.putBytes(0, PAYLOAD);

        termAppenders[0].appendUnfragmentedMessage(headerWriter, buffer, 0, PAYLOAD.length, null, INITIAL_TERM_ID);
        sender.doWork();

        assertThat(receivedFrames.size(), is(2)); // setup then data
        receivedFrames.remove();
        receivedFrames.remove();

        publication.triggerSendSetupFrame();

        sender.doWork();
        assertThat(receivedFrames.size(), is(0)); // setup has been sent already, have to wait

        currentTimestamp += Configuration.PUBLICATION_SETUP_TIMEOUT_NS + 10;

        sender.doWork();

        assertThat(receivedFrames.size(), is(1));

        setupHeader.wrap(new UnsafeBuffer(receivedFrames.remove()));
        assertThat(setupHeader.headerType(), is(HeaderFlyweight.HDR_TYPE_SETUP));
    }
 
开发者ID:real-logic,项目名称:aeron,代码行数:37,代码来源:SenderTest.java

示例7: shouldBeAbleToSendOnChannel

import org.agrona.concurrent.UnsafeBuffer; //导入方法依赖的package包/类
@Test
    public void shouldBeAbleToSendOnChannel()
    {
        final StatusMessageFlyweight msg = mock(StatusMessageFlyweight.class);
        when(msg.consumptionTermId()).thenReturn(INITIAL_TERM_ID);
        when(msg.consumptionTermOffset()).thenReturn(0);
        when(msg.receiverWindowLength()).thenReturn(ALIGNED_FRAME_LENGTH);

        publication.onStatusMessage(msg, rcvAddress);
//        publication.senderPositionLimit(
//            flowControl.onStatusMessage(INITIAL_TERM_ID, 0, ALIGNED_FRAME_LENGTH, rcvAddress));

        final UnsafeBuffer buffer = new UnsafeBuffer(ByteBuffer.allocateDirect(PAYLOAD.length));
        buffer.putBytes(0, PAYLOAD);

        termAppenders[0].appendUnfragmentedMessage(headerWriter, buffer, 0, PAYLOAD.length, null, INITIAL_TERM_ID);
        sender.doWork();

        assertThat(receivedFrames.size(), is(2));
        setupHeader.wrap(new UnsafeBuffer(receivedFrames.remove()));
        assertThat(setupHeader.headerType(), is(HeaderFlyweight.HDR_TYPE_SETUP));

        dataHeader.wrap(new UnsafeBuffer(receivedFrames.remove()));
        assertThat(dataHeader.frameLength(), is(FRAME_LENGTH));
        assertThat(dataHeader.termId(), is(INITIAL_TERM_ID));
        assertThat(dataHeader.streamId(), is(STREAM_ID));
        assertThat(dataHeader.sessionId(), is(SESSION_ID));
        assertThat(dataHeader.termOffset(), is(offsetOfMessage(1)));
        assertThat(dataHeader.headerType(), is(HeaderFlyweight.HDR_TYPE_DATA));
        assertThat(dataHeader.flags(), is(DataHeaderFlyweight.BEGIN_AND_END_FLAGS));
        assertThat(dataHeader.version(), is((short)HeaderFlyweight.CURRENT_VERSION));
    }
 
开发者ID:real-logic,项目名称:aeron,代码行数:33,代码来源:SenderTest.java

示例8: shouldNotSendUntilStatusMessageReceived

import org.agrona.concurrent.UnsafeBuffer; //导入方法依赖的package包/类
@Test
    public void shouldNotSendUntilStatusMessageReceived()
    {
        final UnsafeBuffer buffer = new UnsafeBuffer(ByteBuffer.allocateDirect(PAYLOAD.length));
        buffer.putBytes(0, PAYLOAD);
        termAppenders[0].appendUnfragmentedMessage(headerWriter, buffer, 0, PAYLOAD.length, null, INITIAL_TERM_ID);

        sender.doWork();
        assertThat(receivedFrames.size(), is(1));
        setupHeader.wrap(receivedFrames.remove());
        assertThat(setupHeader.headerType(), is(HeaderFlyweight.HDR_TYPE_SETUP));

        final StatusMessageFlyweight msg = mock(StatusMessageFlyweight.class);
        when(msg.consumptionTermId()).thenReturn(INITIAL_TERM_ID);
        when(msg.consumptionTermOffset()).thenReturn(0);
        when(msg.receiverWindowLength()).thenReturn(ALIGNED_FRAME_LENGTH);

        publication.onStatusMessage(msg, rcvAddress);
//        publication.senderPositionLimit(
//            flowControl.onStatusMessage(INITIAL_TERM_ID, 0, ALIGNED_FRAME_LENGTH, rcvAddress));
        sender.doWork();

        assertThat(receivedFrames.size(), is(1));

        dataHeader.wrap(new UnsafeBuffer(receivedFrames.remove()));

        assertThat(dataHeader.frameLength(), is(FRAME_LENGTH));
        assertThat(dataHeader.termId(), is(INITIAL_TERM_ID));
        assertThat(dataHeader.streamId(), is(STREAM_ID));
        assertThat(dataHeader.sessionId(), is(SESSION_ID));
        assertThat(dataHeader.termOffset(), is(offsetOfMessage(1)));
        assertThat(dataHeader.headerType(), is(HeaderFlyweight.HDR_TYPE_DATA));
        assertThat(dataHeader.flags(), is(DataHeaderFlyweight.BEGIN_AND_END_FLAGS));
        assertThat(dataHeader.version(), is((short)HeaderFlyweight.CURRENT_VERSION));
    }
 
开发者ID:real-logic,项目名称:aeron,代码行数:36,代码来源:SenderTest.java

示例9: shouldNotBeAbleToSendAfterUsingUpYourWindow

import org.agrona.concurrent.UnsafeBuffer; //导入方法依赖的package包/类
@Test
    public void shouldNotBeAbleToSendAfterUsingUpYourWindow()
    {
        final UnsafeBuffer buffer = new UnsafeBuffer(ByteBuffer.allocateDirect(PAYLOAD.length));
        buffer.putBytes(0, PAYLOAD);
        termAppenders[0].appendUnfragmentedMessage(headerWriter, buffer, 0, PAYLOAD.length, null, INITIAL_TERM_ID);

        final StatusMessageFlyweight msg = mock(StatusMessageFlyweight.class);
        when(msg.consumptionTermId()).thenReturn(INITIAL_TERM_ID);
        when(msg.consumptionTermOffset()).thenReturn(0);
        when(msg.receiverWindowLength()).thenReturn(ALIGNED_FRAME_LENGTH);

        publication.onStatusMessage(msg, rcvAddress);
//        publication.senderPositionLimit(
//            flowControl.onStatusMessage(INITIAL_TERM_ID, 0, ALIGNED_FRAME_LENGTH, rcvAddress));

        sender.doWork();

        assertThat(receivedFrames.size(), is(2));
        receivedFrames.remove();                   // skip setup

        dataHeader.wrap(new UnsafeBuffer(receivedFrames.remove()));
        assertThat(dataHeader.frameLength(), is(FRAME_LENGTH));
        assertThat(dataHeader.termId(), is(INITIAL_TERM_ID));
        assertThat(dataHeader.streamId(), is(STREAM_ID));
        assertThat(dataHeader.sessionId(), is(SESSION_ID));
        assertThat(dataHeader.termOffset(), is(offsetOfMessage(1)));
        assertThat(dataHeader.headerType(), is(HeaderFlyweight.HDR_TYPE_DATA));
        assertThat(dataHeader.flags(), is(DataHeaderFlyweight.BEGIN_AND_END_FLAGS));
        assertThat(dataHeader.version(), is((short)HeaderFlyweight.CURRENT_VERSION));

        termAppenders[0].appendUnfragmentedMessage(headerWriter, buffer, 0, PAYLOAD.length, null, INITIAL_TERM_ID);
        sender.doWork();

        assertThat(receivedFrames.size(), is(0));
    }
 
开发者ID:real-logic,项目名称:aeron,代码行数:37,代码来源:SenderTest.java

示例10: shouldSendLastDataFrameAsHeartbeatWhenIdle

import org.agrona.concurrent.UnsafeBuffer; //导入方法依赖的package包/类
@Test
    public void shouldSendLastDataFrameAsHeartbeatWhenIdle()
    {
        final StatusMessageFlyweight msg = mock(StatusMessageFlyweight.class);
        when(msg.consumptionTermId()).thenReturn(INITIAL_TERM_ID);
        when(msg.consumptionTermOffset()).thenReturn(0);
        when(msg.receiverWindowLength()).thenReturn(ALIGNED_FRAME_LENGTH);

        publication.onStatusMessage(msg, rcvAddress);
//        publication.senderPositionLimit(
//            flowControl.onStatusMessage(INITIAL_TERM_ID, 0, ALIGNED_FRAME_LENGTH, rcvAddress));

        final UnsafeBuffer buffer = new UnsafeBuffer(ByteBuffer.allocateDirect(PAYLOAD.length));
        buffer.putBytes(0, PAYLOAD);

        termAppenders[0].appendUnfragmentedMessage(headerWriter, buffer, 0, PAYLOAD.length, null, INITIAL_TERM_ID);
        sender.doWork();

        assertThat(receivedFrames.size(), is(2));  // should send ticks
        receivedFrames.remove();                   // skip setup & data frame
        receivedFrames.remove();

        currentTimestamp += Configuration.PUBLICATION_HEARTBEAT_TIMEOUT_NS - 1;
        sender.doWork();

        assertThat(receivedFrames.size(), is(0));  // should not send yet
        currentTimestamp += 10;
        sender.doWork();

        assertThat(receivedFrames.size(), greaterThanOrEqualTo(1));  // should send ticks

        dataHeader.wrap(receivedFrames.remove());
        assertThat(dataHeader.frameLength(), is(0));
        assertThat(dataHeader.termOffset(), is(offsetOfMessage(2)));
    }
 
开发者ID:real-logic,项目名称:aeron,代码行数:36,代码来源:SenderTest.java

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

示例12: main

import org.agrona.concurrent.UnsafeBuffer; //导入方法依赖的package包/类
public static void main(final String[] args) throws Exception
{
    // Allocate enough buffer size to hold maximum message length
    // The UnsafeBuffer class is part of the Agrona library and is used for efficient buffer management
    final UnsafeBuffer buffer = new UnsafeBuffer(BufferUtil.allocateDirectAligned(512, BitUtil.CACHE_LINE_LENGTH));

    // The channel (an endpoint identifier) to send the message to
    final String channel = "aeron:udp?endpoint=localhost:40123";

    // A unique identifier for a stream within a channel. Stream ID 0 is reserved
    // for internal use and should not be used by applications.
    final int streamId = 10;

    System.out.println("Publishing to " + channel + " on stream Id " + streamId);

    // Create a context, needed for client connection to media driver
    // A separate media driver process needs to be running prior to starting this application
    final Aeron.Context ctx = new Aeron.Context();

    // Create an Aeron instance with client-provided context configuration and connect to the
    // media driver, and create a Publication.  The Aeron and Publication classes implement
    // AutoCloseable, and will automatically clean up resources when this try block is finished.
    try (Aeron aeron = Aeron.connect(ctx);
        Publication publication = aeron.addPublication(channel, streamId))
    {
        final String message = "Hello World! ";
        final byte[] messageBytes = message.getBytes();
        buffer.putBytes(0, messageBytes);

        // Wait for 5 seconds to connect to a subscriber
        final long deadlineNs = System.nanoTime() + TimeUnit.SECONDS.toNanos(5);
        while (!publication.isConnected())
        {
            if (System.nanoTime() >= deadlineNs)
            {
                System.out.println("Failed to connect to subscriber");
                return;
            }

            Thread.sleep(1);
        }

        // Try to publish the buffer. 'offer' is a non-blocking call.
        // If it returns less than 0, the message was not sent, and the offer should be retried.
        final long result = publication.offer(buffer, 0, messageBytes.length);

        if (result < 0L)
        {
            if (result == Publication.BACK_PRESSURED)
            {
                System.out.println(" Offer failed due to back pressure");
            }
            else if (result == Publication.NOT_CONNECTED)
            {
                System.out.println(" Offer failed because publisher is not connected to subscriber");
            }
            else if (result == Publication.ADMIN_ACTION)
            {
                System.out.println("Offer failed because of an administration action in the system");
            }
            else if (result == Publication.CLOSED)
            {
                System.out.println("Offer failed publication is closed");
            }
            else if (result == Publication.MAX_POSITION_EXCEEDED)
            {
                System.out.println("Offer failed due to publication reaching max position");
            }
            else
            {
                System.out.println(" Offer failed due to unknown reason");
            }
        }
        else
        {
            System.out.println(" yay !!");
        }

        System.out.println("Done sending.");
    }
}
 
开发者ID:real-logic,项目名称:aeron,代码行数:82,代码来源:SimplePublisher.java

示例13: shouldBeAbleToSendOnChannelTwice

import org.agrona.concurrent.UnsafeBuffer; //导入方法依赖的package包/类
@Test
    public void shouldBeAbleToSendOnChannelTwice()
    {
        final StatusMessageFlyweight msg = mock(StatusMessageFlyweight.class);
        when(msg.consumptionTermId()).thenReturn(INITIAL_TERM_ID);
        when(msg.consumptionTermOffset()).thenReturn(0);
        when(msg.receiverWindowLength()).thenReturn(2 * ALIGNED_FRAME_LENGTH);

        publication.onStatusMessage(msg, rcvAddress);
//        publication.senderPositionLimit(
//            flowControl.onStatusMessage(INITIAL_TERM_ID, 0, (2 * ALIGNED_FRAME_LENGTH), rcvAddress));

        final UnsafeBuffer buffer = new UnsafeBuffer(ByteBuffer.allocateDirect(PAYLOAD.length));
        buffer.putBytes(0, PAYLOAD);

        termAppenders[0].appendUnfragmentedMessage(headerWriter, buffer, 0, PAYLOAD.length, null, INITIAL_TERM_ID);
        sender.doWork();
        termAppenders[0].appendUnfragmentedMessage(headerWriter, buffer, 0, PAYLOAD.length, null, INITIAL_TERM_ID);
        sender.doWork();

        assertThat(receivedFrames.size(), is(3));

        setupHeader.wrap(new UnsafeBuffer(receivedFrames.remove()));
        assertThat(setupHeader.headerType(), is(HeaderFlyweight.HDR_TYPE_SETUP));

        dataHeader.wrap(new UnsafeBuffer(receivedFrames.remove()));
        assertThat(dataHeader.frameLength(), is(FRAME_LENGTH));
        assertThat(dataHeader.termId(), is(INITIAL_TERM_ID));
        assertThat(dataHeader.streamId(), is(STREAM_ID));
        assertThat(dataHeader.sessionId(), is(SESSION_ID));
        assertThat(dataHeader.termOffset(), is(offsetOfMessage(1)));
        assertThat(dataHeader.headerType(), is(HeaderFlyweight.HDR_TYPE_DATA));
        assertThat(dataHeader.flags(), is(DataHeaderFlyweight.BEGIN_AND_END_FLAGS));
        assertThat(dataHeader.version(), is((short)HeaderFlyweight.CURRENT_VERSION));

        dataHeader.wrap(new UnsafeBuffer(receivedFrames.remove()));
        assertThat(dataHeader.frameLength(), is(FRAME_LENGTH));
        assertThat(dataHeader.termId(), is(INITIAL_TERM_ID));
        assertThat(dataHeader.streamId(), is(STREAM_ID));
        assertThat(dataHeader.sessionId(), is(SESSION_ID));
        assertThat(dataHeader.termOffset(), is(offsetOfMessage(2)));
        assertThat(dataHeader.headerType(), is(HeaderFlyweight.HDR_TYPE_DATA));
        assertThat(dataHeader.flags(), is(DataHeaderFlyweight.BEGIN_AND_END_FLAGS));
        assertThat(dataHeader.version(), is((short)HeaderFlyweight.CURRENT_VERSION));
    }
 
开发者ID:real-logic,项目名称:aeron,代码行数:46,代码来源:SenderTest.java

示例14: shouldSendMultipleDataFramesAsHeartbeatsWhenIdle

import org.agrona.concurrent.UnsafeBuffer; //导入方法依赖的package包/类
@Test
    public void shouldSendMultipleDataFramesAsHeartbeatsWhenIdle()
    {
        final StatusMessageFlyweight msg = mock(StatusMessageFlyweight.class);
        when(msg.consumptionTermId()).thenReturn(INITIAL_TERM_ID);
        when(msg.consumptionTermOffset()).thenReturn(0);
        when(msg.receiverWindowLength()).thenReturn(ALIGNED_FRAME_LENGTH);

        publication.onStatusMessage(msg, rcvAddress);
//        publication.senderPositionLimit(
//            flowControl.onStatusMessage(INITIAL_TERM_ID, 0, ALIGNED_FRAME_LENGTH, rcvAddress));

        final UnsafeBuffer buffer = new UnsafeBuffer(ByteBuffer.allocateDirect(PAYLOAD.length));
        buffer.putBytes(0, PAYLOAD);

        termAppenders[0].appendUnfragmentedMessage(headerWriter, buffer, 0, PAYLOAD.length, null, INITIAL_TERM_ID);
        sender.doWork();

        assertThat(receivedFrames.size(), is(2));  // should send ticks
        receivedFrames.remove();
        receivedFrames.remove();                   // skip setup & data frame

        currentTimestamp += Configuration.PUBLICATION_HEARTBEAT_TIMEOUT_NS - 1;
        sender.doWork();
        assertThat(receivedFrames.size(), is(0));  // should not send yet
        currentTimestamp += 10;
        sender.doWork();
        assertThat(receivedFrames.size(), greaterThanOrEqualTo(1));  // should send ticks

        dataHeader.wrap(receivedFrames.remove());
        assertThat(dataHeader.frameLength(), is(0));
        assertThat(dataHeader.termOffset(), is(offsetOfMessage(2)));

        currentTimestamp += Configuration.PUBLICATION_HEARTBEAT_TIMEOUT_NS - 1;
        sender.doWork();
        assertThat(receivedFrames.size(), is(0));  // should not send yet
        currentTimestamp += 10;
        sender.doWork();
        assertThat(receivedFrames.size(), greaterThanOrEqualTo(1));  // should send ticks

        dataHeader.wrap(receivedFrames.remove());
        assertThat(dataHeader.frameLength(), is(0));
        assertThat(dataHeader.termOffset(), is(offsetOfMessage(2)));
    }
 
开发者ID:real-logic,项目名称:aeron,代码行数:45,代码来源:SenderTest.java

示例15: applyDefaultHeader

import org.agrona.concurrent.UnsafeBuffer; //导入方法依赖的package包/类
/**
 * Apply the default header for a message in a term.
 *
 * @param logMetaDataBuffer containing the default headers.
 * @param termBuffer        to which the default header should be applied.
 * @param termOffset        at which the default should be applied.
 */
public static void applyDefaultHeader(
    final UnsafeBuffer logMetaDataBuffer, final UnsafeBuffer termBuffer, final int termOffset)
{
    termBuffer.putBytes(termOffset, logMetaDataBuffer, LOG_DEFAULT_FRAME_HEADER_OFFSET, HEADER_LENGTH);
}
 
开发者ID:real-logic,项目名称:aeron,代码行数:13,代码来源:LogBufferDescriptor.java


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