Search in sources :

Example 51 with Struct

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

the class GroupCoordinatorResponse method toStruct.

@Override
protected Struct toStruct(short version) {
    Struct struct = new Struct(ApiKeys.GROUP_COORDINATOR.responseSchema(version));
    struct.set(ERROR_CODE_KEY_NAME, error.code());
    Struct coordinator = struct.instance(COORDINATOR_KEY_NAME);
    coordinator.set(NODE_ID_KEY_NAME, node.id());
    coordinator.set(HOST_KEY_NAME, node.host());
    coordinator.set(PORT_KEY_NAME, node.port());
    struct.set(COORDINATOR_KEY_NAME, coordinator);
    return struct;
}
Also used : Struct(org.apache.kafka.common.protocol.types.Struct)

Example 52 with Struct

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

the class HeartbeatRequest method toStruct.

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

Example 53 with Struct

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

the class HeartbeatResponse method toStruct.

@Override
protected Struct toStruct(short version) {
    Struct struct = new Struct(ApiKeys.HEARTBEAT.responseSchema(version));
    struct.set(ERROR_CODE_KEY_NAME, error.code());
    return struct;
}
Also used : Struct(org.apache.kafka.common.protocol.types.Struct)

Example 54 with Struct

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

the class JoinGroupRequest method toStruct.

@Override
protected Struct toStruct() {
    short version = version();
    Struct struct = new Struct(ApiKeys.JOIN_GROUP.requestSchema(version));
    struct.set(GROUP_ID_KEY_NAME, groupId);
    struct.set(SESSION_TIMEOUT_KEY_NAME, sessionTimeout);
    if (version >= 1) {
        struct.set(REBALANCE_TIMEOUT_KEY_NAME, rebalanceTimeout);
    }
    struct.set(MEMBER_ID_KEY_NAME, memberId);
    struct.set(PROTOCOL_TYPE_KEY_NAME, protocolType);
    List<Struct> groupProtocolsList = new ArrayList<>(groupProtocols.size());
    for (ProtocolMetadata protocol : groupProtocols) {
        Struct protocolStruct = struct.instance(GROUP_PROTOCOLS_KEY_NAME);
        protocolStruct.set(PROTOCOL_NAME_KEY_NAME, protocol.name);
        protocolStruct.set(PROTOCOL_METADATA_KEY_NAME, protocol.metadata);
        groupProtocolsList.add(protocolStruct);
    }
    struct.set(GROUP_PROTOCOLS_KEY_NAME, groupProtocolsList.toArray());
    return struct;
}
Also used : ArrayList(java.util.ArrayList) Struct(org.apache.kafka.common.protocol.types.Struct)

Example 55 with Struct

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

the class JoinGroupResponse method toStruct.

@Override
protected Struct toStruct(short version) {
    Struct struct = new Struct(ApiKeys.JOIN_GROUP.responseSchema(version));
    struct.set(ERROR_CODE_KEY_NAME, error.code());
    struct.set(GENERATION_ID_KEY_NAME, generationId);
    struct.set(GROUP_PROTOCOL_KEY_NAME, groupProtocol);
    struct.set(MEMBER_ID_KEY_NAME, memberId);
    struct.set(LEADER_ID_KEY_NAME, leaderId);
    List<Struct> memberArray = new ArrayList<>();
    for (Map.Entry<String, ByteBuffer> entries : members.entrySet()) {
        Struct memberData = struct.instance(MEMBERS_KEY_NAME);
        memberData.set(MEMBER_ID_KEY_NAME, entries.getKey());
        memberData.set(MEMBER_METADATA_KEY_NAME, entries.getValue());
        memberArray.add(memberData);
    }
    struct.set(MEMBERS_KEY_NAME, memberArray.toArray());
    return struct;
}
Also used : ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) ByteBuffer(java.nio.ByteBuffer) 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