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;
}
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;
}
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;
}
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);
}
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;
}
Aggregations