Package org.apache.kafka.common.protocol.types

Examples of org.apache.kafka.common.protocol.types.Struct


    public ListOffsetResponse(Struct struct) {
        super(struct);
        responseData = new HashMap<TopicPartition, PartitionData>();
        for (Object topicResponseObj : struct.getArray(RESPONSES_KEY_NAME)) {
            Struct topicResponse = (Struct) topicResponseObj;
            String topic = topicResponse.getString(TOPIC_KEY_NAME);
            for (Object partitionResponseObj : topicResponse.getArray(PARTITIONS_KEY_NAME)) {
                Struct partitionResponse = (Struct) partitionResponseObj;
                int partition = partitionResponse.getInt(PARTITION_KEY_NAME);
                short errorCode = partitionResponse.getShort(ERROR_CODE_KEY_NAME);
                Object[] offsets = partitionResponse.getArray(OFFSETS_KEY_NAME);
                List<Long> offsetsList = new ArrayList<Long>();
                for (Object offset: offsets)
                    offsetsList.add((Long) offset);
                PartitionData partitionData = new PartitionData(errorCode, offsetsList);
                responseData.put(new TopicPartition(topic, partition), partitionData);
View Full Code Here


        for (NetworkReceive receive : this.selector.completedReceives()) {
            int source = receive.source();
            ClientRequest req = inFlightRequests.completeNext(source);
            ResponseHeader header = ResponseHeader.parse(receive.payload());
            short apiKey = req.request().header().apiKey();
            Struct body = (Struct) ProtoUtils.currentResponseSchema(apiKey).read(receive.payload());
            correlate(req.request().header(), header);
            if (apiKey == ApiKeys.METADATA.id) {
                handleMetadataResponse(req.request().header(), body, now);
            } else {
                // need to add body/header to response here
View Full Code Here

                                 new Field("int64", Type.INT64),
                                 new Field("string", Type.STRING),
                                 new Field("bytes", Type.BYTES),
                                 new Field("array", new ArrayOf(Type.INT32)),
                                 new Field("struct", new Schema(new Field("field", Type.INT32))));
        this.struct = new Struct(this.schema).set("int8", (byte) 1)
                                             .set("int16", (short) 1)
                                             .set("int32", (int) 1)
                                             .set("int64", (long) 1)
                                             .set("string", "1")
                                             .set("bytes", "1".getBytes())
View Full Code Here

    }

    @Test
    public void testDefault() {
        Schema schema = new Schema(new Field("field", Type.INT32, "doc", 42));
        Struct struct = new Struct(schema);
        assertEquals("Should get the default value", 42, struct.get("field"));
        struct.validate(); // should be valid even with missing value
    }
View Full Code Here

    public RequestHeader(short apiKey, String client, int correlation) {
        this(apiKey, ProtoUtils.latestVersion(apiKey), client, correlation);
    }

    public RequestHeader(short apiKey, short version, String client, int correlation) {
        super(new Struct(Protocol.REQUEST_HEADER));
        struct.set(API_KEY_FIELD, apiKey);
        struct.set(API_VERSION_FIELD, version);
        struct.set(CLIENT_ID_FIELD, client);
        struct.set(CORRELATION_ID_FIELD, correlation);
        this.apiKey = apiKey;
View Full Code Here

    private static String TOPICS_KEY_NAME = "topics";

    private final List<String> topics;

    public MetadataRequest(List<String> topics) {
        super(new Struct(curSchema));
        struct.set(TOPICS_KEY_NAME, topics.toArray());
        this.topics = topics;
    }
View Full Code Here

            this.recordSet = recordSet;
        }
    }

    public FetchResponse(Map<TopicPartition, PartitionData> responseData) {
        super(new Struct(curSchema));
        Map<String, Map<Integer, PartitionData>> topicsData = CollectionUtils.groupDataByTopic(responseData);

        List<Struct> topicArray = new ArrayList<Struct>();
        for (Map.Entry<String, Map<Integer, PartitionData>> topicEntry: topicsData.entrySet()) {
            Struct topicData = struct.instance(RESPONSES_KEY_NAME);
            topicData.set(TOPIC_KEY_NAME, topicEntry.getKey());
            List<Struct> partitionArray = new ArrayList<Struct>();
            for (Map.Entry<Integer, PartitionData> partitionEntry : topicEntry.getValue().entrySet()) {
                PartitionData fetchPartitionData = partitionEntry.getValue();
                Struct partitionData = topicData.instance(PARTITIONS_KEY_NAME);
                partitionData.set(PARTITION_KEY_NAME, partitionEntry.getKey());
                partitionData.set(ERROR_CODE_KEY_NAME, fetchPartitionData.errorCode);
                partitionData.set(HIGH_WATERMARK_KEY_NAME, fetchPartitionData.highWatermark);
                partitionData.set(RECORD_SET_KEY_NAME, fetchPartitionData.recordSet);
                partitionArray.add(partitionData);
            }
            topicData.set(PARTITIONS_KEY_NAME, partitionArray.toArray());
            topicArray.add(topicData);
        }
View Full Code Here

    public FetchResponse(Struct struct) {
        super(struct);
        responseData = new HashMap<TopicPartition, PartitionData>();
        for (Object topicResponseObj : struct.getArray(RESPONSES_KEY_NAME)) {
            Struct topicResponse = (Struct) topicResponseObj;
            String topic = topicResponse.getString(TOPIC_KEY_NAME);
            for (Object partitionResponseObj : topicResponse.getArray(PARTITIONS_KEY_NAME)) {
                Struct partitionResponse = (Struct) partitionResponseObj;
                int partition = partitionResponse.getInt(PARTITION_KEY_NAME);
                short errorCode = partitionResponse.getShort(ERROR_CODE_KEY_NAME);
                long highWatermark = partitionResponse.getLong(HIGH_WATERMARK_KEY_NAME);
                ByteBuffer recordSet = partitionResponse.getBytes(RECORD_SET_KEY_NAME);
                PartitionData partitionData = new PartitionData(errorCode, highWatermark, recordSet);
                responseData.put(new TopicPartition(topic, partition), partitionData);
            }
        }
    }
View Full Code Here

    private final int generationId;
    private final String consumerId;
    private final List<TopicPartition> assignedPartitions;

    public JoinGroupResponse(short errorCode, int generationId, String consumerId, List<TopicPartition> assignedPartitions) {
        super(new Struct(curSchema));

        Map<String, List<Integer>> partitionsByTopic = CollectionUtils.groupDataByTopic(assignedPartitions);

        struct.set(ERROR_CODE_KEY_NAME, errorCode);
        struct.set(GENERATION_ID_KEY_NAME, generationId);
        struct.set(CONSUMER_ID_KEY_NAME, consumerId);
        List<Struct> topicArray = new ArrayList<Struct>();
        for (Map.Entry<String, List<Integer>> entries: partitionsByTopic.entrySet()) {
            Struct topicData = struct.instance(ASSIGNED_PARTITIONS_KEY_NAME);
            topicData.set(TOPIC_KEY_NAME, entries.getKey());
            topicData.set(PARTITIONS_KEY_NAME, entries.getValue().toArray());
            topicArray.add(topicData);
        }
        struct.set(ASSIGNED_PARTITIONS_KEY_NAME, topicArray.toArray());

        this.errorCode = errorCode;
View Full Code Here

    public JoinGroupResponse(Struct struct) {
        super(struct);
        assignedPartitions = new ArrayList<TopicPartition>();
        for (Object topicDataObj : struct.getArray(ASSIGNED_PARTITIONS_KEY_NAME)) {
            Struct topicData = (Struct) topicDataObj;
            String topic = topicData.getString(TOPIC_KEY_NAME);
            for (Object partitionObj : topicData.getArray(PARTITIONS_KEY_NAME))
                assignedPartitions.add(new TopicPartition(topic, (Integer) partitionObj));
        }
        errorCode = struct.getShort(ERROR_CODE_KEY_NAME);
        generationId = struct.getInt(GENERATION_ID_KEY_NAME);
        consumerId = struct.getString(CONSUMER_ID_KEY_NAME);
View Full Code Here

TOP

Related Classes of org.apache.kafka.common.protocol.types.Struct

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.