Search in sources :

Example 31 with MutableDirectBuffer

use of org.agrona.MutableDirectBuffer in project zeebe by zeebe-io.

the class InvitationRequest method wrap.

@Override
public void wrap(final DirectBuffer buffer, int offset, final int length) {
    final int frameEnd = offset + length;
    headerDecoder.wrap(buffer, offset);
    offset += headerDecoder.encodedLength();
    bodyDecoder.wrap(buffer, offset, headerDecoder.blockLength(), headerDecoder.version());
    partitionId = bodyDecoder.partitionId();
    term = bodyDecoder.term();
    members.clear();
    final Iterator<MembersDecoder> iterator = bodyDecoder.members().iterator();
    while (iterator.hasNext()) {
        final MembersDecoder decoder = iterator.next();
        final SocketAddress member = new SocketAddress();
        member.port(decoder.port());
        final MutableDirectBuffer hostBuffer = member.getHostBuffer();
        final int hostLength = decoder.hostLength();
        member.hostLength(hostLength);
        decoder.getHost(hostBuffer, 0, hostLength);
        members.add(member);
    }
    final int topicNameLength = bodyDecoder.topicNameLength();
    final int topicNameOffset = bodyDecoder.limit() + topicNameHeaderLength();
    topicName.wrap(buffer, topicNameOffset, topicNameLength);
    // skip topic name in decoder
    bodyDecoder.limit(topicNameOffset + topicNameLength);
    assert bodyDecoder.limit() == frameEnd : "Decoder read only to position " + bodyDecoder.limit() + " but expected " + frameEnd + " as final position";
}
Also used : MembersDecoder(io.zeebe.clustering.management.InvitationRequestDecoder.MembersDecoder) SocketAddress(io.zeebe.transport.SocketAddress) MutableDirectBuffer(org.agrona.MutableDirectBuffer)

Example 32 with MutableDirectBuffer

use of org.agrona.MutableDirectBuffer in project zeebe by zeebe-io.

the class GossipEventCreationHelper method updateMemberWithNewRaftState.

public static void updateMemberWithNewRaftState(MemberRaftComposite memberRaftComposite, DirectBuffer memberRaftStatesBuffer) {
    int offset = 0;
    final int count = memberRaftStatesBuffer.getInt(offset, ByteOrder.LITTLE_ENDIAN);
    offset += SIZE_OF_INT;
    for (int i = 0; i < count; i++) {
        final int partition = memberRaftStatesBuffer.getInt(offset, ByteOrder.LITTLE_ENDIAN);
        offset += SIZE_OF_INT;
        final int topicNameLength = memberRaftStatesBuffer.getInt(offset, ByteOrder.LITTLE_ENDIAN);
        offset += SIZE_OF_INT;
        final MutableDirectBuffer topicBuffer = new UnsafeBuffer(new byte[topicNameLength]);
        memberRaftStatesBuffer.getBytes(offset, topicBuffer, 0, topicNameLength);
        offset += topicNameLength;
        final byte state = memberRaftStatesBuffer.getByte(offset);
        offset += SIZE_OF_BYTE;
        memberRaftComposite.updateRaft(partition, topicBuffer, state == (byte) 1 ? RaftState.LEADER : RaftState.FOLLOWER);
    }
}
Also used : MutableDirectBuffer(org.agrona.MutableDirectBuffer) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer)

Example 33 with MutableDirectBuffer

use of org.agrona.MutableDirectBuffer in project zeebe by zeebe-io.

the class StubResponseChannelHandler method onRequest.

@Override
public boolean onRequest(ServerOutput output, RemoteAddress remoteAddress, DirectBuffer buffer, int offset, int length, long requestId) {
    final MutableDirectBuffer copy = new UnsafeBuffer(new byte[length]);
    copy.putBytes(0, buffer, offset, length);
    headerDecoder.wrap(copy, 0);
    boolean requestHandled = false;
    if (ExecuteCommandRequestDecoder.TEMPLATE_ID == headerDecoder.templateId()) {
        final ExecuteCommandRequest request = new ExecuteCommandRequest(remoteAddress, msgPackHelper);
        request.wrap(copy, 0, length);
        commandRequests.add(request);
        allRequests.add(request);
        requestHandled = handleRequest(output, request, cmdRequestStubs, remoteAddress, requestId);
    } else if (ControlMessageRequestDecoder.TEMPLATE_ID == headerDecoder.templateId()) {
        final ControlMessageRequest request = new ControlMessageRequest(remoteAddress, msgPackHelper);
        request.wrap(copy, 0, length);
        controlMessageRequests.add(request);
        allRequests.add(request);
        requestHandled = handleRequest(output, request, controlMessageStubs, remoteAddress, requestId);
    }
    if (!requestHandled) {
        throw new RuntimeException(String.format("no stub applies to request with schema id %s and template id %s ", headerDecoder.schemaId(), headerDecoder.templateId()));
    } else {
        return true;
    }
}
Also used : MutableDirectBuffer(org.agrona.MutableDirectBuffer) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer)

Example 34 with MutableDirectBuffer

use of org.agrona.MutableDirectBuffer in project aeron by real-logic.

the class EventLogger method logFrameOut.

public void logFrameOut(final ByteBuffer buffer, final InetSocketAddress dstAddress) {
    if (IS_FRAME_OUT_ENABLED) {
        final MutableDirectBuffer encodedBuffer = ENCODING_BUFFER.get();
        final int encodedLength = EventEncoder.encode(encodedBuffer, buffer, buffer.position(), buffer.remaining(), dstAddress);
        ringBuffer.write(EventCode.FRAME_OUT.id(), encodedBuffer, 0, encodedLength);
    }
}
Also used : MutableDirectBuffer(org.agrona.MutableDirectBuffer)

Example 35 with MutableDirectBuffer

use of org.agrona.MutableDirectBuffer in project aeron by real-logic.

the class EventLogger method log.

public void log(final EventCode code, final DirectBuffer buffer, final int offset, final int length) {
    if (EventCode.isEnabled(code, ENABLED_EVENT_CODES)) {
        final MutableDirectBuffer encodedBuffer = ENCODING_BUFFER.get();
        final int encodedLength = EventEncoder.encode(encodedBuffer, buffer, offset, length);
        ringBuffer.write(code.id(), encodedBuffer, 0, encodedLength);
    }
}
Also used : MutableDirectBuffer(org.agrona.MutableDirectBuffer)

Aggregations

MutableDirectBuffer (org.agrona.MutableDirectBuffer)42 UnsafeBuffer (org.agrona.concurrent.UnsafeBuffer)18 BeforeEach (org.junit.jupiter.api.BeforeEach)12 Test (org.junit.jupiter.api.Test)12 DirectBuffer (org.agrona.DirectBuffer)11 MediaDriver (io.aeron.driver.MediaDriver)10 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)10 RegisterExtension (org.junit.jupiter.api.extension.RegisterExtension)10 RegistrationException (io.aeron.exceptions.RegistrationException)8 FragmentHandler (io.aeron.logbuffer.FragmentHandler)8 InterruptAfter (io.aeron.test.InterruptAfter)8 InterruptingTestCallback (io.aeron.test.InterruptingTestCallback)8 SystemTestWatcher (io.aeron.test.SystemTestWatcher)8 Tests (io.aeron.test.Tests)8 TestMediaDriver (io.aeron.test.driver.TestMediaDriver)8 Objects.requireNonNull (java.util.Objects.requireNonNull)8 MutableLong (org.agrona.collections.MutableLong)8 Assertions.assertNotEquals (org.junit.jupiter.api.Assertions.assertNotEquals)8 Assertions.assertThrows (org.junit.jupiter.api.Assertions.assertThrows)8 Assumptions.assumeTrue (org.junit.jupiter.api.Assumptions.assumeTrue)8