chia7712 commented on code in PR #19191: URL: https://github.com/apache/kafka/pull/19191#discussion_r2047340719
########## clients/src/main/java/org/apache/kafka/common/Endpoint.java: ########## @@ -16,35 +16,51 @@ */ package org.apache.kafka.common; -import org.apache.kafka.common.annotation.InterfaceStability; import org.apache.kafka.common.security.auth.SecurityProtocol; +import java.util.Locale; import java.util.Objects; import java.util.Optional; /** * Represents a broker endpoint. */ -@InterfaceStability.Evolving public class Endpoint { private final String listenerName; private final SecurityProtocol securityProtocol; private final String host; private final int port; + public static String parseListenerName(String connectionString) { + int firstColon = connectionString.indexOf(':'); + if (firstColon < 0) { + throw new KafkaException("Unable to parse a listener name from " + connectionString); + } + return connectionString.substring(0, firstColon).toUpperCase(Locale.ROOT); + } + public Endpoint(String listenerName, SecurityProtocol securityProtocol, String host, int port) { this.listenerName = listenerName; this.securityProtocol = securityProtocol; this.host = host; this.port = port; } + /** + * Returns the listener name of this endpoint. + */ + public String listener() { + return listenerName; + } + /** * Returns the listener name of this endpoint. This is non-empty for endpoints provided * to broker plugins, but may be empty when used in clients. + * @deprecated Since 4.1. Use {@link #listener} instead. This function will be removed in 5.0. */ + @Deprecated Review Comment: `@Deprecated(since = "4.1", forRemoval = true)` ########## clients/src/main/java/org/apache/kafka/clients/admin/RaftVoterEndpoint.java: ########## @@ -49,22 +49,33 @@ static String requireNonNullAllCapsNonEmpty(String input) { /** * Create an endpoint for a metadata quorum voter. * - * @param name The human-readable name for this endpoint. For example, CONTROLLER. + * @param listener The human-readable name for this endpoint. For example, CONTROLLER. * @param host The DNS hostname for this endpoint. * @param port The network port for this endpoint. */ public RaftVoterEndpoint( - String name, + String listener, String host, int port ) { - this.name = requireNonNullAllCapsNonEmpty(name); + this.listener = requireNonNullAllCapsNonEmpty(listener); this.host = Objects.requireNonNull(host); this.port = port; } + /** + * The listener name for this endpoint. + */ + public String listener() { + return listener; + } + + /** + * @deprecated Since 4.1. Use {@link #listener()} instead. This function will be removed in 5.0. + */ + @Deprecated Review Comment: `@Deprecated(since = "4.1", forRemoval = true)` ########## clients/src/main/java/org/apache/kafka/common/Endpoint.java: ########## @@ -16,35 +16,51 @@ */ package org.apache.kafka.common; -import org.apache.kafka.common.annotation.InterfaceStability; import org.apache.kafka.common.security.auth.SecurityProtocol; +import java.util.Locale; import java.util.Objects; import java.util.Optional; /** * Represents a broker endpoint. */ -@InterfaceStability.Evolving public class Endpoint { private final String listenerName; private final SecurityProtocol securityProtocol; private final String host; private final int port; + public static String parseListenerName(String connectionString) { Review Comment: it seems only `KafkaConfig` uses this helper. Could you please move it to the `KafkaConfig` instead of leaving it in this public APIs? ########## clients/src/main/java/org/apache/kafka/common/Endpoint.java: ########## @@ -16,35 +16,51 @@ */ package org.apache.kafka.common; -import org.apache.kafka.common.annotation.InterfaceStability; import org.apache.kafka.common.security.auth.SecurityProtocol; +import java.util.Locale; import java.util.Objects; import java.util.Optional; /** * Represents a broker endpoint. */ -@InterfaceStability.Evolving public class Endpoint { private final String listenerName; private final SecurityProtocol securityProtocol; private final String host; private final int port; + public static String parseListenerName(String connectionString) { + int firstColon = connectionString.indexOf(':'); + if (firstColon < 0) { + throw new KafkaException("Unable to parse a listener name from " + connectionString); + } + return connectionString.substring(0, firstColon).toUpperCase(Locale.ROOT); + } + public Endpoint(String listenerName, SecurityProtocol securityProtocol, String host, int port) { this.listenerName = listenerName; this.securityProtocol = securityProtocol; this.host = host; this.port = port; } + /** + * Returns the listener name of this endpoint. + */ + public String listener() { + return listenerName; Review Comment: How about renaming it to `listenerName` for consistency? -- 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