Search in sources :

Example 41 with MutableLong

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;
}
Also used : CommonContext(io.aeron.CommonContext) MutableLong(org.agrona.collections.MutableLong) ConsensusModuleProxy(io.aeron.cluster.service.ConsensusModuleProxy) ArrayList(java.util.ArrayList) List(java.util.List) Aeron(io.aeron.Aeron)

Example 42 with MutableLong

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();
}
Also used : RecordingPos(io.aeron.archive.status.RecordingPos) MediaDriver(io.aeron.driver.MediaDriver) RecordingDescriptorConsumer(io.aeron.archive.client.RecordingDescriptorConsumer) CountersReader(org.agrona.concurrent.status.CountersReader) LOCAL(io.aeron.archive.codecs.SourceLocation.LOCAL) Test(org.junit.Test) ExpandableArrayBuffer(org.agrona.ExpandableArrayBuffer) IoUtil(org.agrona.IoUtil) File(java.io.File) Assert.assertThat(org.junit.Assert.assertThat) io.aeron(io.aeron) MutableLong(org.agrona.collections.MutableLong) ThreadingMode(io.aeron.driver.ThreadingMode) After(org.junit.After) AeronArchive(io.aeron.archive.client.AeronArchive) Is.is(org.hamcrest.core.Is.is) Matchers.greaterThan(org.hamcrest.Matchers.greaterThan) FragmentHandler(io.aeron.logbuffer.FragmentHandler) MutableInteger(org.agrona.collections.MutableInteger) CloseHelper(org.agrona.CloseHelper) NULL_POSITION(io.aeron.archive.client.AeronArchive.NULL_POSITION) Assert.assertEquals(org.junit.Assert.assertEquals) Before(org.junit.Before) MutableLong(org.agrona.collections.MutableLong) RecordingDescriptorConsumer(io.aeron.archive.client.RecordingDescriptorConsumer)

Example 43 with MutableLong

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();
}
Also used : MediaDriver(io.aeron.driver.MediaDriver) FRAME_ALIGNMENT(io.aeron.logbuffer.FrameDescriptor.FRAME_ALIGNMENT) NOOP_FRAGMENT_HANDLER(io.aeron.samples.archive.TestUtil.NOOP_FRAGMENT_HANDLER) RecordingDescriptorConsumer(io.aeron.archive.client.RecordingDescriptorConsumer) SampleConfiguration(io.aeron.samples.SampleConfiguration) MEGABYTE(io.aeron.samples.archive.TestUtil.MEGABYTE) Archive(io.aeron.archive.Archive) SystemUtil.loadPropertiesFiles(org.agrona.SystemUtil.loadPropertiesFiles) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) File(java.io.File) io.aeron(io.aeron) BufferUtil.allocateDirectAligned(org.agrona.BufferUtil.allocateDirectAligned) Header(io.aeron.logbuffer.Header) MutableLong(org.agrona.collections.MutableLong) ArchivingMediaDriver(io.aeron.archive.ArchivingMediaDriver) AeronArchive(io.aeron.archive.client.AeronArchive) ContinueBarrier(org.agrona.console.ContinueBarrier) FragmentHandler(io.aeron.logbuffer.FragmentHandler) CloseHelper(org.agrona.CloseHelper) DirectBuffer(org.agrona.DirectBuffer) ARCHIVE_DIR_DEFAULT(io.aeron.archive.Archive.Configuration.ARCHIVE_DIR_DEFAULT) MutableLong(org.agrona.collections.MutableLong) RecordingDescriptorConsumer(io.aeron.archive.client.RecordingDescriptorConsumer)

Example 44 with MutableLong

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));
}
Also used : MutableLong(org.agrona.collections.MutableLong) Test(org.junit.jupiter.api.Test)

Example 45 with MutableLong

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();
}
Also used : CommonContext(io.aeron.CommonContext) MutableLong(org.agrona.collections.MutableLong) Aeron(io.aeron.Aeron)

Aggregations

MutableLong (org.agrona.collections.MutableLong)82 Test (org.junit.jupiter.api.Test)68 InterruptAfter (io.aeron.test.InterruptAfter)44 MutableReference (org.agrona.collections.MutableReference)28 CountersReader (org.agrona.concurrent.status.CountersReader)19 RecordingSignal (io.aeron.archive.codecs.RecordingSignal)18 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)16 MediaDriver (io.aeron.driver.MediaDriver)14 FragmentHandler (io.aeron.logbuffer.FragmentHandler)14 DirectBuffer (org.agrona.DirectBuffer)13 UnsafeBuffer (org.agrona.concurrent.UnsafeBuffer)11 RegistrationException (io.aeron.exceptions.RegistrationException)10 TestMediaDriver (io.aeron.test.driver.TestMediaDriver)10 AtomicLong (java.util.concurrent.atomic.AtomicLong)10 Assertions.assertThrows (org.junit.jupiter.api.Assertions.assertThrows)10 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)10 RegisterExtension (org.junit.jupiter.api.extension.RegisterExtension)10 AeronArchive (io.aeron.archive.client.AeronArchive)8 Authenticator (io.aeron.security.Authenticator)8 CredentialsSupplier (io.aeron.security.CredentialsSupplier)8