Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/package org.apache.kafka.common.requests;
import org.apache.kafka.common.errors.UnsupportedVersionException;
import org.apache.kafka.common.network.Send;
import org.apache.kafka.common.protocol.ApiKeys;
import org.apache.kafka.common.protocol.Errors;
import org.apache.kafka.common.protocol.MessageUtil;
import org.apache.kafka.common.protocol.ObjectSerializationCache;
import org.apache.kafka.common.protocol.SendBuilder;
import java.nio.ByteBuffer;
import java.util.Map;
publicabstractclassAbstractRequestimplementsAbstractRequestResponse {publicstaticabstractclassBuilder {privatefinal ApiKeys apiKey;
privatefinalshort oldestAllowedVersion;
privatefinalshort latestAllowedVersion;
/**
* Construct a new builder which allows any supported version
*/public Builder(ApiKeys apiKey, boolean enableUnstableLastVersion) {
this(apiKey, apiKey.oldestVersion(), apiKey.latestVersion(enableUnstableLastVersion));
}
/**
* Construct a new builder which allows any supported and released version
*/public Builder(ApiKeys apiKey) {
this(apiKey, false);
}
/**
* Construct a new builder which allows only a specific version
*/public Builder(ApiKeys apiKey, short allowedVersion) {
this(apiKey, allowedVersion, allowedVersion);
}
/**
* Construct a new builder which allows an inclusive range of versions
*/public Builder(ApiKeys apiKey, short oldestAllowedVersion, short latestAllowedVersion) {
this.apiKey = apiKey;
this.oldestAllowedVersion = oldestAllowedVersion;
this.latestAllowedVersion = latestAllowedVersion;
}
public ApiKeys apiKey() {
return apiKey;
}
publicshort oldestAllowedVersion() {
return oldestAllowedVersion;
}
publicshort latestAllowedVersion() {
return latestAllowedVersion;
}
public T build() {
return build(latestAllowedVersion());
}
publicabstract T build(short version);
}
privatefinalshort version;
privatefinal ApiKeys apiKey;
public AbstractRequest(ApiKeys apiKey, short version) {
if (!apiKey.isVersionSupported(version))
thrownew UnsupportedVersionException("The " + apiKey + " protocol does not support version " + version);
this.version = version;
this.apiKey = apiKey;
}
/**
* Get the version of this AbstractRequest object.
*/publicshort version() {
return version;
}
public ApiKeys apiKey() {
return apiKey;
}
publicfinal Send toSend(RequestHeader header) {
return SendBuilder.buildRequestSend(header, data());
}
/**
* Serializes header and body without prefixing with size (unlike `toSend`, which does include a size prefix).
*/publicfinal ByteBuffer serializeWithHeader(RequestHeader header) {
if (header.apiKey() != apiKey) {
thrownew IllegalArgumentException("Could not build request " + apiKey + " with header api key " + header.apiKey());
}
if (header.apiVersion() != version) {
thrownew IllegalArgumentException("Could not build request version " + version + " with header version " + header.apiVersion());
}
return RequestUtils.serialize(header.data(), header.headerVersion(), data(), version);
}
// Visible for testingpublicfinal ByteBuffer serialize() {
return MessageUtil.toByteBuffer(data(), version);
}
// Visible for testingfinalint sizeInBytes() {
return data().size(new ObjectSerializationCache(), version);
}
public String toString(boolean verbose) {
return data().toString();
}
@Overridepublicfinal String toString() {
return toString(true);
}
/**
* Get an error response for a request
*/public AbstractResponse getErrorResponse(Throwable e) {
return getErrorResponse(AbstractResponse.DEFAULT_THROTTLE_TIME, e);
}
/**
* Get an error response for a request with specified throttle time in the response if applicable
*/publicabstract AbstractResponse getErrorResponse(int throttleTimeMs, Throwable e);
/**
* Get the error counts corresponding to an error response. This is overridden for requests
* where response may be null (e.g produce with acks=0).
*/public Map errorCounts(Throwable e) {
AbstractResponse response = getErrorResponse(0, e);
if (response == null)
thrownew IllegalStateException("Error counts could not be obtained for request " + this);
elsereturn response.errorCounts();
}
/**
* Factory method for getting a request object based on ApiKey ID and a version
*/publicstatic RequestAndSize parseRequest(ApiKeys apiKey, short apiVersion, ByteBuffer buffer) {
int bufferSize = buffer.remaining();
returnnew RequestAndSize(doParseRequest(apiKey, apiVersion, buffer), bufferSize);
}
privatestatic AbstractRequest doParseRequest(ApiKeys apiKey, short apiVersion, ByteBuffer buffer) {
switch (apiKey) {
casePRODUCE:return ProduceRequest.parse(buffer, apiVersion);
caseFETCH:return FetchRequest.parse(buffer, apiVersion);
caseLIST_OFFSETS:return ListOffsetsRequest.parse(buffer, apiVersion);
caseMETADATA:return MetadataRequest.parse(buffer, apiVersion);
caseOFFSET_COMMIT:return OffsetCommitRequest.parse(buffer, apiVersion);
caseOFFSET_FETCH:return OffsetFetchRequest.parse(buffer, apiVersion);
caseFIND_COORDINATOR:return FindCoordinatorRequest.parse(buffer, apiVersion);
caseJOIN_GROUP:return JoinGroupRequest.parse(buffer, apiVersion);
caseHEARTBEAT:return HeartbeatRequest.parse(buffer, apiVersion);
caseLEAVE_GROUP:return LeaveGroupRequest.parse(buffer, apiVersion);
caseSYNC_GROUP:return SyncGroupRequest.parse(buffer, apiVersion);
caseSTOP_REPLICA:return StopReplicaRequest.parse(buffer, apiVersion);
caseCONTROLLED_SHUTDOWN:return ControlledShutdownRequest.parse(buffer, apiVersion);
caseUPDATE_METADATA:return UpdateMetadataRequest.parse(buffer, apiVersion);
caseLEADER_AND_ISR:return LeaderAndIsrRequest.parse(buffer, apiVersion);
caseDESCRIBE_GROUPS:return DescribeGroupsRequest.parse(buffer, apiVersion);
caseLIST_GROUPS:return ListGroupsRequest.parse(buffer, apiVersion);
caseSASL_HANDSHAKE:return SaslHandshakeRequest.parse(buffer, apiVersion);
caseAPI_VERSIONS:return ApiVersionsRequest.parse(buffer, apiVersion);
caseCREATE_TOPICS:return CreateTopicsRequest.parse(buffer, apiVersion);
caseDELETE_TOPICS:return DeleteTopicsRequest.parse(buffer, apiVersion);
caseDELETE_RECORDS:return DeleteRecordsRequest.parse(buffer, apiVersion);
caseINIT_PRODUCER_ID:return InitProducerIdRequest.parse(buffer, apiVersion);
caseOFFSET_FOR_LEADER_EPOCH:return OffsetsForLeaderEpochRequest.parse(buffer, apiVersion);
caseADD_PARTITIONS_TO_TXN:return AddPartitionsToTxnRequest.parse(buffer, apiVersion);
caseADD_OFFSETS_TO_TXN:return AddOffsetsToTxnRequest.parse(buffer, apiVersion);
caseEND_TXN:return EndTxnRequest.parse(buffer, apiVersion);
caseWRITE_TXN_MARKERS:return WriteTxnMarkersRequest.parse(buffer, apiVersion);
caseTXN_OFFSET_COMMIT:return TxnOffsetCommitRequest.parse(buffer, apiVersion);
caseDESCRIBE_ACLS:return DescribeAclsRequest.parse(buffer, apiVersion);
caseCREATE_ACLS:return CreateAclsRequest.parse(buffer, apiVersion);
caseDELETE_ACLS:return DeleteAclsRequest.parse(buffer, apiVersion);
caseDESCRIBE_CONFIGS:return DescribeConfigsRequest.parse(buffer, apiVersion);
caseALTER_CONFIGS:return AlterConfigsRequest.parse(buffer, apiVersion);
caseALTER_REPLICA_LOG_DIRS:return AlterReplicaLogDirsRequest.parse(buffer, apiVersion);
caseDESCRIBE_LOG_DIRS:return DescribeLogDirsRequest.parse(buffer, apiVersion);
caseSASL_AUTHENTICATE:return SaslAuthenticateRequest.parse(buffer, apiVersion);
caseCREATE_PARTITIONS:return CreatePartitionsRequest.parse(buffer, apiVersion);
caseCREATE_DELEGATION_TOKEN:return CreateDelegationTokenRequest.parse(buffer, apiVersion);
caseRENEW_DELEGATION_TOKEN:return RenewDelegationTokenRequest.parse(buffer, apiVersion);
caseEXPIRE_DELEGATION_TOKEN:return ExpireDelegationTokenRequest.parse(buffer, apiVersion);
caseDESCRIBE_DELEGATION_TOKEN:return DescribeDelegationTokenRequest.parse(buffer, apiVersion);
caseDELETE_GROUPS:return DeleteGroupsRequest.parse(buffer, apiVersion);
caseELECT_LEADERS:return ElectLeadersRequest.parse(buffer, apiVersion);
caseINCREMENTAL_ALTER_CONFIGS:return IncrementalAlterConfigsRequest.parse(buffer, apiVersion);
caseALTER_PARTITION_REASSIGNMENTS:return AlterPartitionReassignmentsRequest.parse(buffer, apiVersion);
caseLIST_PARTITION_REASSIGNMENTS:return ListPartitionReassignmentsRequest.parse(buffer, apiVersion);
caseOFFSET_DELETE:return OffsetDeleteRequest.parse(buffer, apiVersion);
caseDESCRIBE_CLIENT_QUOTAS:return DescribeClientQuotasRequest.parse(buffer, apiVersion);
caseALTER_CLIENT_QUOTAS:return AlterClientQuotasRequest.parse(buffer, apiVersion);
caseDESCRIBE_USER_SCRAM_CREDENTIALS:return DescribeUserScramCredentialsRequest.parse(buffer, apiVersion);
caseALTER_USER_SCRAM_CREDENTIALS:return AlterUserScramCredentialsRequest.parse(buffer, apiVersion);
caseVOTE:return VoteRequest.parse(buffer, apiVersion);
caseBEGIN_QUORUM_EPOCH:return BeginQuorumEpochRequest.parse(buffer, apiVersion);
caseEND_QUORUM_EPOCH:return EndQuorumEpochRequest.parse(buffer, apiVersion);
caseDESCRIBE_QUORUM:return DescribeQuorumRequest.parse(buffer, apiVersion);
caseALTER_PARTITION:return AlterPartitionRequest.parse(buffer, apiVersion);
caseUPDATE_FEATURES:return UpdateFeaturesRequest.parse(buffer, apiVersion);
caseENVELOPE:return EnvelopeRequest.parse(buffer, apiVersion);
caseFETCH_SNAPSHOT:return FetchSnapshotRequest.parse(buffer, apiVersion);
caseDESCRIBE_CLUSTER:return DescribeClusterRequest.parse(buffer, apiVersion);
caseDESCRIBE_PRODUCERS:return DescribeProducersRequest.parse(buffer, apiVersion);
caseBROKER_REGISTRATION:return BrokerRegistrationRequest.parse(buffer, apiVersion);
caseBROKER_HEARTBEAT:return BrokerHeartbeatRequest.parse(buffer, apiVersion);
caseUNREGISTER_BROKER:return UnregisterBrokerRequest.parse(buffer, apiVersion);
caseDESCRIBE_TRANSACTIONS:return DescribeTransactionsRequest.parse(buffer, apiVersion);
caseLIST_TRANSACTIONS:return ListTransactionsRequest.parse(buffer, apiVersion);
caseALLOCATE_PRODUCER_IDS:return AllocateProducerIdsRequest.parse(buffer, apiVersion);
caseCONSUMER_GROUP_HEARTBEAT:return ConsumerGroupHeartbeatRequest.parse(buffer, apiVersion);
default:thrownew AssertionError(String.format("ApiKey %s is not currently handled in `parseRequest`, the " +
"code should be updated to do so.", apiKey));
}
}
}