Search in sources :

Example 61 with Struct

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

the class ConnectProtocol method deserializeMetadata.

public static WorkerState deserializeMetadata(ByteBuffer buffer) {
    Struct header = CONNECT_PROTOCOL_HEADER_SCHEMA.read(buffer);
    Short version = header.getShort(VERSION_KEY_NAME);
    checkVersionCompatibility(version);
    Struct struct = CONFIG_STATE_V0.read(buffer);
    long configOffset = struct.getLong(CONFIG_OFFSET_KEY_NAME);
    String url = struct.getString(URL_KEY_NAME);
    return new WorkerState(url, configOffset);
}
Also used : Struct(org.apache.kafka.common.protocol.types.Struct)

Example 62 with Struct

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

the class ConnectProtocol method deserializeAssignment.

public static Assignment deserializeAssignment(ByteBuffer buffer) {
    Struct header = CONNECT_PROTOCOL_HEADER_SCHEMA.read(buffer);
    Short version = header.getShort(VERSION_KEY_NAME);
    checkVersionCompatibility(version);
    Struct struct = ASSIGNMENT_V0.read(buffer);
    short error = struct.getShort(ERROR_KEY_NAME);
    String leader = struct.getString(LEADER_KEY_NAME);
    String leaderUrl = struct.getString(LEADER_URL_KEY_NAME);
    long offset = struct.getLong(CONFIG_OFFSET_KEY_NAME);
    List<String> connectorIds = new ArrayList<>();
    List<ConnectorTaskId> taskIds = new ArrayList<>();
    for (Object structObj : struct.getArray(ASSIGNMENT_KEY_NAME)) {
        Struct assignment = (Struct) structObj;
        String connector = assignment.getString(CONNECTOR_KEY_NAME);
        for (Object taskIdObj : assignment.getArray(TASKS_KEY_NAME)) {
            Integer taskId = (Integer) taskIdObj;
            if (taskId == CONNECTOR_TASK)
                connectorIds.add(connector);
            else
                taskIds.add(new ConnectorTaskId(connector, taskId));
        }
    }
    return new Assignment(error, leader, leaderUrl, offset, connectorIds, taskIds);
}
Also used : ConnectorTaskId(org.apache.kafka.connect.util.ConnectorTaskId) ArrayList(java.util.ArrayList) Struct(org.apache.kafka.common.protocol.types.Struct)

Example 63 with Struct

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

the class ConsumerProtocol method serializeSubscription.

public static ByteBuffer serializeSubscription(PartitionAssignor.Subscription subscription) {
    Struct struct = new Struct(SUBSCRIPTION_V0);
    struct.set(USER_DATA_KEY_NAME, subscription.userData());
    struct.set(TOPICS_KEY_NAME, subscription.topics().toArray());
    ByteBuffer buffer = ByteBuffer.allocate(CONSUMER_PROTOCOL_HEADER_V0.sizeOf() + SUBSCRIPTION_V0.sizeOf(struct));
    CONSUMER_PROTOCOL_HEADER_V0.writeTo(buffer);
    SUBSCRIPTION_V0.write(buffer, struct);
    buffer.flip();
    return buffer;
}
Also used : 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