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