Java Code Examples for org.agrona.ExpandableArrayBuffer#putStringWithoutLengthAscii()

The following examples show how to use org.agrona.ExpandableArrayBuffer#putStringWithoutLengthAscii() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ClusterNodeTest.java    From aeron with Apache License 2.0 6 votes vote down vote up
@Test
@Timeout(10)
public void shouldEchoMessageViaServiceUsingDirectOffer()
{
    final ExpandableArrayBuffer msgBuffer = new ExpandableArrayBuffer();
    final String msg = "Hello World!";
    msgBuffer.putStringWithoutLengthAscii(0, msg);

    final MutableInteger messageCount = new MutableInteger();

    final EgressListener listener =
        (clusterSessionId, timestamp, buffer, offset, length, header) ->
        {
            assertEquals(msg, buffer.getStringWithoutLengthAscii(offset, length));
            messageCount.value += 1;
        };

    container = launchEchoService();
    aeronCluster = connectToCluster(listener);

    offerMessage(msgBuffer, msg);
    awaitResponse(messageCount);

    ClusterTests.failOnClusterError();
}
 
Example 2
Source File: ClusterNodeTest.java    From aeron with Apache License 2.0 6 votes vote down vote up
@Test
@Timeout(10)
public void shouldScheduleEventInService()
{
    final ExpandableArrayBuffer msgBuffer = new ExpandableArrayBuffer();
    final String msg = "Hello World!";
    msgBuffer.putStringWithoutLengthAscii(0, msg);

    final MutableInteger messageCount = new MutableInteger();

    final EgressListener listener =
        (clusterSessionId, timestamp, buffer, offset, length, header) ->
        {
            final String expected = msg + "-scheduled";
            assertEquals(expected, buffer.getStringWithoutLengthAscii(offset, length));
            messageCount.value += 1;
        };

    container = launchTimedService();
    aeronCluster = connectToCluster(listener);

    offerMessage(msgBuffer, msg);
    awaitResponse(messageCount);

    ClusterTests.failOnClusterError();
}
 
Example 3
Source File: ClusterNodeTest.java    From aeron with Apache License 2.0 6 votes vote down vote up
@Test
@Timeout(10)
public void shouldSendResponseAfterServiceMessage()
{
    final ExpandableArrayBuffer msgBuffer = new ExpandableArrayBuffer();
    final String msg = "Hello World!";
    msgBuffer.putStringWithoutLengthAscii(0, msg);

    final MutableInteger messageCount = new MutableInteger();

    final EgressListener listener =
        (clusterSessionId, timestamp, buffer, offset, length, header) ->
        {
            assertEquals(msg, buffer.getStringWithoutLengthAscii(offset, length));
            messageCount.value += 1;
        };

    container = launchServiceMessageIngressService();
    aeronCluster = connectToCluster(listener);

    offerMessage(msgBuffer, msg);
    awaitResponse(messageCount);

    ClusterTests.failOnClusterError();
}
 
Example 4
Source File: ExtendRecordingTest.java    From aeron with Apache License 2.0 5 votes vote down vote up
private static void offer(
    final Publication publication, final int startIndex, final int count, final String prefix)
{
    final ExpandableArrayBuffer buffer = new ExpandableArrayBuffer();

    for (int i = startIndex; i < (startIndex + count); i++)
    {
        final int length = buffer.putStringWithoutLengthAscii(0, prefix + i);

        while (publication.offer(buffer, 0, length) <= 0)
        {
            Tests.yield();
        }
    }
}
 
Example 5
Source File: Common.java    From aeron with Apache License 2.0 5 votes vote down vote up
static void offer(final Publication publication, final int count, final String prefix)
{
    final ExpandableArrayBuffer buffer = new ExpandableArrayBuffer();

    for (int i = 0; i < count; i++)
    {
        final int length = buffer.putStringWithoutLengthAscii(0, prefix + i);

        while (publication.offer(buffer, 0, length) <= 0)
        {
            Tests.yield();
        }
    }
}
 
Example 6
Source File: Common.java    From aeron with Apache License 2.0 5 votes vote down vote up
static void offerToPosition(final Publication publication, final String prefix, final long minimumPosition)
{
    final ExpandableArrayBuffer buffer = new ExpandableArrayBuffer();

    for (int i = 0; publication.position() < minimumPosition; i++)
    {
        final int length = buffer.putStringWithoutLengthAscii(0, prefix + i);

        while (publication.offer(buffer, 0, length) <= 0)
        {
            Tests.yield();
        }
    }
}
 
Example 7
Source File: ClusterCounters.java    From aeron with Apache License 2.0 5 votes vote down vote up
/**
 * Allocate a counter to represent the a component state within a cluster.
 *
 * @param aeron     to allocate the counter.
 * @param name      of the counter for the label.
 * @param typeId    for the counter.
 * @param clusterId to which the allocated counter belongs.
 * @return the {@link Counter} for the commit position.
 */
public static Counter allocate(final Aeron aeron, final String name, final int typeId, final int clusterId)
{
    final ExpandableArrayBuffer buffer = new ExpandableArrayBuffer();

    int index = 0;
    buffer.putInt(index, clusterId);
    index += SIZE_OF_INT;

    index += buffer.putStringWithoutLengthAscii(index, name);
    index += buffer.putStringWithoutLengthAscii(index, " - clusterId=");
    index += buffer.putIntAscii(index, clusterId);

    return aeron.addCounter(typeId, buffer, 0, SIZE_OF_INT, buffer, SIZE_OF_INT, index - SIZE_OF_INT);
}
 
Example 8
Source File: ClusterTests.java    From aeron with Apache License 2.0 5 votes vote down vote up
public static Thread startMessageThread(final TestCluster cluster, final long backoffIntervalNs)
{
    final Thread thread = new Thread(
        () ->
        {
            final IdleStrategy idleStrategy = YieldingIdleStrategy.INSTANCE;
            final AeronCluster client = cluster.client();
            final ExpandableArrayBuffer msgBuffer = cluster.msgBuffer();
            msgBuffer.putStringWithoutLengthAscii(0, HELLO_WORLD_MSG);

            while (!Thread.interrupted())
            {
                if (client.offer(msgBuffer, 0, HELLO_WORLD_MSG.length()) < 0)
                {
                    LockSupport.parkNanos(backoffIntervalNs);
                }

                idleStrategy.idle(client.pollEgress());
            }
        });

    thread.setDaemon(true);
    thread.setName("message-thread");
    thread.start();

    return thread;
}
 
Example 9
Source File: StartFromTruncatedRecordingLogTest.java    From aeron with Apache License 2.0 5 votes vote down vote up
private void assertClusterIsFunctioningCorrectly()
{
    awaitLeaderMemberId();
    connectClient();

    final ExpandableArrayBuffer msgBuffer = new ExpandableArrayBuffer();
    msgBuffer.putStringWithoutLengthAscii(0, ClusterTests.HELLO_WORLD_MSG);

    final int initialCount = responseCount.get();
    sendMessages(msgBuffer);
    awaitResponses(MESSAGE_COUNT + initialCount);

    closeClient();
}
 
Example 10
Source File: ArchiveCreator.java    From aeron with Apache License 2.0 5 votes vote down vote up
private static void offerToPosition(final Publication publication, final long minimumPosition)
{
    final ExpandableArrayBuffer buffer = new ExpandableArrayBuffer();

    for (int i = 0; publication.position() < minimumPosition; i++)
    {
        final int length = buffer.putStringWithoutLengthAscii(0, MESSAGE_PREFIX + i);

        while (publication.offer(buffer, 0, length) <= 0)
        {
            Thread.yield();
            checkInterruptStatus();
        }
    }
}