Repository: apache/kafka
File: clients/src/main/java/org/apache/kafka/common/Endpoint.java (Java)

Code before:
 * 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;

import org.apache.kafka.common.security.auth.SecurityProtocol;

import java.util.Locale;
import java.util.Objects;
import java.util.Optional;

/**
 * Represents a broker endpoint.
 */

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.

Review comment (refactor):
it seems only `KafkaConfig` uses this helper. Could you please move it to the `KafkaConfig` instead of leaving it in this public APIs?

Code after:
 * 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;

import org.apache.kafka.common.security.auth.SecurityProtocol;

import java.util.Objects;
import java.util.Optional;

/**
 * Represents a broker endpoint.
 */

public class Endpoint {

    private final String listener;
    private final SecurityProtocol securityProtocol;
    private final String host;
    private final int port;

    public Endpoint(String listener, SecurityProtocol securityProtocol, String host, int port) {
        this.listener = listener;
        this.securityProtocol = securityProtocol;
        this.host = host;
        this.port = port;
    }

    /**
     * Returns the listener name of this endpoint.
     */
    public String listener() {
        return listener;
    }

    /**
     * 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(since = "4.1", forRemoval = true)
    public Optional<String> listenerName() {
        return Optional.ofNullable(listener);
    }

    /**
     * Returns the security protocol of this endpoint.
     */