use of org.agrona.ExpandableArrayBuffer in project aeron by real-logic.
the class FileSender method sendFileCreate.
private static void sendFileCreate(final Publication publication, final long correlationId, final int length, final String filename) {
final ExpandableArrayBuffer buffer = new ExpandableArrayBuffer();
buffer.putInt(VERSION_OFFSET, VERSION, LITTLE_ENDIAN);
buffer.putInt(TYPE_OFFSET, FILE_CREATE_TYPE, LITTLE_ENDIAN);
buffer.putLong(CORRELATION_ID_OFFSET, correlationId, LITTLE_ENDIAN);
buffer.putLong(FILE_LENGTH_OFFSET, length, LITTLE_ENDIAN);
final int msgLength = FILE_NAME_OFFSET + buffer.putStringUtf8(FILE_NAME_OFFSET, filename);
long result;
while ((result = publication.offer(buffer, 0, msgLength)) < 0) {
checkResult(result);
Thread.yield();
}
}
use of org.agrona.ExpandableArrayBuffer in project aeron by real-logic.
the class BasicArchiveTest method offer.
private static void offer(final Publication publication, final int count, final String prefix) {
final ExpandableArrayBuffer buffer = new ExpandableArrayBuffer();
for (int i = 0; i < count; i++) {
final int length = buffer.putStringWithoutLengthAscii(0, prefix + i);
while (publication.offer(buffer, 0, length) <= 0) {
SystemTest.checkInterruptedStatus();
Thread.yield();
}
}
}
use of org.agrona.ExpandableArrayBuffer in project aeron by real-logic.
the class ExtendRecordingTest method offer.
private static void offer(final Publication publication, final int startIndex, final int count, final String prefix) {
final ExpandableArrayBuffer buffer = new ExpandableArrayBuffer();
for (int i = startIndex; i < (startIndex + count); i++) {
final int length = buffer.putStringWithoutLengthAscii(0, prefix + i);
while (publication.offer(buffer, 0, length) <= 0) {
SystemTest.checkInterruptedStatus();
Thread.yield();
}
}
}
use of org.agrona.ExpandableArrayBuffer in project aeron by real-logic.
the class ClusterNodeTest method shouldScheduleEventInService.
@Test(timeout = 10_000)
public void shouldScheduleEventInService() {
container = launchTimedService();
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 + "-scheduled"));
messageCount.value += 1;
}
}, aeronCluster.egressSubscription(), FRAGMENT_LIMIT);
while (messageCount.get() == 0) {
if (adapter.poll() <= 0) {
TestUtil.checkInterruptedStatus();
Thread.yield();
}
}
}
use of org.agrona.ExpandableArrayBuffer 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();
}
}
}
Aggregations