chia7712 commented on code in PR #19426: URL: https://github.com/apache/kafka/pull/19426#discussion_r2041751400
########## core/src/main/scala/kafka/server/DefaultApiVersionManager.scala: ########## @@ -0,0 +1,83 @@ +/* + * 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 kafka.server + +import org.apache.kafka.common.message.ApiMessageType.ListenerType +import org.apache.kafka.common.protocol.ApiKeys +import org.apache.kafka.common.requests.ApiVersionsResponse +import org.apache.kafka.metadata.MetadataCache +import org.apache.kafka.server.{ApiVersionManager, BrokerFeatures, ClientMetricsManager} +import org.apache.kafka.server.common.FinalizedFeatures + +import java.util + +/** + * The default ApiVersionManager that supports forwarding and has metadata cache, used in brokers. + * The enabled APIs are determined by the broker listener type and the controller APIs. + * + * @param listenerType the listener type + * @param forwardingManager the forwarding manager + * @param brokerFeatures the broker features + * @param metadataCache the metadata cache, used to get the finalized features and the metadata version + * @param enableUnstableLastVersion whether to enable unstable last version, see [[KafkaConfig.unstableApiVersionsEnabled]] + * @param clientMetricsManager the client metrics manager, helps to determine whether client telemetry is enabled + */ +class DefaultApiVersionManager( + val listenerType: ListenerType, + forwardingManager: ForwardingManager, Review Comment: How about using `Supplier<Optional<NodeApiVersions>>` to replace it and then rewrite `DefaultApiVersionManager` by java? ########## server/src/main/java/org/apache/kafka/server/ApiVersionManager.java: ########## @@ -0,0 +1,81 @@ +/* + * 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.server; + +import org.apache.kafka.common.message.ApiMessageType; +import org.apache.kafka.common.protocol.ApiKeys; +import org.apache.kafka.common.requests.ApiVersionsResponse; +import org.apache.kafka.network.metrics.RequestChannelMetrics; +import org.apache.kafka.server.common.FinalizedFeatures; + +import java.util.Set; + +/** + * ApiVersionManagers are used to define the APIs supported by servers + */ +public interface ApiVersionManager { + + /** + * Whether to mark unstable API versions as enabled + * @return true if unstable API versions are enabled, otherwise false + */ + boolean enableUnstableLastVersion(); + + /** + * The listener type + * @return Broker or Controller depending on the server's role + */ + ApiMessageType.ListenerType listenerType(); + + /** + * The enabled APIs + * @return A Set of ApiKeys + */ + Set<ApiKeys> enabledApis(); Review Comment: Both implementations rely on `ApiKeys.apisForListener(listenerType())`, and this method is only used by `newRequestMetrics`. Hence, maybe we can remove it and then rewrite `newRequestMetrics` ```java default RequestChannelMetrics newRequestMetrics() { return new RequestChannelMetrics(ApiKeys.apisForListener(listenerType())); } ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org