当前位置: 首页>>代码示例>>Java>>正文


Java ApiKeys类代码示例

本文整理汇总了Java中org.apache.kafka.common.protocol.ApiKeys的典型用法代码示例。如果您正苦于以下问题:Java ApiKeys类的具体用法?Java ApiKeys怎么用?Java ApiKeys使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ApiKeys类属于org.apache.kafka.common.protocol包,在下文中一共展示了ApiKeys类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: disconnect

import org.apache.kafka.common.protocol.ApiKeys; //导入依赖的package包/类
/**
 * Disconnects the connection to a particular node, if there is one.
 * Any pending ClientRequests for this connection will receive disconnections.
 *
 * @param nodeId The id of the node
 */
@Override
public void disconnect(String nodeId) {
    selector.close(nodeId);
    List<ApiKeys> requestTypes = new ArrayList<>();
    long now = time.milliseconds();
    for (InFlightRequest request : inFlightRequests.clearAll(nodeId)) {
        if (request.isInternalRequest) {
            if (request.header.apiKey() == ApiKeys.METADATA.id) {
                metadataUpdater.handleDisconnection(request.destination);
            }
        } else {
            requestTypes.add(ApiKeys.forId(request.header.apiKey()));
            abortedSends.add(new ClientResponse(request.header,
                    request.callback, request.destination, request.createdTimeMs, now,
                    true, null, null));
        }
    }
    connectionStates.disconnected(nodeId, now);
    if (log.isDebugEnabled()) {
        log.debug("Manually disconnected from {}.  Removed requests: {}.", nodeId,
            Utils.join(requestTypes, ", "));
    }
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:30,代码来源:NetworkClient.java

示例2: toStruct

import org.apache.kafka.common.protocol.ApiKeys; //导入依赖的package包/类
@Override
protected Struct toStruct(short version) {
    Struct struct = new Struct(ApiKeys.JOIN_GROUP.responseSchema(version));
    if (struct.hasField(THROTTLE_TIME_KEY_NAME))
        struct.set(THROTTLE_TIME_KEY_NAME, throttleTimeMs);

    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;
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:24,代码来源:JoinGroupResponse.java

示例3: toStruct

import org.apache.kafka.common.protocol.ApiKeys; //导入依赖的package包/类
@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;
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:22,代码来源:JoinGroupRequest.java

示例4: getErrorResponse

import org.apache.kafka.common.protocol.ApiKeys; //导入依赖的package包/类
@Override
public DescribeConfigsResponse getErrorResponse(int throttleTimeMs, Throwable e) {
    short version = version();
    switch (version) {
        case 0:
            ApiError error = ApiError.fromThrowable(e);
            Map<Resource, DescribeConfigsResponse.Config> errors = new HashMap<>(resources().size());
            DescribeConfigsResponse.Config config = new DescribeConfigsResponse.Config(error,
                    Collections.<DescribeConfigsResponse.ConfigEntry>emptyList());
            for (Resource resource : resources())
                errors.put(resource, config);
            return new DescribeConfigsResponse(throttleTimeMs, errors);
        default:
            throw new IllegalArgumentException(String.format("Version %d is not valid. Valid versions for %s are 0 to %d",
                    version, this.getClass().getSimpleName(), ApiKeys.DESCRIBE_CONFIGS.latestVersion()));
    }
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:18,代码来源:DescribeConfigsRequest.java

示例5: getErrorResponse

import org.apache.kafka.common.protocol.ApiKeys; //导入依赖的package包/类
@Override
public AbstractResponse getErrorResponse(int throttleTimeMs, Throwable e) {
    Map<TopicPartition, DeleteRecordsResponse.PartitionResponse> responseMap = new HashMap<>();

    for (Map.Entry<TopicPartition, Long> entry : partitionOffsets.entrySet()) {
        responseMap.put(entry.getKey(), new DeleteRecordsResponse.PartitionResponse(DeleteRecordsResponse.INVALID_LOW_WATERMARK, Errors.forException(e)));
    }

    short versionId = version();
    switch (versionId) {
        case 0:
            return new DeleteRecordsResponse(throttleTimeMs, responseMap);
        default:
            throw new IllegalArgumentException(String.format("Version %d is not valid. Valid versions for %s are 0 to %d",
                versionId, this.getClass().getSimpleName(), ApiKeys.DELETE_RECORDS.latestVersion()));
    }
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:18,代码来源:DeleteRecordsRequest.java

示例6: toStruct

import org.apache.kafka.common.protocol.ApiKeys; //导入依赖的package包/类
@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;
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:18,代码来源:ControlledShutdownResponse.java

示例7: toStruct

import org.apache.kafka.common.protocol.ApiKeys; //导入依赖的package包/类
@Override
protected Struct toStruct(short version) {
    Struct struct = new Struct(ApiKeys.LEADER_AND_ISR.responseSchema(version));

    List<Struct> responseDatas = new ArrayList<>(responses.size());
    for (Map.Entry<TopicPartition, Errors> response : responses.entrySet()) {
        Struct partitionData = struct.instance(PARTITIONS_KEY_NAME);
        TopicPartition partition = response.getKey();
        partitionData.set(PARTITIONS_TOPIC_KEY_NAME, partition.topic());
        partitionData.set(PARTITIONS_PARTITION_KEY_NAME, partition.partition());
        partitionData.set(PARTITIONS_ERROR_CODE_KEY_NAME, response.getValue().code());
        responseDatas.add(partitionData);
    }

    struct.set(PARTITIONS_KEY_NAME, responseDatas.toArray());
    struct.set(ERROR_CODE_KEY_NAME, error.code());

    return struct;
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:20,代码来源:LeaderAndIsrResponse.java

示例8: getErrorResponse

import org.apache.kafka.common.protocol.ApiKeys; //导入依赖的package包/类
@Override
public AbstractResponse getErrorResponse(int throttleTimeMs, Throwable e) {
    Map<TopicPartition, Errors> responses = new HashMap<>(partitions.size());
    for (TopicPartition partition : partitions) {
        responses.put(partition, Errors.forException(e));
    }

    short versionId = version();
    switch (versionId) {
        case 0:
            return new StopReplicaResponse(Errors.NONE, responses);
        default:
            throw new IllegalArgumentException(String.format("Version %d is not valid. Valid versions for %s are 0 to %d",
                    versionId, this.getClass().getSimpleName(), ApiKeys.STOP_REPLICA.latestVersion()));
    }
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:17,代码来源:StopReplicaRequest.java

示例9: toStruct

import org.apache.kafka.common.protocol.ApiKeys; //导入依赖的package包/类
@Override
protected Struct toStruct() {
    Struct struct = new Struct(ApiKeys.OFFSET_FETCH.requestSchema(version()));
    struct.set(GROUP_ID_KEY_NAME, groupId);
    if (partitions != null) {
        Map<String, List<Integer>> topicsData = CollectionUtils.groupDataByTopic(partitions);

        List<Struct> topicArray = new ArrayList<>();
        for (Map.Entry<String, List<Integer>> entries : topicsData.entrySet()) {
            Struct topicData = struct.instance(TOPICS_KEY_NAME);
            topicData.set(TOPIC_KEY_NAME, entries.getKey());
            List<Struct> partitionArray = new ArrayList<>();
            for (Integer partitionId : entries.getValue()) {
                Struct partitionData = topicData.instance(PARTITIONS_KEY_NAME);
                partitionData.set(PARTITION_KEY_NAME, partitionId);
                partitionArray.add(partitionData);
            }
            topicData.set(PARTITIONS_KEY_NAME, partitionArray.toArray());
            topicArray.add(topicData);
        }
        struct.set(TOPICS_KEY_NAME, topicArray.toArray());
    } else
        struct.set(TOPICS_KEY_NAME, null);

    return struct;
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:27,代码来源:OffsetFetchRequest.java

示例10: getErrorResponse

import org.apache.kafka.common.protocol.ApiKeys; //导入依赖的package包/类
@Override
public AbstractResponse getErrorResponse(int throttleTimeMs, Throwable e) {
    List<MetadataResponse.TopicMetadata> topicMetadatas = new ArrayList<>();
    Errors error = Errors.forException(e);
    List<MetadataResponse.PartitionMetadata> partitions = Collections.emptyList();

    if (topics != null) {
        for (String topic : topics)
            topicMetadatas.add(new MetadataResponse.TopicMetadata(error, topic, false, partitions));
    }

    short versionId = version();
    switch (versionId) {
        case 0:
        case 1:
        case 2:
            return new MetadataResponse(Collections.<Node>emptyList(), null, MetadataResponse.NO_CONTROLLER_ID, topicMetadatas);
        case 3:
        case 4:
            return new MetadataResponse(throttleTimeMs, Collections.<Node>emptyList(), null, MetadataResponse.NO_CONTROLLER_ID, topicMetadatas);
        default:
            throw new IllegalArgumentException(String.format("Version %d is not valid. Valid versions for %s are 0 to %d",
                    versionId, this.getClass().getSimpleName(), ApiKeys.METADATA.latestVersion()));
    }
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:26,代码来源:MetadataRequest.java

示例11: getErrorResponse

import org.apache.kafka.common.protocol.ApiKeys; //导入依赖的package包/类
@Override
public AbstractResponse getErrorResponse(int throttleTimeMs, Throwable e) {
    short versionId = version();
    switch (versionId) {
        case 0:
            return new SyncGroupResponse(
                    Errors.forException(e),
                    ByteBuffer.wrap(new byte[]{}));
        case 1:
            return new SyncGroupResponse(
                    throttleTimeMs,
                    Errors.forException(e),
                    ByteBuffer.wrap(new byte[]{}));
        default:
            throw new IllegalArgumentException(String.format("Version %d is not valid. Valid versions for %s are 0 to %d",
                    versionId, this.getClass().getSimpleName(), ApiKeys.SYNC_GROUP.latestVersion()));
    }
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:19,代码来源:SyncGroupRequest.java

示例12: toStruct

import org.apache.kafka.common.protocol.ApiKeys; //导入依赖的package包/类
@Override
protected Struct toStruct() {
    Struct struct = new Struct(ApiKeys.SYNC_GROUP.requestSchema(version()));
    struct.set(GROUP_ID_KEY_NAME, groupId);
    struct.set(GENERATION_ID_KEY_NAME, generationId);
    struct.set(MEMBER_ID_KEY_NAME, memberId);

    List<Struct> memberArray = new ArrayList<>();
    for (Map.Entry<String, ByteBuffer> entries: groupAssignment.entrySet()) {
        Struct memberData = struct.instance(GROUP_ASSIGNMENT_KEY_NAME);
        memberData.set(MEMBER_ID_KEY_NAME, entries.getKey());
        memberData.set(MEMBER_ASSIGNMENT_KEY_NAME, entries.getValue());
        memberArray.add(memberData);
    }
    struct.set(GROUP_ASSIGNMENT_KEY_NAME, memberArray.toArray());
    return struct;
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:18,代码来源:SyncGroupRequest.java

示例13: getErrorResponse

import org.apache.kafka.common.protocol.ApiKeys; //导入依赖的package包/类
@Override
public ProduceResponse getErrorResponse(int throttleTimeMs, Throwable e) {
    /* In case the producer doesn't actually want any response */
    if (acks == 0)
        return null;

    Errors error = Errors.forException(e);
    Map<TopicPartition, ProduceResponse.PartitionResponse> responseMap = new HashMap<>();
    ProduceResponse.PartitionResponse partitionResponse = new ProduceResponse.PartitionResponse(error);

    for (TopicPartition tp : partitions())
        responseMap.put(tp, partitionResponse);

    short versionId = version();
    switch (versionId) {
        case 0:
        case 1:
        case 2:
        case 3:
            return new ProduceResponse(responseMap, throttleTimeMs);
        default:
            throw new IllegalArgumentException(String.format("Version %d is not valid. Valid versions for %s are 0 to %d",
                    versionId, this.getClass().getSimpleName(), ApiKeys.PRODUCE.latestVersion()));
    }
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:26,代码来源:ProduceRequest.java

示例14: toStruct

import org.apache.kafka.common.protocol.ApiKeys; //导入依赖的package包/类
@Override
public Struct toStruct(short version) {
    Struct struct = new Struct(ApiKeys.OFFSET_COMMIT.responseSchema(version));
    if (struct.hasField(THROTTLE_TIME_KEY_NAME))
        struct.set(THROTTLE_TIME_KEY_NAME, throttleTimeMs);

    Map<String, Map<Integer, Errors>> topicsData = CollectionUtils.groupDataByTopic(responseData);
    List<Struct> topicArray = new ArrayList<>();
    for (Map.Entry<String, Map<Integer, Errors>> entries: topicsData.entrySet()) {
        Struct topicData = struct.instance(RESPONSES_KEY_NAME);
        topicData.set(TOPIC_KEY_NAME, entries.getKey());
        List<Struct> partitionArray = new ArrayList<>();
        for (Map.Entry<Integer, Errors> partitionEntry : entries.getValue().entrySet()) {
            Struct partitionData = topicData.instance(PARTITIONS_KEY_NAME);
            partitionData.set(PARTITION_KEY_NAME, partitionEntry.getKey());
            partitionData.set(ERROR_CODE_KEY_NAME, partitionEntry.getValue().code());
            partitionArray.add(partitionData);
        }
        topicData.set(PARTITIONS_KEY_NAME, partitionArray.toArray());
        topicArray.add(topicData);
    }
    struct.set(RESPONSES_KEY_NAME, topicArray.toArray());

    return struct;
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:26,代码来源:OffsetCommitResponse.java

示例15: produceRequestToStringTest

import org.apache.kafka.common.protocol.ApiKeys; //导入依赖的package包/类
@Test
public void produceRequestToStringTest() {
    ProduceRequest request = createProduceRequest(ApiKeys.PRODUCE.latestVersion());
    assertEquals(1, request.partitionRecordsOrFail().size());
    assertFalse(request.toString(false).contains("partitionSizes"));
    assertTrue(request.toString(false).contains("numPartitions=1"));
    assertTrue(request.toString(true).contains("partitionSizes"));
    assertFalse(request.toString(true).contains("numPartitions"));

    request.clearPartitionRecords();
    try {
        request.partitionRecordsOrFail();
        fail("partitionRecordsOrFail should fail after clearPartitionRecords()");
    } catch (IllegalStateException e) {
        // OK
    }

    // `toString` should behave the same after `clearPartitionRecords`
    assertFalse(request.toString(false).contains("partitionSizes"));
    assertTrue(request.toString(false).contains("numPartitions=1"));
    assertTrue(request.toString(true).contains("partitionSizes"));
    assertFalse(request.toString(true).contains("numPartitions"));
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:24,代码来源:RequestResponseTest.java


注:本文中的org.apache.kafka.common.protocol.ApiKeys类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。