All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.streamnative.pulsar.handlers.kop.lookup.ServiceLookupData Maven / Gradle / Ivy

There is a newer version: 4.0.0.4
Show newest version
/**
 * Copyright (c) 2019 - 2024 StreamNative, Inc.. All Rights Reserved.
 */
package io.streamnative.pulsar.handlers.kop.lookup;

import java.net.InetSocketAddress;
import java.util.Map;
import java.util.Objects;
import org.apache.commons.lang3.StringUtils;

public record ServiceLookupData(String pulsarServiceUrl, String pulsarServiceUrlTls, Map protocols) {

    public boolean hasListened(InetSocketAddress address) {
        final var hostAndPort = address.getHostName() + ":" + address.getPort();
        return StringUtils.endsWith(pulsarServiceUrl, hostAndPort)
            || StringUtils.endsWith(pulsarServiceUrlTls, hostAndPort);
    }

    @Override
    public boolean equals(Object obj) {
        if (obj instanceof ServiceLookupData that) {
            return Objects.equals(this.pulsarServiceUrl, that.pulsarServiceUrl)
                && Objects.equals(this.pulsarServiceUrlTls, that.pulsarServiceUrlTls)
                && Objects.equals(this.protocols, that.protocols);
        }
        return false;
    }

    @Override
    public String toString() {
        final var builder = new StringBuilder();
        if (pulsarServiceUrl != null) {
            builder.append("pulsarServiceUrl: \"").append(pulsarServiceUrl).append("\"");
        } else {
            builder.append("pulsarServiceUrl: null");
        }
        builder.append(", ");
        if (pulsarServiceUrlTls != null) {
            builder.append("pulsarServiceUrlTls: \"").append(pulsarServiceUrlTls).append("\"");
        } else {
            builder.append("pulsarServiceUrlTls: null");
        }
        builder.append(", ").append("protocols: ");
        if (protocols != null) {
            builder.append("[");
            final var protocolStrings = protocols.entrySet().stream()
                .map(e -> e.getKey() + ": \"" + e.getValue() + "\"").sorted().toList();
            builder.append(String.join(", ", protocolStrings)).append("]");
        } else {
            builder.append("null");
        }
        return builder.toString();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy