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";
}
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);
}
}
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;
}
}
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);
}
}
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);
}
}
Aggregations