use of org.agrona.collections.MutableInteger in project aeron by real-logic.
the class MultiDestinationCastTest method shouldSendToTwoPortsWithManualSingleDriver.
@Test(timeout = 10_000)
public void shouldSendToTwoPortsWithManualSingleDriver() {
final int numMessagesToSend = NUM_MESSAGES_PER_TERM * 3;
launch();
publication = clientA.addPublication(PUB_MDC_MANUAL_URI, STREAM_ID);
subscriptionA = clientA.addSubscription(SUB1_MDC_MANUAL_URI, STREAM_ID);
subscriptionB = clientA.addSubscription(SUB2_MDC_MANUAL_URI, STREAM_ID);
publication.addDestination(SUB1_MDC_MANUAL_URI);
publication.addDestination(SUB2_MDC_MANUAL_URI);
while (!subscriptionA.isConnected() || !subscriptionB.isConnected()) {
SystemTest.checkInterruptedStatus();
Thread.yield();
}
for (int i = 0; i < numMessagesToSend; i++) {
while (publication.offer(buffer, 0, buffer.capacity()) < 0L) {
SystemTest.checkInterruptedStatus();
Thread.yield();
}
final MutableInteger fragmentsRead = new MutableInteger();
pollForFragment(subscriptionA, fragmentHandlerA, fragmentsRead);
fragmentsRead.set(0);
pollForFragment(subscriptionB, fragmentHandlerB, fragmentsRead);
}
verifyFragments(fragmentHandlerA, numMessagesToSend);
verifyFragments(fragmentHandlerB, numMessagesToSend);
}
use of org.agrona.collections.MutableInteger in project aeron by real-logic.
the class ClusterNodeTest method shouldEchoMessageViaService.
@Test(timeout = 10_000)
public void shouldEchoMessageViaService() {
container = launchEchoService();
aeronCluster = connectToCluster();
final Aeron aeron = aeronCluster.context().aeron();
final SessionDecorator sessionDecorator = new SessionDecorator(aeronCluster.clusterSessionId());
final Publication publication = aeronCluster.ingressPublication();
final ExpandableArrayBuffer msgBuffer = new ExpandableArrayBuffer();
final long msgCorrelationId = aeron.nextCorrelationId();
final String msg = "Hello World!";
msgBuffer.putStringWithoutLengthAscii(0, msg);
while (sessionDecorator.offer(publication, msgCorrelationId, msgBuffer, 0, msg.length()) < 0) {
TestUtil.checkInterruptedStatus();
Thread.yield();
}
final MutableInteger messageCount = new MutableInteger();
final EgressAdapter adapter = new EgressAdapter(new StubEgressListener() {
public void onMessage(final long correlationId, final long clusterSessionId, final long timestamp, final DirectBuffer buffer, final int offset, final int length, final Header header) {
assertThat(correlationId, is(msgCorrelationId));
assertThat(buffer.getStringWithoutLengthAscii(offset, length), is(msg));
messageCount.value += 1;
}
}, aeronCluster.egressSubscription(), FRAGMENT_LIMIT);
while (messageCount.get() == 0) {
if (adapter.poll() <= 0) {
TestUtil.checkInterruptedStatus();
Thread.yield();
}
}
}
use of org.agrona.collections.MutableInteger in project aeron by real-logic.
the class StatusUtil method receiveChannelStatus.
/**
* Return the read-only status indicator for the given receive channel URI.
*
* @param countersReader that holds the status indicator.
* @param channel for the receive channel.
* @return read-only status indicator that can be used to query the status of the receive channel or null.
* @see ChannelEndpointStatus for status values and indications.
*/
public static StatusIndicatorReader receiveChannelStatus(final CountersReader countersReader, final String channel) {
StatusIndicatorReader statusReader = null;
final MutableInteger id = new MutableInteger(-1);
countersReader.forEach((counterId, typeId, keyBuffer, label) -> {
if (typeId == ReceiveChannelStatus.RECEIVE_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;
}
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;
}
use of org.agrona.collections.MutableInteger in project aeron by real-logic.
the class ClusterNodeTest method shouldScheduleEventInService.
@Test
@InterruptAfter(10)
public void shouldScheduleEventInService() {
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) -> {
final String expected = msg + "-scheduled";
assertEquals(expected, buffer.getStringWithoutLengthAscii(offset, length));
messageCount.value += 1;
};
container = launchTimedService();
aeronCluster = connectToCluster(listener);
offerMessage(msgBuffer, msg);
awaitResponse(messageCount);
ClusterTests.failOnClusterError();
}
Aggregations