use of org.agrona.DirectBuffer 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.DirectBuffer in project aeron by real-logic.
the class ClusterNodeTest method launchEchoService.
private ClusteredServiceContainer launchEchoService() {
final ClusteredService echoService = new StubClusteredService() {
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 ClientSession session = cluster.getClientSession(clusterSessionId);
while (session.offer(correlationId, buffer, offset, length) < 0) {
TestUtil.checkInterruptedStatus();
Thread.yield();
}
}
};
return ClusteredServiceContainer.launch(new ClusteredServiceContainer.Context().clusteredService(echoService).errorHandler(Throwable::printStackTrace).deleteDirOnStart(true));
}
use of org.agrona.DirectBuffer in project zeebe by zeebe-io.
the class ClusterManager method onInvitationRequest.
public boolean onInvitationRequest(final DirectBuffer buffer, final int offset, final int length, final ServerOutput output, final RemoteAddress requestAddress, final long requestId) {
invitationRequest.reset();
invitationRequest.wrap(buffer, offset, length);
LOG.debug("Received invitation request from {} for partition {}", requestAddress.getAddress(), invitationRequest.partitionId());
final DirectBuffer topicName = invitationRequest.topicName();
final int partitionId = invitationRequest.partitionId();
createPartition(topicName, partitionId, new ArrayList<>(invitationRequest.members()));
invitationResponse.reset();
response.reset().remoteAddress(requestAddress).requestId(requestId).writer(invitationResponse);
return output.sendResponse(response);
}
use of org.agrona.DirectBuffer in project zeebe by zeebe-io.
the class POJOMappingBenchmark method performReadingReverseOrder.
@Benchmark
@Threads(1)
public void performReadingReverseOrder(POJOMappingContext ctx) {
final TaskEvent taskEvent = ctx.getTaskEvent();
final DirectBuffer encodedTaskEvent = ctx.getReverseOrderEncodedTaskEvent();
taskEvent.reset();
taskEvent.wrap(encodedTaskEvent, 0, encodedTaskEvent.capacity());
}
use of org.agrona.DirectBuffer in project zeebe by zeebe-io.
the class Events method readValueAs.
protected static <T extends UnpackedObject> T readValueAs(LoggedEvent event, Class<T> valueClass) {
final DirectBuffer copy = BufferUtil.cloneBuffer(event.getValueBuffer(), event.getValueOffset(), event.getValueLength());
final T valuePojo = ReflectUtil.newInstance(valueClass);
valuePojo.wrap(copy);
return valuePojo;
}
Aggregations