Search in sources :

Example 1 with MultiSend

use of org.apache.kafka.common.network.MultiSend in project kafka by apache.

the class FetchResponse method toSend.

public Send toSend(Struct responseStruct, int throttleTimeMs, String dest, RequestHeader requestHeader) {
    Struct responseHeader = new ResponseHeader(requestHeader.correlationId()).toStruct();
    // write the total size and the response header
    ByteBuffer buffer = ByteBuffer.allocate(responseHeader.sizeOf() + 4);
    buffer.putInt(responseHeader.sizeOf() + responseStruct.sizeOf());
    responseHeader.writeTo(buffer);
    buffer.rewind();
    List<Send> sends = new ArrayList<>();
    sends.add(new ByteBufferSend(dest, buffer));
    addResponseData(responseStruct, throttleTimeMs, dest, sends);
    return new MultiSend(dest, sends);
}
Also used : MultiSend(org.apache.kafka.common.network.MultiSend) ByteBufferSend(org.apache.kafka.common.network.ByteBufferSend) ArrayList(java.util.ArrayList) ByteBuffer(java.nio.ByteBuffer) Struct(org.apache.kafka.common.protocol.types.Struct) ByteBufferSend(org.apache.kafka.common.network.ByteBufferSend) MultiSend(org.apache.kafka.common.network.MultiSend) Send(org.apache.kafka.common.network.Send)

Example 2 with MultiSend

use of org.apache.kafka.common.network.MultiSend in project apache-kafka-on-k8s by banzaicloud.

the class FetchResponse method toSend.

@Override
protected Send toSend(String dest, ResponseHeader responseHeader, short apiVersion) {
    Struct responseHeaderStruct = responseHeader.toStruct();
    Struct responseBodyStruct = toStruct(apiVersion);
    // write the total size and the response header
    ByteBuffer buffer = ByteBuffer.allocate(responseHeaderStruct.sizeOf() + 4);
    buffer.putInt(responseHeaderStruct.sizeOf() + responseBodyStruct.sizeOf());
    responseHeaderStruct.writeTo(buffer);
    buffer.rewind();
    Queue<Send> sends = new ArrayDeque<>();
    sends.add(new ByteBufferSend(dest, buffer));
    addResponseData(responseBodyStruct, throttleTimeMs, dest, sends);
    return new MultiSend(dest, sends);
}
Also used : MultiSend(org.apache.kafka.common.network.MultiSend) ByteBufferSend(org.apache.kafka.common.network.ByteBufferSend) ByteBuffer(java.nio.ByteBuffer) ArrayDeque(java.util.ArrayDeque) Struct(org.apache.kafka.common.protocol.types.Struct) MultiSend(org.apache.kafka.common.network.MultiSend) Send(org.apache.kafka.common.network.Send) ByteBufferSend(org.apache.kafka.common.network.ByteBufferSend)

Aggregations

ByteBuffer (java.nio.ByteBuffer)2 ByteBufferSend (org.apache.kafka.common.network.ByteBufferSend)2 MultiSend (org.apache.kafka.common.network.MultiSend)2 Send (org.apache.kafka.common.network.Send)2 Struct (org.apache.kafka.common.protocol.types.Struct)2 ArrayDeque (java.util.ArrayDeque)1 ArrayList (java.util.ArrayList)1