Search in sources :

Example 16 with Struct

use of org.apache.kafka.common.protocol.types.Struct 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 17 with Struct

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

the class GroupCoordinatorRequest method toStruct.

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

Example 18 with Struct

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

the class ApiVersionsResponse method toStruct.

@Override
protected Struct toStruct(short version) {
    Struct struct = new Struct(ApiKeys.API_VERSIONS.responseSchema(version));
    struct.set(ERROR_CODE_KEY_NAME, error.code());
    List<Struct> apiVersionList = new ArrayList<>();
    for (ApiVersion apiVersion : apiKeyToApiVersion.values()) {
        Struct apiVersionStruct = struct.instance(API_VERSIONS_KEY_NAME);
        apiVersionStruct.set(API_KEY_NAME, apiVersion.apiKey);
        apiVersionStruct.set(MIN_VERSION_KEY_NAME, apiVersion.minVersion);
        apiVersionStruct.set(MAX_VERSION_KEY_NAME, apiVersion.maxVersion);
        apiVersionList.add(apiVersionStruct);
    }
    struct.set(API_VERSIONS_KEY_NAME, apiVersionList.toArray());
    return struct;
}
Also used : ArrayList(java.util.ArrayList) Struct(org.apache.kafka.common.protocol.types.Struct)

Example 19 with Struct

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

the class ControlledShutdownRequest method toStruct.

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

Example 20 with Struct

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

the class ControlledShutdownResponse method toStruct.

@Override
protected Struct toStruct(short version) {
    Struct struct = new Struct(ApiKeys.CONTROLLED_SHUTDOWN_KEY.responseSchema(version));
    struct.set(ERROR_CODE_KEY_NAME, error.code());
    List<Struct> partitionsRemainingList = new ArrayList<>(partitionsRemaining.size());
    for (TopicPartition topicPartition : partitionsRemaining) {
        Struct topicPartitionStruct = struct.instance(PARTITIONS_REMAINING_KEY_NAME);
        topicPartitionStruct.set(TOPIC_KEY_NAME, topicPartition.topic());
        topicPartitionStruct.set(PARTITION_KEY_NAME, topicPartition.partition());
        partitionsRemainingList.add(topicPartitionStruct);
    }
    struct.set(PARTITIONS_REMAINING_KEY_NAME, partitionsRemainingList.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