Search in sources :

Example 6 with MutableInteger

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

the class ArchiveMigration_2_3 method migrateCatalogFile.

private int migrateCatalogFile(final Catalog catalog, final int version, final MappedByteBuffer mappedByteBuffer) {
    final UnsafeBuffer buffer = new UnsafeBuffer(mappedByteBuffer);
    final int alignment = CACHE_LINE_LENGTH;
    // Create CatalogHeader for version 3.0.0
    final int catalogHeaderLength = writeCatalogHeader(buffer, version, catalog.nextRecordingId(), alignment);
    final MutableInteger offset = new MutableInteger(catalogHeaderLength);
    catalog.forEach((recordingDescriptorOffset, headerEncoder, headerDecoder, descriptorEncoder, descriptorDecoder) -> {
        final int strippedChannelLength = descriptorDecoder.strippedChannelLength();
        descriptorDecoder.skipStrippedChannel();
        final int originalChannelLength = descriptorDecoder.originalChannelLength();
        descriptorDecoder.skipOriginalChannel();
        final int sourceIdentityLength = descriptorDecoder.sourceIdentityLength();
        final int frameLength = align(DESCRIPTOR_HEADER_LENGTH + 7 * SIZE_OF_LONG + 6 * SIZE_OF_INT + SIZE_OF_INT + strippedChannelLength + SIZE_OF_INT + originalChannelLength + SIZE_OF_INT + sourceIdentityLength, alignment);
        final DirectBuffer srcBuffer = headerDecoder.buffer();
        final int headerLength = headerDecoder.encodedLength();
        // Copy recording header
        int index = offset.get();
        buffer.putBytes(index, srcBuffer, 0, headerLength);
        index += headerLength;
        // Correct length
        buffer.putInt(offset.get(), frameLength - headerLength, LITTLE_ENDIAN);
        // Copy recording descriptor
        buffer.putBytes(index, srcBuffer, headerLength, frameLength - headerLength);
        offset.addAndGet(frameLength);
    });
    return offset.get();
}
Also used : MutableInteger(org.agrona.collections.MutableInteger) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer)

Example 7 with MutableInteger

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

the class ClusterNodeTest method shouldEchoMessageViaServiceUsingTryClaim.

@Test
@InterruptAfter(10)
public void shouldEchoMessageViaServiceUsingTryClaim() {
    final ExpandableArrayBuffer msgBuffer = new ExpandableArrayBuffer();
    final String msg = "Hello World!";
    msgBuffer.putStringWithoutLengthAscii(0, msg);
    final MutableInteger messageCount = new MutableInteger();
    final EgressListener listener = (clusterSessionId, timestamp, buffer, offset, length, header) -> {
        assertEquals(msg, buffer.getStringWithoutLengthAscii(offset, length));
        messageCount.value += 1;
    };
    container = launchEchoService();
    aeronCluster = connectToCluster(listener);
    final BufferClaim bufferClaim = new BufferClaim();
    long publicationResult;
    do {
        publicationResult = aeronCluster.tryClaim(msg.length(), bufferClaim);
        if (publicationResult > 0) {
            final int offset = bufferClaim.offset() + AeronCluster.SESSION_HEADER_LENGTH;
            bufferClaim.buffer().putBytes(offset, msgBuffer, 0, msg.length());
            bufferClaim.commit();
        } else {
            Tests.yield();
        }
    } while (publicationResult < 0);
    offerMessage(msgBuffer, msg);
    awaitResponse(messageCount);
    ClusterTests.failOnClusterError();
}
Also used : ClusterTests(io.aeron.test.cluster.ClusterTests) AeronCluster(io.aeron.cluster.client.AeronCluster) Tests(io.aeron.test.Tests) BeforeEach(org.junit.jupiter.api.BeforeEach) StubClusteredService(io.aeron.test.cluster.StubClusteredService) ClusteredServiceContainer(io.aeron.cluster.service.ClusteredServiceContainer) CLUSTER_MEMBERS(io.aeron.cluster.ClusterTestConstants.CLUSTER_MEMBERS) ClusteredService(io.aeron.cluster.service.ClusteredService) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) BufferClaim(io.aeron.logbuffer.BufferClaim) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ArchiveThreadingMode(io.aeron.archive.ArchiveThreadingMode) MutableInteger(org.agrona.collections.MutableInteger) CloseHelper(org.agrona.CloseHelper) MediaDriver(io.aeron.driver.MediaDriver) InterruptingTestCallback(io.aeron.test.InterruptingTestCallback) Archive(io.aeron.archive.Archive) ExpandableArrayBuffer(org.agrona.ExpandableArrayBuffer) Test(org.junit.jupiter.api.Test) EgressListener(io.aeron.cluster.client.EgressListener) InterruptAfter(io.aeron.test.InterruptAfter) AfterEach(org.junit.jupiter.api.AfterEach) Header(io.aeron.logbuffer.Header) ClientSession(io.aeron.cluster.service.ClientSession) ThreadingMode(io.aeron.driver.ThreadingMode) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) INGRESS_ENDPOINTS(io.aeron.cluster.ClusterTestConstants.INGRESS_ENDPOINTS) DirectBuffer(org.agrona.DirectBuffer) MutableInteger(org.agrona.collections.MutableInteger) ExpandableArrayBuffer(org.agrona.ExpandableArrayBuffer) EgressListener(io.aeron.cluster.client.EgressListener) BufferClaim(io.aeron.logbuffer.BufferClaim) Test(org.junit.jupiter.api.Test) InterruptAfter(io.aeron.test.InterruptAfter)

Example 8 with MutableInteger

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

the class ClusterNodeTest method shouldEchoMessageViaServiceUsingDirectOffer.

@Test
@InterruptAfter(10)
public void shouldEchoMessageViaServiceUsingDirectOffer() {
    final ExpandableArrayBuffer msgBuffer = new ExpandableArrayBuffer();
    final String msg = "Hello World!";
    msgBuffer.putStringWithoutLengthAscii(0, msg);
    final MutableInteger messageCount = new MutableInteger();
    final EgressListener listener = (clusterSessionId, timestamp, buffer, offset, length, header) -> {
        assertEquals(msg, buffer.getStringWithoutLengthAscii(offset, length));
        messageCount.value += 1;
    };
    container = launchEchoService();
    aeronCluster = connectToCluster(listener);
    offerMessage(msgBuffer, msg);
    awaitResponse(messageCount);
    ClusterTests.failOnClusterError();
}
Also used : ClusterTests(io.aeron.test.cluster.ClusterTests) AeronCluster(io.aeron.cluster.client.AeronCluster) Tests(io.aeron.test.Tests) BeforeEach(org.junit.jupiter.api.BeforeEach) StubClusteredService(io.aeron.test.cluster.StubClusteredService) ClusteredServiceContainer(io.aeron.cluster.service.ClusteredServiceContainer) CLUSTER_MEMBERS(io.aeron.cluster.ClusterTestConstants.CLUSTER_MEMBERS) ClusteredService(io.aeron.cluster.service.ClusteredService) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) BufferClaim(io.aeron.logbuffer.BufferClaim) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ArchiveThreadingMode(io.aeron.archive.ArchiveThreadingMode) MutableInteger(org.agrona.collections.MutableInteger) CloseHelper(org.agrona.CloseHelper) MediaDriver(io.aeron.driver.MediaDriver) InterruptingTestCallback(io.aeron.test.InterruptingTestCallback) Archive(io.aeron.archive.Archive) ExpandableArrayBuffer(org.agrona.ExpandableArrayBuffer) Test(org.junit.jupiter.api.Test) EgressListener(io.aeron.cluster.client.EgressListener) InterruptAfter(io.aeron.test.InterruptAfter) AfterEach(org.junit.jupiter.api.AfterEach) Header(io.aeron.logbuffer.Header) ClientSession(io.aeron.cluster.service.ClientSession) ThreadingMode(io.aeron.driver.ThreadingMode) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) INGRESS_ENDPOINTS(io.aeron.cluster.ClusterTestConstants.INGRESS_ENDPOINTS) DirectBuffer(org.agrona.DirectBuffer) MutableInteger(org.agrona.collections.MutableInteger) ExpandableArrayBuffer(org.agrona.ExpandableArrayBuffer) EgressListener(io.aeron.cluster.client.EgressListener) Test(org.junit.jupiter.api.Test) InterruptAfter(io.aeron.test.InterruptAfter)

Example 9 with MutableInteger

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

the class StatusUtil method controllableIdleStrategy.

/**
 * Return the controllable idle strategy {@link StatusIndicator}.
 *
 * @param countersReader that holds the status indicator.
 * @return status indicator to use or null if not found.
 */
public static StatusIndicator controllableIdleStrategy(final CountersReader countersReader) {
    StatusIndicator statusIndicator = null;
    final MutableInteger id = new MutableInteger(-1);
    countersReader.forEach((counterId, label) -> {
        if (counterId == SystemCounterDescriptor.CONTROLLABLE_IDLE_STRATEGY.id() && label.equals(SystemCounterDescriptor.CONTROLLABLE_IDLE_STRATEGY.label())) {
            id.value = counterId;
        }
    });
    if (Aeron.NULL_VALUE != id.value) {
        statusIndicator = new UnsafeBufferStatusIndicator(countersReader.valuesBuffer(), id.value);
    }
    return statusIndicator;
}
Also used : StatusIndicator(org.agrona.concurrent.status.StatusIndicator) UnsafeBufferStatusIndicator(org.agrona.concurrent.status.UnsafeBufferStatusIndicator) MutableInteger(org.agrona.collections.MutableInteger) UnsafeBufferStatusIndicator(org.agrona.concurrent.status.UnsafeBufferStatusIndicator)

Example 10 with MutableInteger

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

the class StatusUtil method sendChannelStatus.

/**
 * Return the read-only status indicator for the given send channel URI.
 *
 * @param countersReader that holds the status indicator.
 * @param channel        for the send channel.
 * @return read-only status indicator that can be used to query the status of the send channel or null.
 * @see ChannelEndpointStatus for status values and indications.
 */
public static StatusIndicatorReader sendChannelStatus(final CountersReader countersReader, final String channel) {
    StatusIndicatorReader statusReader = null;
    final MutableInteger id = new MutableInteger(-1);
    countersReader.forEach((counterId, typeId, keyBuffer, label) -> {
        if (typeId == SendChannelStatus.SEND_CHANNEL_STATUS_TYPE_ID) {
            if (channel.startsWith(keyBuffer.getStringAscii(ChannelEndpointStatus.CHANNEL_OFFSET))) {
                id.value = counterId;
            }
        }
    });
    if (Aeron.NULL_VALUE != id.value) {
        statusReader = new UnsafeBufferStatusIndicator(countersReader.valuesBuffer(), id.value);
    }
    return statusReader;
}
Also used : StatusIndicatorReader(org.agrona.concurrent.status.StatusIndicatorReader) MutableInteger(org.agrona.collections.MutableInteger) UnsafeBufferStatusIndicator(org.agrona.concurrent.status.UnsafeBufferStatusIndicator)

Aggregations

MutableInteger (org.agrona.collections.MutableInteger)145 UnsafeBuffer (org.agrona.concurrent.UnsafeBuffer)72 DirectBuffer (org.agrona.DirectBuffer)58 Test (org.junit.jupiter.api.Test)55 InterruptAfter (io.aeron.test.InterruptAfter)52 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)40 MethodSource (org.junit.jupiter.params.provider.MethodSource)38 Test (org.junit.Test)33 ByteBuffer (java.nio.ByteBuffer)32 UTF_8 (java.nio.charset.StandardCharsets.UTF_8)29 Array32FW (io.aklivity.zilla.specs.binding.kafka.internal.types.Array32FW)28 HEADER (io.aklivity.zilla.specs.binding.kafka.internal.types.KafkaConditionType.HEADER)28 HEADERS (io.aklivity.zilla.specs.binding.kafka.internal.types.KafkaConditionType.HEADERS)28 KEY (io.aklivity.zilla.specs.binding.kafka.internal.types.KafkaConditionType.KEY)28 NOT (io.aklivity.zilla.specs.binding.kafka.internal.types.KafkaConditionType.NOT)28 KafkaDeltaType (io.aklivity.zilla.specs.binding.kafka.internal.types.KafkaDeltaType)28 KafkaOffsetFW (io.aklivity.zilla.specs.binding.kafka.internal.types.KafkaOffsetFW)28 KafkaSkip (io.aklivity.zilla.specs.binding.kafka.internal.types.KafkaSkip)28 KafkaValueMatchFW (io.aklivity.zilla.specs.binding.kafka.internal.types.KafkaValueMatchFW)28 OctetsFW (io.aklivity.zilla.specs.binding.kafka.internal.types.OctetsFW)28