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 ArchiveCreator method offerToPosition.
private static void offerToPosition(final Publication publication, final long minimumPosition) {
final ExpandableArrayBuffer buffer = new ExpandableArrayBuffer();
for (int i = 0; publication.position() < minimumPosition; i++) {
final int length = buffer.putStringWithoutLengthAscii(0, MESSAGE_PREFIX + i);
while (publication.offer(buffer, 0, length) <= 0) {
Thread.yield();
checkInterruptStatus();
}
}
}
use of org.agrona.ExpandableArrayBuffer in project Aeron by real-logic.
the class MultiModuleSharedDriverTest method echoMessage.
private void echoMessage(final AeronCluster client, final String message, final MutableReference<String> egress) {
final ExpandableArrayBuffer buffer = new ExpandableArrayBuffer();
final int length = buffer.putStringWithoutLengthAscii(0, message);
while (client.offer(buffer, 0, length) < 0) {
Tests.yield();
}
egress.set(null);
while (null == egress.get()) {
Tests.yield();
client.pollEgress();
}
assertEquals(message, egress.get());
}
use of org.agrona.ExpandableArrayBuffer in project Aeron by real-logic.
the class ClusterTests method startPublisherThread.
public static Thread startPublisherThread(final TestCluster testCluster, final MutableInteger messageCounter, final long backoffIntervalNs) {
final Thread thread = new Thread(() -> {
final IdleStrategy idleStrategy = YieldingIdleStrategy.INSTANCE;
final AeronCluster client = testCluster.client();
final ExpandableArrayBuffer msgBuffer = testCluster.msgBuffer();
msgBuffer.putStringWithoutLengthAscii(0, HELLO_WORLD_MSG);
while (!Thread.interrupted()) {
final long result = client.offer(msgBuffer, 0, HELLO_WORLD_MSG.length());
if (result > 0) {
messageCounter.increment();
} else {
if (Publication.CLOSED == result) {
break;
}
LockSupport.parkNanos(backoffIntervalNs);
}
idleStrategy.idle(client.pollEgress());
}
});
thread.setDaemon(true);
thread.setName("message-thread");
thread.start();
return thread;
}
use of org.agrona.ExpandableArrayBuffer in project aeron by real-logic.
the class ClusterNodeRestartTest method launchService.
private void launchService(final boolean initialLaunch, final AtomicLong msgCounter) {
final ClusteredService service = new StubClusteredService() {
private int counterValue = 0;
public void onSessionMessage(final long clusterSessionId, final long correlationId, final long timestampMs, final DirectBuffer buffer, final int offset, final int length, final Header header) {
final int sentValue = buffer.getInt(offset);
assertThat(sentValue, is(counterValue));
counterValue++;
serviceState.set(Integer.toString(counterValue));
msgCounter.getAndIncrement();
}
public void onTakeSnapshot(final Publication snapshotPublication) {
final ExpandableArrayBuffer buffer = new ExpandableArrayBuffer();
int length = 0;
buffer.putInt(length, counterValue);
length += SIZE_OF_INT;
length += buffer.putIntAscii(length, counterValue);
snapshotPublication.offer(buffer, 0, length);
}
public void onLoadSnapshot(final Image snapshotImage) {
while (true) {
final int fragments = snapshotImage.poll((buffer, offset, length, header) -> {
counterValue = buffer.getInt(offset);
final String s = buffer.getStringWithoutLengthAscii(offset + SIZE_OF_INT, length - SIZE_OF_INT);
serviceState.set(s);
}, 1);
if (fragments == 1) {
break;
}
TestUtil.checkInterruptedStatus();
Thread.yield();
}
}
};
container = null;
container = ClusteredServiceContainer.launch(new ClusteredServiceContainer.Context().clusteredService(service).terminationHook(() -> {
}).errorHandler(Throwable::printStackTrace).deleteDirOnStart(initialLaunch));
}
Aggregations