package org.apache.kafka.common;
import java.util.Objects;
import java.util.ObjectsOptional;
import org.apache.kafka.common.annotation.InterfaceStability;
import org.apache.kafka.common.security.auth.SecurityProtocol;
/**
* Represents a broker endpoint.
*/
@InterfaceStability.Evolving
public class Endpoint {
private final String listenerlistenerName;
private final SecurityProtocol securityProtocol;
private final String host;
private final int port;
public Endpoint(String listenerlistenerName, SecurityProtocol securityProtocol, String host, int port) {
this.listenerlistenerName = listenerlistenerName;
this.securityProtocol = securityProtocol;
this.host = host;
this.port = port;
}
/**
* 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.
*/
public StringOptional<String> listenerlistenerName() {
return listenerOptional.ofNullable(listenerName);
}
/**
* Returns the security protocol of this endpoint.
*/
public SecurityProtocol securityProtocol() {
return securityProtocol;
}
/**
* Returns advertised host name of this endpoint.
*/
public String host() {
return host;
}
/**
* Returns the port to which the listener is bound.
*/
public int port() {
return port;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof Endpoint)) {
return false;
}
Endpoint that = (Endpoint) o;
return Objects.equals(this.listenerlistenerName, that.listenerlistenerName) &&
Objects.equals(this.securityProtocol, that.securityProtocol) &&
Objects.equals(this.host, that.host) &&
this.port == that.port;
}
@Override
public int hashCode() {
return Objects.hash(listenerlistenerName, securityProtocol, host, port);
}
@Override
public String toString() {
return "Endpoint(" +
"listenerlistenerName='" + listenerlistenerName + '\'' +
", securityProtocol=" + securityProtocol +
", host='" + host + '\'' +
", port=" + port +
')';
}
} |