org.agrona.collections.MutableBoolean Java Examples

The following examples show how to use org.agrona.collections.MutableBoolean. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ClusterTool.java    From aeron with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #2
Source File: AgentRunnerTest.java    From agrona with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldRaiseInterruptFlagByClose() throws Exception
{
    when(mockAgent.doWork()).then(answersWithDelay(500, RETURNS_DEFAULTS));

    new Thread(runner).start();

    while (runner.thread() == null)
    {
        Thread.yield();
    }

    Thread.currentThread().interrupt();

    final MutableBoolean actionCalled = new MutableBoolean();
    final Consumer<Thread> failedCloseAction = (ignore) -> actionCalled.set(true);
    runner.close(AgentRunner.RETRY_CLOSE_TIMEOUT_MS, failedCloseAction);

    assertTrue(Thread.interrupted());
    assertTrue(actionCalled.get());
}
 
Example #3
Source File: ArchiveTest.java    From aeron with Apache License 2.0 5 votes vote down vote up
private void preSendChecks(
    final ArchiveProxy archiveProxy,
    final Subscription recordingEvents,
    final int sessionId,
    final int termBufferLength,
    final long startPosition)
{
    final MutableBoolean recordingStarted = new MutableBoolean();
    final RecordingEventsAdapter recordingEventsAdapter = new RecordingEventsAdapter(
        new FailRecordingEventsListener()
        {
            public void onStart(
                final long recordingId0,
                final long startPosition0,
                final int sessionId0,
                final int streamId0,
                final String channel,
                final String sourceIdentity)
            {
                recordingId = recordingId0;
                assertEquals(PUBLISH_STREAM_ID, streamId0);
                assertEquals(sessionId, sessionId0);
                assertEquals(startPosition, startPosition0);
                recordingStarted.set(true);
            }
        },
        recordingEvents,
        1);

    while (!recordingStarted.get())
    {
        if (recordingEventsAdapter.poll() == 0)
        {
            Tests.yield();
        }
    }

    verifyDescriptorListOngoingArchive(archiveProxy, termBufferLength);
}
 
Example #4
Source File: BufferClaimMessageTest.java    From aeron with Apache License 2.0 5 votes vote down vote up
@ParameterizedTest
@MethodSource("channels")
@Timeout(10)
public void shouldTransferReservedValue(final String channel)
{
    final BufferClaim bufferClaim = new BufferClaim();

    try (Subscription subscription = aeron.addSubscription(channel, STREAM_ID);
        Publication publication = aeron.addPublication(channel, STREAM_ID))
    {
        while (publication.tryClaim(MESSAGE_LENGTH, bufferClaim) < 0L)
        {
            Tests.yield();
        }

        final long reservedValue = System.currentTimeMillis();
        bufferClaim.reservedValue(reservedValue);
        bufferClaim.commit();

        final MutableBoolean done = new MutableBoolean();
        while (!done.get())
        {
            final int fragments = subscription.poll(
                (buffer, offset, length, header) ->
                {
                    assertEquals(MESSAGE_LENGTH, length);
                    assertEquals(reservedValue, header.reservedValue());

                    done.value = true;
                },
                FRAGMENT_COUNT_LIMIT);

            if (0 == fragments)
            {
                Tests.yield();
            }
        }
    }
}
 
Example #5
Source File: ArchiveTest.java    From aeron with Apache License 2.0 4 votes vote down vote up
private void postPublicationValidations(
    final ArchiveProxy archiveProxy,
    final Subscription recordingEvents,
    final int termBufferLength,
    final int initialTermId,
    final int maxPayloadLength,
    final int messageCount)
{
    verifyDescriptorListOngoingArchive(archiveProxy, termBufferLength);
    assertNull(trackerError);

    final long requestStopCorrelationId = correlationId++;
    if (!archiveProxy.stopRecording(publishUri, PUBLISH_STREAM_ID, requestStopCorrelationId, controlSessionId))
    {
        throw new IllegalStateException("Failed to stop recording");
    }

    ArchiveTests.awaitOk(controlResponse, requestStopCorrelationId);

    final MutableBoolean recordingStopped = new MutableBoolean();
    final RecordingEventsAdapter recordingEventsAdapter = new RecordingEventsAdapter(
        new FailRecordingEventsListener()
        {
            public void onStop(final long id, final long startPosition, final long stopPosition)
            {
                assertEquals(recordingId, id);
                recordingStopped.set(true);
            }
        },
        recordingEvents,
        1);

    while (!recordingStopped.get())
    {
        if (recordingEventsAdapter.poll() == 0)
        {
            Tests.yield();
        }
    }

    verifyDescriptorListOngoingArchive(archiveProxy, termBufferLength);
    validateArchiveFile(messageCount, recordingId);
    validateReplay(archiveProxy, messageCount, initialTermId, maxPayloadLength, termBufferLength);
}