Search in sources :

Example 21 with Struct

use of org.apache.kafka.common.protocol.types.Struct in project kafka by apache.

the class ProduceRequest method toStruct.

/**
     * Visible for testing.
     */
@Override
public Struct toStruct() {
    // Store it in a local variable to protect against concurrent updates
    Map<TopicPartition, MemoryRecords> partitionRecords = partitionRecordsOrFail();
    Struct struct = new Struct(ApiKeys.PRODUCE.requestSchema(version()));
    Map<String, Map<Integer, MemoryRecords>> recordsByTopic = CollectionUtils.groupDataByTopic(partitionRecords);
    struct.set(ACKS_KEY_NAME, acks);
    struct.set(TIMEOUT_KEY_NAME, timeout);
    List<Struct> topicDatas = new ArrayList<>(recordsByTopic.size());
    for (Map.Entry<String, Map<Integer, MemoryRecords>> entry : recordsByTopic.entrySet()) {
        Struct topicData = struct.instance(TOPIC_DATA_KEY_NAME);
        topicData.set(TOPIC_KEY_NAME, entry.getKey());
        List<Struct> partitionArray = new ArrayList<>();
        for (Map.Entry<Integer, MemoryRecords> partitionEntry : entry.getValue().entrySet()) {
            MemoryRecords records = partitionEntry.getValue();
            Struct part = topicData.instance(PARTITION_DATA_KEY_NAME).set(PARTITION_KEY_NAME, partitionEntry.getKey()).set(RECORD_SET_KEY_NAME, records);
            partitionArray.add(part);
        }
        topicData.set(PARTITION_DATA_KEY_NAME, partitionArray.toArray());
        topicDatas.add(topicData);
    }
    struct.set(TOPIC_DATA_KEY_NAME, topicDatas.toArray());
    return struct;
}
Also used : TopicPartition(org.apache.kafka.common.TopicPartition) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) Map(java.util.Map) MemoryRecords(org.apache.kafka.common.record.MemoryRecords) Struct(org.apache.kafka.common.protocol.types.Struct)

Example 22 with Struct

use of org.apache.kafka.common.protocol.types.Struct in project kafka by apache.

the class RequestHeader method toStruct.

public Struct toStruct() {
    Struct struct = new Struct(Protocol.REQUEST_HEADER);
    struct.set(API_KEY_FIELD, apiKey);
    struct.set(API_VERSION_FIELD, apiVersion);
    struct.set(CLIENT_ID_FIELD, clientId);
    struct.set(CORRELATION_ID_FIELD, correlationId);
    return struct;
}
Also used : Struct(org.apache.kafka.common.protocol.types.Struct)

Example 23 with Struct

use of org.apache.kafka.common.protocol.types.Struct in project kafka by apache.

the class ResponseHeader method toStruct.

public Struct toStruct() {
    Struct struct = new Struct(Protocol.RESPONSE_HEADER);
    struct.set(CORRELATION_KEY_FIELD, correlationId);
    return struct;
}
Also used : Struct(org.apache.kafka.common.protocol.types.Struct)

Example 24 with Struct

use of org.apache.kafka.common.protocol.types.Struct in project kafka by apache.

the class SaslHandshakeRequest method toStruct.

@Override
protected Struct toStruct() {
    Struct struct = new Struct(ApiKeys.SASL_HANDSHAKE.requestSchema(version()));
    struct.set(MECHANISM_KEY_NAME, mechanism);
    return struct;
}
Also used : Struct(org.apache.kafka.common.protocol.types.Struct)

Example 25 with Struct

use of org.apache.kafka.common.protocol.types.Struct in project kafka by apache.

the class StopReplicaRequest method toStruct.

@Override
protected Struct toStruct() {
    Struct struct = new Struct(ApiKeys.STOP_REPLICA.requestSchema(version()));
    struct.set(CONTROLLER_ID_KEY_NAME, controllerId);
    struct.set(CONTROLLER_EPOCH_KEY_NAME, controllerEpoch);
    struct.set(DELETE_PARTITIONS_KEY_NAME, deletePartitions);
    List<Struct> partitionDatas = new ArrayList<>(partitions.size());
    for (TopicPartition partition : partitions) {
        Struct partitionData = struct.instance(PARTITIONS_KEY_NAME);
        partitionData.set(TOPIC_KEY_NAME, partition.topic());
        partitionData.set(PARTITION_KEY_NAME, partition.partition());
        partitionDatas.add(partitionData);
    }
    struct.set(PARTITIONS_KEY_NAME, partitionDatas.toArray());
    return struct;
}
Also used : TopicPartition(org.apache.kafka.common.TopicPartition) ArrayList(java.util.ArrayList) Struct(org.apache.kafka.common.protocol.types.Struct)

Aggregations

Struct (org.apache.kafka.common.protocol.types.Struct)63 ArrayList (java.util.ArrayList)32 Map (java.util.Map)22 HashMap (java.util.HashMap)19 ByteBuffer (java.nio.ByteBuffer)18 TopicPartition (org.apache.kafka.common.TopicPartition)10 Test (org.junit.Test)5 List (java.util.List)4 ByteBufferSend (org.apache.kafka.common.network.ByteBufferSend)4 Errors (org.apache.kafka.common.protocol.Errors)4 LinkedHashMap (java.util.LinkedHashMap)3 Node (org.apache.kafka.common.Node)2 Send (org.apache.kafka.common.network.Send)2 ApiKeys (org.apache.kafka.common.protocol.ApiKeys)2 ArrayOf (org.apache.kafka.common.protocol.types.ArrayOf)2 Field (org.apache.kafka.common.protocol.types.Field)2 Schema (org.apache.kafka.common.protocol.types.Schema)2 ResponseHeader (org.apache.kafka.common.requests.ResponseHeader)2 Subscription (org.apache.kafka.clients.consumer.internals.PartitionAssignor.Subscription)1 MultiSend (org.apache.kafka.common.network.MultiSend)1