Search in sources :

Example 26 with MutableBoolean

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

the class BasicAuctionClusteredService method loadSnapshot.

// end::takeSnapshot[]
// tag::loadSnapshot[]
private void loadSnapshot(final Cluster cluster, final Image snapshotImage) {
    final MutableBoolean allDataLoaded = new MutableBoolean(false);
    while (// <1>
    !snapshotImage.isEndOfStream()) {
        final int fragmentsPolled = snapshotImage.poll((// <2>
        buffer, // <2>
        offset, // <2>
        length, // <2>
        header) -> {
            // <3>
            assert length >= SNAPSHOT_MESSAGE_LENGTH;
            final long customerId = buffer.getLong(offset + SNAPSHOT_CUSTOMER_ID_OFFSET);
            final long price = buffer.getLong(offset + SNAPSHOT_PRICE_OFFSET);
            // <4>
            auction.loadInitialState(price, customerId);
            allDataLoaded.set(true);
        }, 1);
        if (// <5>
        allDataLoaded.value) {
            break;
        }
        // <6>
        idleStrategy.idle(fragmentsPolled);
    }
    // <7>
    assert snapshotImage.isEndOfStream();
    assert allDataLoaded.value;
}
Also used : MutableBoolean(org.agrona.collections.MutableBoolean)

Example 27 with MutableBoolean

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

the class ClusterTool method nextBackupQueryDeadlineMs.

/**
 * Set the deadline time (MS) for the next cluster backup query.
 *
 * @param markFile for the cluster component.
 * @param timeMs   to set for the next deadline.
 * @return true if successful, otherwise false.
 */
public static boolean nextBackupQueryDeadlineMs(final ClusterMarkFile markFile, final long timeMs) {
    final String aeronDirectoryName = markFile.decoder().aeronDirectory();
    final MutableBoolean result = new MutableBoolean(false);
    try (Aeron aeron = Aeron.connect(new Aeron.Context().aeronDirectoryName(aeronDirectoryName))) {
        final CountersReader countersReader = aeron.countersReader();
        countersReader.forEach((counterId, typeId, keyBuffer, label) -> {
            if (ClusterBackup.QUERY_DEADLINE_TYPE_ID == typeId) {
                final AtomicCounter atomicCounter = new AtomicCounter(countersReader.valuesBuffer(), counterId, null);
                atomicCounter.setOrdered(timeMs);
                result.value = true;
            }
        });
    }
    return result.value;
}
Also used : CommonContext(io.aeron.CommonContext) MutableBoolean(org.agrona.collections.MutableBoolean) AtomicCounter(org.agrona.concurrent.status.AtomicCounter) Aeron(io.aeron.Aeron) CountersReader(org.agrona.concurrent.status.CountersReader)

Example 28 with MutableBoolean

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

the class BasicAuctionClusteredService method loadSnapshot.

// end::takeSnapshot[]
// tag::loadSnapshot[]
private void loadSnapshot(final Cluster cluster, final Image snapshotImage) {
    final MutableBoolean allDataLoaded = new MutableBoolean(false);
    while (// <1>
    !snapshotImage.isEndOfStream()) {
        final int fragmentsPolled = snapshotImage.poll((// <2>
        buffer, // <2>
        offset, // <2>
        length, // <2>
        header) -> {
            // <3>
            assert length >= SNAPSHOT_MESSAGE_LENGTH;
            final long customerId = buffer.getLong(offset + SNAPSHOT_CUSTOMER_ID_OFFSET);
            final long price = buffer.getLong(offset + SNAPSHOT_PRICE_OFFSET);
            // <4>
            auction.loadInitialState(price, customerId);
            allDataLoaded.set(true);
        }, 1);
        if (// <5>
        allDataLoaded.value) {
            break;
        }
        // <6>
        idleStrategy.idle(fragmentsPolled);
    }
    // <7>
    assert snapshotImage.isEndOfStream();
    assert allDataLoaded.value;
}
Also used : MutableBoolean(org.agrona.collections.MutableBoolean)

Example 29 with MutableBoolean

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

the class ClusterTest method shouldTakeASnapshotAfterReceivingAdminRequestOfTypeSnapshot.

@Test
@InterruptAfter(20)
void shouldTakeASnapshotAfterReceivingAdminRequestOfTypeSnapshot() {
    cluster = aCluster().withStaticNodes(3).withAuthorisationServiceSupplier(() -> AuthorisationService.ALLOW_ALL).start();
    systemTestWatcher.cluster(cluster);
    final TestNode leader = cluster.awaitLeader();
    final long requestCorrelationId = System.nanoTime();
    final MutableBoolean responseReceived = injectAdminResponseEgressListener(requestCorrelationId, AdminRequestType.SNAPSHOT, AdminResponseCode.OK, "");
    final AeronCluster client = cluster.connectClient();
    while (!client.sendAdminRequestToTakeASnapshot(requestCorrelationId)) {
        Tests.yield();
    }
    while (!responseReceived.get()) {
        client.pollEgress();
        Tests.yield();
    }
    cluster.awaitSnapshotCount(1);
    cluster.awaitNeutralControlToggle(leader);
}
Also used : MutableBoolean(org.agrona.collections.MutableBoolean) AeronCluster(io.aeron.cluster.client.AeronCluster) TestNode(io.aeron.test.cluster.TestNode) Test(org.junit.jupiter.api.Test)

Example 30 with MutableBoolean

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

the class ClusterTest method injectAdminResponseEgressListener.

private MutableBoolean injectAdminResponseEgressListener(final long expectedCorrelationId, final AdminRequestType expectedRequestType, final AdminResponseCode expectedResponseCode, final String expectedMessage) {
    final MutableBoolean responseReceived = new MutableBoolean();
    cluster.egressListener(new EgressListener() {

        public void onMessage(final long clusterSessionId, final long timestamp, final DirectBuffer buffer, final int offset, final int length, final Header header) {
        }

        public void onAdminResponse(final long clusterSessionId, final long correlationId, final AdminRequestType requestType, final AdminResponseCode responseCode, final String message, final DirectBuffer payload, final int payloadOffset, final int payloadLength) {
            responseReceived.set(true);
            assertEquals(expectedCorrelationId, correlationId);
            assertEquals(expectedRequestType, requestType);
            assertEquals(expectedResponseCode, responseCode);
            assertEquals(expectedMessage, message);
            assertNotNull(payload);
            final int minPayloadOffset = MessageHeaderEncoder.ENCODED_LENGTH + AdminResponseEncoder.BLOCK_LENGTH + AdminResponseEncoder.messageHeaderLength() + message.length() + AdminResponseEncoder.payloadHeaderLength();
            assertTrue(payloadOffset > minPayloadOffset);
            assertEquals(0, payloadLength);
        }
    });
    return responseReceived;
}
Also used : DirectBuffer(org.agrona.DirectBuffer) Header(io.aeron.logbuffer.Header) MutableBoolean(org.agrona.collections.MutableBoolean) ControlledEgressListener(io.aeron.cluster.client.ControlledEgressListener) EgressListener(io.aeron.cluster.client.EgressListener)

Aggregations

MutableBoolean (org.agrona.collections.MutableBoolean)32 Test (org.junit.jupiter.api.Test)12 AeronCluster (io.aeron.cluster.client.AeronCluster)10 TestNode (io.aeron.test.cluster.TestNode)6 Publication (io.aeron.Publication)4 RecordingEventsAdapter (io.aeron.archive.client.RecordingEventsAdapter)4 ControlledEgressListener (io.aeron.cluster.client.ControlledEgressListener)4 Header (io.aeron.logbuffer.Header)4 DirectBuffer (org.agrona.DirectBuffer)4 Aeron (io.aeron.Aeron)2 CommonContext (io.aeron.CommonContext)2 ControlResponseAdapter (io.aeron.archive.client.ControlResponseAdapter)2 EgressListener (io.aeron.cluster.client.EgressListener)2 BufferClaim (io.aeron.logbuffer.BufferClaim)2 InterruptAfter (io.aeron.test.InterruptAfter)2 TestMediaDriver (io.aeron.test.driver.TestMediaDriver)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 AtomicCounter (org.agrona.concurrent.status.AtomicCounter)2 CountersReader (org.agrona.concurrent.status.CountersReader)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2