use of org.agrona.collections.MutableLong in project aeron by real-logic.
the class ClusterTool method queryClusterMembers.
/**
* Query the membership of a cluster.
*
* @param controlProperties from a {@link ClusterMarkFile}.
* @param timeoutMs to wait for the query.
* @param clusterMembership to populate.
* @return true if the query was successful.
*/
public static boolean queryClusterMembers(final ClusterNodeControlProperties controlProperties, final long timeoutMs, final ClusterMembership clusterMembership) {
final MutableLong id = new MutableLong(NULL_VALUE);
final ClusterControlAdapter.Listener listener = new ClusterControlAdapter.Listener() {
public void onClusterMembersResponse(final long correlationId, final int leaderMemberId, final String activeMembers, final String passiveMembers) {
if (correlationId == id.get()) {
clusterMembership.leaderMemberId = leaderMemberId;
clusterMembership.activeMembersStr = activeMembers;
clusterMembership.passiveMembersStr = passiveMembers;
id.set(NULL_VALUE);
}
}
public void onClusterMembersExtendedResponse(final long correlationId, final long currentTimeNs, final int leaderMemberId, final int memberId, final List<ClusterMember> activeMembers, final List<ClusterMember> passiveMembers) {
if (correlationId == id.get()) {
clusterMembership.currentTimeNs = currentTimeNs;
clusterMembership.leaderMemberId = leaderMemberId;
clusterMembership.memberId = memberId;
clusterMembership.activeMembers = activeMembers;
clusterMembership.passiveMembers = passiveMembers;
clusterMembership.activeMembersStr = ClusterMember.encodeAsString(activeMembers);
clusterMembership.passiveMembersStr = ClusterMember.encodeAsString(passiveMembers);
id.set(NULL_VALUE);
}
}
};
try (Aeron aeron = Aeron.connect(new Aeron.Context().aeronDirectoryName(controlProperties.aeronDirectoryName));
ConsensusModuleProxy consensusModuleProxy = new ConsensusModuleProxy(aeron.addPublication(controlProperties.controlChannel, controlProperties.consensusModuleStreamId));
ClusterControlAdapter clusterControlAdapter = new ClusterControlAdapter(aeron.addSubscription(controlProperties.controlChannel, controlProperties.serviceStreamId), listener)) {
id.set(aeron.nextCorrelationId());
if (consensusModuleProxy.clusterMembersQuery(id.get())) {
final long startTime = System.currentTimeMillis();
do {
if (clusterControlAdapter.poll() == 0) {
if ((System.currentTimeMillis() - startTime) > timeoutMs) {
break;
}
Thread.yield();
}
} while (NULL_VALUE != id.get());
}
}
return id.get() == NULL_VALUE;
}
use of org.agrona.collections.MutableLong in project aeron by real-logic.
the class BasicArchiveTest method findRecordingId.
private long findRecordingId(final String expectedChannel, final int expectedStreamId, final long expectedPosition) {
final MutableLong foundRecordingId = new MutableLong();
final RecordingDescriptorConsumer consumer = (controlSessionId, correlationId, recordingId, startTimestamp, stopTimestamp, startPosition, stopPosition, initialTermId, segmentFileLength, termBufferLength, mtuLength, sessionId, streamId, strippedChannel, originalChannel, sourceIdentity) -> {
foundRecordingId.set(recordingId);
assertEquals(0L, startPosition);
assertEquals(expectedPosition, stopPosition);
assertEquals(expectedStreamId, streamId);
assertEquals(expectedChannel, originalChannel);
};
final int recordingsFound = aeronArchive.listRecordingsForUri(0L, 10, expectedChannel, expectedStreamId, consumer);
assertThat(recordingsFound, greaterThan(0));
return foundRecordingId.get();
}
use of org.agrona.collections.MutableLong in project aeron by real-logic.
the class EmbeddedReplayThroughput method findRecordingId.
private long findRecordingId(final String expectedChannel, final int expectedStreamId) {
final MutableLong foundRecordingId = new MutableLong();
final RecordingDescriptorConsumer consumer = (controlSessionId, correlationId, recordingId, startTimestamp, stopTimestamp, startPosition, stopPosition, initialTermId, segmentFileLength, termBufferLength, mtuLength, sessionId, streamId, strippedChannel, originalChannel, sourceIdentity) -> foundRecordingId.set(recordingId);
final int recordingsFound = aeronArchive.listRecordingsForUri(0L, 10, expectedChannel, expectedStreamId, consumer);
if (1 != recordingsFound) {
throw new IllegalStateException("Should have been one recording");
}
return foundRecordingId.get();
}
use of org.agrona.collections.MutableLong in project Aeron by real-logic.
the class ListRecordingsForUriSessionTest method shouldSendAllDescriptors.
@Test
public void shouldSendAllDescriptors() {
final ListRecordingsForUriSession session = new ListRecordingsForUriSession(correlationId, 0, 3, LOCALHOST_BYTES, 1, catalog, controlResponseProxy, controlSession, descriptorBuffer, recordingDescriptorDecoder);
final MutableLong counter = new MutableLong(0);
when(controlSession.sendDescriptor(eq(correlationId), any(), eq(controlResponseProxy))).then(verifySendDescriptor(counter));
assertEquals(3, session.doWork());
verify(controlSession, times(3)).sendDescriptor(eq(correlationId), any(), eq(controlResponseProxy));
}
use of org.agrona.collections.MutableLong in project Aeron by real-logic.
the class ClusterTool method nextBackupQueryDeadlineMs.
/**
* Get the deadline time (MS) for the next cluster backup query.
*
* @param markFile for the cluster component.
* @return the deadline time (MS) for the next cluster backup query, or {@link Aeron#NULL_VALUE} not available.
*/
public static long nextBackupQueryDeadlineMs(final ClusterMarkFile markFile) {
final String aeronDirectoryName = markFile.decoder().aeronDirectory();
final MutableLong nextQueryMs = new MutableLong(NULL_VALUE);
try (Aeron aeron = Aeron.connect(new Aeron.Context().aeronDirectoryName(aeronDirectoryName))) {
aeron.countersReader().forEach((counterId, typeId, keyBuffer, label) -> {
if (ClusterBackup.QUERY_DEADLINE_TYPE_ID == typeId) {
nextQueryMs.set(aeron.countersReader().getCounterValue(counterId));
}
});
}
return nextQueryMs.get();
}
Aggregations