Search in sources :

Example 6 with DirectBuffer

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();
        }
    }
}
Also used : DirectBuffer(org.agrona.DirectBuffer) Header(io.aeron.logbuffer.Header) MutableInteger(org.agrona.collections.MutableInteger) Publication(io.aeron.Publication) SessionDecorator(io.aeron.cluster.client.SessionDecorator) Aeron(io.aeron.Aeron) ExpandableArrayBuffer(org.agrona.ExpandableArrayBuffer) EgressAdapter(io.aeron.cluster.client.EgressAdapter) Test(org.junit.Test)

Example 7 with DirectBuffer

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));
}
Also used : DirectBuffer(org.agrona.DirectBuffer) Header(io.aeron.logbuffer.Header) ClientSession(io.aeron.cluster.service.ClientSession) ClusteredService(io.aeron.cluster.service.ClusteredService)

Example 8 with DirectBuffer

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);
}
Also used : DirectBuffer(org.agrona.DirectBuffer)

Example 9 with DirectBuffer

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());
}
Also used : MutableDirectBuffer(org.agrona.MutableDirectBuffer) DirectBuffer(org.agrona.DirectBuffer) TaskEvent(io.zeebe.broker.taskqueue.data.TaskEvent) Threads(org.openjdk.jmh.annotations.Threads) Benchmark(org.openjdk.jmh.annotations.Benchmark)

Example 10 with DirectBuffer

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;
}
Also used : DirectBuffer(org.agrona.DirectBuffer)

Aggregations

DirectBuffer (org.agrona.DirectBuffer)102 Header (io.aeron.logbuffer.Header)18 MutableDirectBuffer (org.agrona.MutableDirectBuffer)16 UnsafeBuffer (org.agrona.concurrent.UnsafeBuffer)15 File (java.io.File)14 MappedByteBuffer (java.nio.MappedByteBuffer)11 Test (org.junit.Test)11 MediaDriver (io.aeron.driver.MediaDriver)10 CountersReader (org.agrona.concurrent.status.CountersReader)10 ClusteredService (io.aeron.cluster.service.ClusteredService)8 Publication (io.aeron.Publication)7 ClientSession (io.aeron.cluster.service.ClientSession)7 ExpandableArrayBuffer (org.agrona.ExpandableArrayBuffer)7 ThreadingMode (io.aeron.driver.ThreadingMode)6 FragmentHandler (io.aeron.logbuffer.FragmentHandler)6 ByteBuffer (java.nio.ByteBuffer)6 ClusteredServiceContainer (io.aeron.cluster.service.ClusteredServiceContainer)5 InterruptAfter (io.aeron.test.InterruptAfter)5 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)5 LogBufferDescriptor (io.aeron.logbuffer.LogBufferDescriptor)4