junrao commented on code in PR #17519: URL: https://github.com/apache/kafka/pull/17519#discussion_r1809540887
########## clients/src/main/java/org/apache/kafka/common/network/ServerConnectionId.java: ########## @@ -0,0 +1,143 @@ +/* + * 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.network; + +import java.net.Socket; +import java.util.Map; +import java.util.Optional; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * ServerConnectionId is used to uniquely identify a connection on server for the client. The + * connection id is in the format of "localHost:localPort-remoteHost:remotePort-processorId-index". + * The processorId is the id of the processor that will handle this connection and the index is + * used to ensure uniqueness. + */ +public class ServerConnectionId { + + private static final Pattern URI_PARSE_EXP = Pattern.compile("\\[?([0-9a-zA-Z\\-%._:]*)]?:([0-9]+)"); Review Comment: > I am not sure about this but the code handles with or without brackets. I think it's the right behaviour. Well, we create the connection string in two paths. The first one gets the hostname from `InetAddress.getHostAddress()`, which shouldn't include brackets according to https://groups.google.com/g/golang-dev/c/AiC3MffM4-U. The second one gets the hostname from ServerConnectionId.parseHostPort() which stripes out the brackets if present. -- 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]
