TaiJuWu commented on code in PR #20567:
URL: https://github.com/apache/kafka/pull/20567#discussion_r2392661028
##########
server/src/main/java/org/apache/kafka/server/config/AbstractKafkaConfig.java:
##########
@@ -161,6 +169,76 @@ 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);
+ }
+
+ if (!requireDistinctPorts) return;
+
+ Map<Integer, List<Endpoint>> duplicatePorts = endPoints.stream()
+ .filter(ep -> ep.port() != 0) // filter port 0 for unit tests
+ .collect(Collectors.groupingBy(Endpoint::port))
+ .entrySet().stream()
+ .filter(entry -> entry.getValue().size() > 1)
+ .collect(Collectors.toMap(Map.Entry::getKey,
Map.Entry::getValue));
Review Comment:
fixed.
--
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]