Search in sources :

Example 11 with ExpandableArrayBuffer

use of org.agrona.ExpandableArrayBuffer in project Aeron by real-logic.

the class FileSender method sendFileCreate.

private static void sendFileCreate(final Publication publication, final long correlationId, final int length, final String filename) {
    final ExpandableArrayBuffer buffer = new ExpandableArrayBuffer();
    buffer.putInt(VERSION_OFFSET, VERSION, LITTLE_ENDIAN);
    buffer.putInt(TYPE_OFFSET, FILE_CREATE_TYPE, LITTLE_ENDIAN);
    buffer.putLong(CORRELATION_ID_OFFSET, correlationId, LITTLE_ENDIAN);
    buffer.putLong(FILE_LENGTH_OFFSET, length, LITTLE_ENDIAN);
    final int msgLength = FILE_NAME_OFFSET + buffer.putStringUtf8(FILE_NAME_OFFSET, filename);
    long result;
    while ((result = publication.offer(buffer, 0, msgLength)) < 0) {
        checkResult(result);
        Thread.yield();
    }
}
Also used : ExpandableArrayBuffer(org.agrona.ExpandableArrayBuffer)

Example 12 with ExpandableArrayBuffer

use of org.agrona.ExpandableArrayBuffer in project Aeron by real-logic.

the class ArchiveCreator method offerToPosition.

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();
        }
    }
}
Also used : ExpandableArrayBuffer(org.agrona.ExpandableArrayBuffer)

Example 13 with ExpandableArrayBuffer

use of org.agrona.ExpandableArrayBuffer in project Aeron by real-logic.

the class MultiModuleSharedDriverTest method echoMessage.

private void echoMessage(final AeronCluster client, final String message, final MutableReference<String> egress) {
    final ExpandableArrayBuffer buffer = new ExpandableArrayBuffer();
    final int length = buffer.putStringWithoutLengthAscii(0, message);
    while (client.offer(buffer, 0, length) < 0) {
        Tests.yield();
    }
    egress.set(null);
    while (null == egress.get()) {
        Tests.yield();
        client.pollEgress();
    }
    assertEquals(message, egress.get());
}
Also used : ExpandableArrayBuffer(org.agrona.ExpandableArrayBuffer)

Example 14 with ExpandableArrayBuffer

use of org.agrona.ExpandableArrayBuffer in project Aeron by real-logic.

the class ClusterTests method startPublisherThread.

public static Thread startPublisherThread(final TestCluster testCluster, final MutableInteger messageCounter, final long backoffIntervalNs) {
    final Thread thread = new Thread(() -> {
        final IdleStrategy idleStrategy = YieldingIdleStrategy.INSTANCE;
        final AeronCluster client = testCluster.client();
        final ExpandableArrayBuffer msgBuffer = testCluster.msgBuffer();
        msgBuffer.putStringWithoutLengthAscii(0, HELLO_WORLD_MSG);
        while (!Thread.interrupted()) {
            final long result = client.offer(msgBuffer, 0, HELLO_WORLD_MSG.length());
            if (result > 0) {
                messageCounter.increment();
            } else {
                if (Publication.CLOSED == result) {
                    break;
                }
                LockSupport.parkNanos(backoffIntervalNs);
            }
            idleStrategy.idle(client.pollEgress());
        }
    });
    thread.setDaemon(true);
    thread.setName("message-thread");
    thread.start();
    return thread;
}
Also used : YieldingIdleStrategy(org.agrona.concurrent.YieldingIdleStrategy) IdleStrategy(org.agrona.concurrent.IdleStrategy) AeronCluster(io.aeron.cluster.client.AeronCluster) ExpandableArrayBuffer(org.agrona.ExpandableArrayBuffer)

Example 15 with ExpandableArrayBuffer

use of org.agrona.ExpandableArrayBuffer in project aeron by real-logic.

the class ClusterNodeRestartTest method launchService.

private void launchService(final boolean initialLaunch, final AtomicLong msgCounter) {
    final ClusteredService service = new StubClusteredService() {

        private int counterValue = 0;

        public void onSessionMessage(final long clusterSessionId, final long correlationId, final long timestampMs, final DirectBuffer buffer, final int offset, final int length, final Header header) {
            final int sentValue = buffer.getInt(offset);
            assertThat(sentValue, is(counterValue));
            counterValue++;
            serviceState.set(Integer.toString(counterValue));
            msgCounter.getAndIncrement();
        }

        public void onTakeSnapshot(final Publication snapshotPublication) {
            final ExpandableArrayBuffer buffer = new ExpandableArrayBuffer();
            int length = 0;
            buffer.putInt(length, counterValue);
            length += SIZE_OF_INT;
            length += buffer.putIntAscii(length, counterValue);
            snapshotPublication.offer(buffer, 0, length);
        }

        public void onLoadSnapshot(final Image snapshotImage) {
            while (true) {
                final int fragments = snapshotImage.poll((buffer, offset, length, header) -> {
                    counterValue = buffer.getInt(offset);
                    final String s = buffer.getStringWithoutLengthAscii(offset + SIZE_OF_INT, length - SIZE_OF_INT);
                    serviceState.set(s);
                }, 1);
                if (fragments == 1) {
                    break;
                }
                TestUtil.checkInterruptedStatus();
                Thread.yield();
            }
        }
    };
    container = null;
    container = ClusteredServiceContainer.launch(new ClusteredServiceContainer.Context().clusteredService(service).terminationHook(() -> {
    }).errorHandler(Throwable::printStackTrace).deleteDirOnStart(initialLaunch));
}
Also used : DirectBuffer(org.agrona.DirectBuffer) Header(io.aeron.logbuffer.Header) Publication(io.aeron.Publication) ClusteredService(io.aeron.cluster.service.ClusteredService) Image(io.aeron.Image) ExpandableArrayBuffer(org.agrona.ExpandableArrayBuffer)

Aggregations

ExpandableArrayBuffer (org.agrona.ExpandableArrayBuffer)21 Header (io.aeron.logbuffer.Header)11 DirectBuffer (org.agrona.DirectBuffer)11 ClusteredService (io.aeron.cluster.service.ClusteredService)10 AeronCluster (io.aeron.cluster.client.AeronCluster)9 ClientSession (io.aeron.cluster.service.ClientSession)9 StubClusteredService (io.aeron.test.cluster.StubClusteredService)8 Archive (io.aeron.archive.Archive)7 ArchiveThreadingMode (io.aeron.archive.ArchiveThreadingMode)7 CLUSTER_MEMBERS (io.aeron.cluster.ClusterTestConstants.CLUSTER_MEMBERS)7 INGRESS_ENDPOINTS (io.aeron.cluster.ClusterTestConstants.INGRESS_ENDPOINTS)7 ClusteredServiceContainer (io.aeron.cluster.service.ClusteredServiceContainer)7 MediaDriver (io.aeron.driver.MediaDriver)7 ThreadingMode (io.aeron.driver.ThreadingMode)7 ClusterTests (io.aeron.test.cluster.ClusterTests)7 CloseHelper (org.agrona.CloseHelper)7 AfterEach (org.junit.jupiter.api.AfterEach)7 BeforeEach (org.junit.jupiter.api.BeforeEach)7 Test (org.junit.jupiter.api.Test)7 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)7