io.streamnative.pulsar.handlers.kop.lookup.ServiceLookupData Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of pulsar-protocol-handler-kafka Show documentation
Show all versions of pulsar-protocol-handler-kafka Show documentation
Kafka on Pulsar implemented using Pulsar Protocol Handler
/**
* 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();
}
}