chia7712 commented on code in PR #20567:
URL: https://github.com/apache/kafka/pull/20567#discussion_r2375305246
##########
server/src/main/java/org/apache/kafka/server/config/AbstractKafkaConfig.java:
##########
@@ -161,6 +169,80 @@ public static Map<String, String> getMap(String propName,
String propValue) {
}
}
+ public static List<Endpoint> listenerListToEndPoints(List<String>
listeners, Map<ListenerName, SecurityProtocol> securityProtocolMap) {
+ return listenerListToEndPoints(listeners, securityProtocolMap, true);
+ }
+
+ public static List<Endpoint> listenerListToEndPoints(List<String>
listeners, Map<ListenerName, SecurityProtocol> securityProtocolMap, boolean
requireDistinctPorts) {
+ List<Endpoint> endPoints;
+ try {
+ endPoints = SocketServerConfigs.listenerListToEndPoints(listeners,
securityProtocolMap);
+ } catch (Exception e) {
+ throw new IllegalArgumentException(String.format("Error creating
broker listeners from '%s': %s", listeners, e.getMessage()), e);
+ }
+ validate(endPoints, listeners, requireDistinctPorts);
+ return endPoints;
+ }
+
+ private static void validate(List<Endpoint> endPoints, List<String>
listeners, boolean requireDistinctPorts) {
+ long distinctListenerNames =
endPoints.stream().map(Endpoint::listener).distinct().count();
+ if (distinctListenerNames != endPoints.size()) {
+ throw new IllegalArgumentException("Each listener must have a
different name, listeners: " + listeners);
+ }
+
Review Comment:
It can return early if `requireDistinctPorts` is `false`, right? for example:
```java
private static void validate(List<Endpoint> endPoints, List<String>
listeners, boolean requireDistinctPorts) {
long distinct =
endPoints.stream().map(Endpoint::listener).distinct().count();
if (distinct != endPoints.size()) {
throw new IllegalArgumentException("Each listener must have a
different name, listeners: " + listeners);
}
if (!requireDistinctPorts) return;
...
```
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]