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


Java ApiKeys.forId方法代码示例

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


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

示例1: fireCompletion

import org.apache.kafka.common.protocol.ApiKeys; //导入方法依赖的package包/类
public void fireCompletion() {
    if (e != null) {
        future.raise(e);
    } else if (response.wasDisconnected()) {
        RequestHeader requestHeader = response.requestHeader();
        ApiKeys api = ApiKeys.forId(requestHeader.apiKey());
        int correlation = requestHeader.correlationId();
        log.debug("Cancelled {} request {} with correlation id {} due to node {} being disconnected",
                api, requestHeader, correlation, response.destination());
        future.raise(DisconnectException.INSTANCE);
    } else if (response.versionMismatch() != null) {
        future.raise(response.versionMismatch());
    } else {
        future.complete(response);
    }
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:17,代码来源:ConsumerNetworkClient.java

示例2: handleKafkaResponse

import org.apache.kafka.common.protocol.ApiKeys; //导入方法依赖的package包/类
private void handleKafkaResponse(RequestHeader requestHeader, byte[] responseBytes) {
    AbstractResponse response;
    ApiKeys apiKey;
    try {
        response = NetworkClient.parseResponse(ByteBuffer.wrap(responseBytes), requestHeader);
        apiKey = ApiKeys.forId(requestHeader.apiKey());
    } catch (SchemaException | IllegalArgumentException e) {
        LOG.debug("Invalid SASL mechanism response, server may be expecting only GSSAPI tokens");
        throw new AuthenticationException("Invalid SASL mechanism response", e);
    }
    switch (apiKey) {
        case SASL_HANDSHAKE:
            handleSaslHandshakeResponse((SaslHandshakeResponse) response);
            break;
        default:
            throw new IllegalStateException("Unexpected API key during handshake: " + apiKey);
    }
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:19,代码来源:SaslClientAuthenticator.java

示例3: parseStructMaybeUpdateThrottleTimeMetrics

import org.apache.kafka.common.protocol.ApiKeys; //导入方法依赖的package包/类
private static Struct parseStructMaybeUpdateThrottleTimeMetrics(ByteBuffer responseBuffer, RequestHeader requestHeader,
                                                                Sensor throttleTimeSensor, long now) {
    ResponseHeader responseHeader = ResponseHeader.parse(responseBuffer);
    // Always expect the response version id to be the same as the request version id
    ApiKeys apiKey = ApiKeys.forId(requestHeader.apiKey());
    Struct responseBody = apiKey.parseResponse(requestHeader.apiVersion(), responseBuffer);
    correlate(requestHeader, responseHeader);
    if (throttleTimeSensor != null && responseBody.hasField(AbstractResponse.THROTTLE_TIME_KEY_NAME))
        throttleTimeSensor.record(responseBody.getInt(AbstractResponse.THROTTLE_TIME_KEY_NAME), now);
    return responseBody;
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:12,代码来源:NetworkClient.java

示例4: NodeApiVersions

import org.apache.kafka.common.protocol.ApiKeys; //导入方法依赖的package包/类
public NodeApiVersions(Collection<ApiVersion> nodeApiVersions) {
    for (ApiVersion nodeApiVersion : nodeApiVersions) {
        if (ApiKeys.hasId(nodeApiVersion.apiKey)) {
            ApiKeys nodeApiKey = ApiKeys.forId(nodeApiVersion.apiKey);
            usableVersions.put(nodeApiKey, new UsableVersion(nodeApiKey, nodeApiVersion));
        } else {
            // Newer brokers may support ApiKeys we don't know about
            unknownApis.add(nodeApiVersion);
        }
    }
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:12,代码来源:NodeApiVersions.java

示例5: apiVersionToText

import org.apache.kafka.common.protocol.ApiKeys; //导入方法依赖的package包/类
private String apiVersionToText(ApiVersion apiVersion) {
    StringBuilder bld = new StringBuilder();
    ApiKeys apiKey = null;
    if (ApiKeys.hasId(apiVersion.apiKey)) {
        apiKey = ApiKeys.forId(apiVersion.apiKey);
        bld.append(apiKey.name).append("(").append(apiKey.id).append("): ");
    } else {
        bld.append("UNKNOWN(").append(apiVersion.apiKey).append("): ");
    }

    if (apiVersion.minVersion == apiVersion.maxVersion) {
        bld.append(apiVersion.minVersion);
    } else {
        bld.append(apiVersion.minVersion).append(" to ").append(apiVersion.maxVersion);
    }

    if (apiKey != null) {
        UsableVersion usableVersion = usableVersions.get(apiKey);
        if (usableVersion.isTooOld())
            bld.append(" [unusable: node too old]");
        else if (usableVersion.isTooNew())
            bld.append(" [unusable: node too new]");
        else
            bld.append(" [usable: ").append(usableVersion.value).append("]");
    }
    return bld.toString();
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:28,代码来源:NodeApiVersions.java

示例6: createResponse

import org.apache.kafka.common.protocol.ApiKeys; //导入方法依赖的package包/类
private static AbstractResponse createResponse(Struct responseStruct, RequestHeader requestHeader) {
    ApiKeys apiKey = ApiKeys.forId(requestHeader.apiKey());
    return AbstractResponse.getResponse(apiKey, responseStruct);
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:5,代码来源:NetworkClient.java

示例7: handleKafkaRequest

import org.apache.kafka.common.protocol.ApiKeys; //导入方法依赖的package包/类
private boolean handleKafkaRequest(byte[] requestBytes) throws IOException, AuthenticationException {
    boolean isKafkaRequest = false;
    String clientMechanism = null;
    try {
        ByteBuffer requestBuffer = ByteBuffer.wrap(requestBytes);
        RequestHeader requestHeader = RequestHeader.parse(requestBuffer);
        ApiKeys apiKey = ApiKeys.forId(requestHeader.apiKey());
        // A valid Kafka request header was received. SASL authentication tokens are now expected only
        // following a SaslHandshakeRequest since this is not a GSSAPI client token from a Kafka 0.9.0.x client.

        // 状态切换
        setSaslState(SaslState.HANDSHAKE_REQUEST);
        isKafkaRequest = true;
        // 检测apikye、version是否合法

        if (!Protocol.apiVersionSupported(requestHeader.apiKey(), requestHeader.apiVersion())) {
            if (apiKey == ApiKeys.API_VERSIONS)
                sendKafkaResponse(ApiVersionsResponse.unsupportedVersionSend(node, requestHeader));
            else
                throw new UnsupportedVersionException("Version " + requestHeader.apiVersion() + " is not supported for apiKey " + apiKey);
        } else {
            AbstractRequest request = AbstractRequest.getRequest(requestHeader.apiKey(), requestHeader.apiVersion(),
                    requestBuffer).request;

            LOG.debug("Handle Kafka request {}", apiKey);
            switch (apiKey) {
                case API_VERSIONS:
                    handleApiVersionsRequest(requestHeader);
                    break;
                case SASL_HANDSHAKE:
                    clientMechanism = handleHandshakeRequest(requestHeader, (SaslHandshakeRequest) request);
                    break;
                default:
                    throw new IllegalSaslStateException("Unexpected Kafka request of type " + apiKey + " during SASL handshake.");
            }
        }
    } catch (SchemaException | IllegalArgumentException e) {
        if (saslState == SaslState.GSSAPI_OR_HANDSHAKE_REQUEST) {
            // SchemaException is thrown if the request is not in Kafka format. IllegalArgumentException is thrown
            // if the API key is invalid. For compatibility with 0.9.0.x where the first packet is a GSSAPI token
            // starting with 0x60, revert to GSSAPI for both these exceptions.
            if (LOG.isDebugEnabled()) {
                StringBuilder tokenBuilder = new StringBuilder();
                for (byte b : requestBytes) {
                    tokenBuilder.append(String.format("%02x", b));
                    if (tokenBuilder.length() >= 20)
                         break;
                }
                LOG.debug("Received client packet of length {} starting with bytes 0x{}, process as GSSAPI packet", requestBytes.length, tokenBuilder);
            }
            if (enabledMechanisms.contains(SaslConfigs.GSSAPI_MECHANISM)) {
                LOG.debug("First client packet is not a SASL mechanism request, using default mechanism GSSAPI");
                clientMechanism = SaslConfigs.GSSAPI_MECHANISM;
            } else
                throw new UnsupportedSaslMechanismException("Exception handling first SASL packet from client, GSSAPI is not supported by server", e);
        } else
            throw e;
    }
    if (clientMechanism != null) {
        // sasl机制检测通过,创建PlainSaslServer
        createSaslServer(clientMechanism);
        setSaslState(SaslState.AUTHENTICATE);
    }
    return isKafkaRequest;
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:66,代码来源:SaslServerAuthenticator.java


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