Search in sources :

Example 1 with ByteBufferSend

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

the class FetchResponse method addTopicData.

private static void addTopicData(String dest, List<Send> sends, Struct topicData) {
    String topic = topicData.getString(TOPIC_KEY_NAME);
    Object[] allPartitionData = topicData.getArray(PARTITIONS_KEY_NAME);
    // include the topic header and the count for the number of partitions
    ByteBuffer buffer = ByteBuffer.allocate(Type.STRING.sizeOf(topic) + 4);
    Type.STRING.write(buffer, topic);
    buffer.putInt(allPartitionData.length);
    buffer.rewind();
    sends.add(new ByteBufferSend(dest, buffer));
    for (Object partitionData : allPartitionData) addPartitionData(dest, sends, (Struct) partitionData);
}
Also used : ByteBufferSend(org.apache.kafka.common.network.ByteBufferSend) ByteBuffer(java.nio.ByteBuffer) Struct(org.apache.kafka.common.protocol.types.Struct)

Example 2 with ByteBufferSend

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

the class FetchResponse method addPartitionData.

private static void addPartitionData(String dest, List<Send> sends, Struct partitionData) {
    Struct header = partitionData.getStruct(PARTITION_HEADER_KEY_NAME);
    Records records = partitionData.getRecords(RECORD_SET_KEY_NAME);
    // include the partition header and the size of the record set
    ByteBuffer buffer = ByteBuffer.allocate(header.sizeOf() + 4);
    header.writeTo(buffer);
    buffer.putInt(records.sizeInBytes());
    buffer.rewind();
    sends.add(new ByteBufferSend(dest, buffer));
    // finally the send for the record set itself
    sends.add(new RecordsSend(dest, records));
}
Also used : ByteBufferSend(org.apache.kafka.common.network.ByteBufferSend) Records(org.apache.kafka.common.record.Records) ByteBuffer(java.nio.ByteBuffer) Struct(org.apache.kafka.common.protocol.types.Struct)

Example 3 with ByteBufferSend

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

the class FetchResponse method addResponseData.

private static void addResponseData(Struct struct, int throttleTimeMs, String dest, List<Send> sends) {
    Object[] allTopicData = struct.getArray(RESPONSES_KEY_NAME);
    if (struct.hasField(THROTTLE_TIME_KEY_NAME)) {
        ByteBuffer buffer = ByteBuffer.allocate(8);
        buffer.putInt(throttleTimeMs);
        buffer.putInt(allTopicData.length);
        buffer.rewind();
        sends.add(new ByteBufferSend(dest, buffer));
    } else {
        ByteBuffer buffer = ByteBuffer.allocate(4);
        buffer.putInt(allTopicData.length);
        buffer.rewind();
        sends.add(new ByteBufferSend(dest, buffer));
    }
    for (Object topicData : allTopicData) addTopicData(dest, sends, (Struct) topicData);
}
Also used : ByteBufferSend(org.apache.kafka.common.network.ByteBufferSend) ByteBuffer(java.nio.ByteBuffer) Struct(org.apache.kafka.common.protocol.types.Struct)

Example 4 with ByteBufferSend

use of org.apache.kafka.common.network.ByteBufferSend 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)

Aggregations

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