本文整理了Java中org.apache.kafka.common.utils.Utils.getHost()
方法的一些代码示例,展示了Utils.getHost()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Utils.getHost()
方法的具体详情如下:
包路径:org.apache.kafka.common.utils.Utils
类名称:Utils
方法名:getHost
[英]Extracts the hostname from a "host:port" address string.
[中]从“主机:端口”地址字符串中提取主机名。
代码示例来源:origin: apache/kafka
if (url != null && !url.isEmpty()) {
try {
String host = getHost(url);
Integer port = getPort(url);
if (host == null || port == null)
代码示例来源:origin: apache/kafka
@Test
public void testGetHost() {
assertEquals("127.0.0.1", getHost("127.0.0.1:8000"));
assertEquals("mydomain.com", getHost("PLAINTEXT://mydomain.com:8080"));
assertEquals("MyDomain.com", getHost("PLAINTEXT://MyDomain.com:8080"));
assertEquals("My_Domain.com", getHost("PLAINTEXT://My_Domain.com:8080"));
assertEquals("::1", getHost("[::1]:1234"));
assertEquals("2001:db8:85a3:8d3:1319:8a2e:370:7348", getHost("PLAINTEXT://[2001:db8:85a3:8d3:1319:8a2e:370:7348]:5678"));
assertEquals("2001:DB8:85A3:8D3:1319:8A2E:370:7348", getHost("PLAINTEXT://[2001:DB8:85A3:8D3:1319:8A2E:370:7348]:5678"));
assertEquals("fe80::b1da:69ca:57f7:63d8%3", getHost("PLAINTEXT://[fe80::b1da:69ca:57f7:63d8%3]:5678"));
}
代码示例来源:origin: org.apache.kafka/kafka-streams
private static HostInfo parseHostInfo(final String endPoint) {
if (endPoint == null || endPoint.trim().isEmpty()) {
return StreamsMetadataState.UNKNOWN_HOST;
}
final String host = getHost(endPoint);
final Integer port = getPort(endPoint);
if (host == null || port == null) {
throw new ConfigException(String.format("Error parsing host address %s. Expected format host:port.", endPoint));
}
return new HostInfo(host, port);
}
代码示例来源:origin: me.jeffshaw.kafka/kafka-clients
public static List<InetSocketAddress> parseAndValidateAddresses(List<String> urls) {
List<InetSocketAddress> addresses = new ArrayList<InetSocketAddress>();
for (String url : urls) {
if (url != null && url.length() > 0) {
String host = getHost(url);
Integer port = getPort(url);
if (host == null || port == null)
throw new ConfigException("Invalid url in " + ProducerConfig.BOOTSTRAP_SERVERS_CONFIG + ": " + url);
try {
InetSocketAddress address = new InetSocketAddress(host, port);
if (address.isUnresolved())
throw new ConfigException("DNS resolution failed for url in " + ProducerConfig.BOOTSTRAP_SERVERS_CONFIG + ": " + url);
addresses.add(address);
} catch (NumberFormatException e) {
throw new ConfigException("Invalid port in " + ProducerConfig.BOOTSTRAP_SERVERS_CONFIG + ": " + url);
}
}
}
if (addresses.size() < 1)
throw new ConfigException("No bootstrap urls given in " + ProducerConfig.BOOTSTRAP_SERVERS_CONFIG);
return addresses;
}
}
代码示例来源:origin: org.apache.kafka/kafka-streams
ClientMetadata(final String endPoint) {
// get the host info if possible
if (endPoint != null) {
final String host = getHost(endPoint);
final Integer port = getPort(endPoint);
if (host == null || port == null) {
throw new ConfigException(String.format("Error parsing host address %s. Expected format host:port.", endPoint));
}
hostInfo = new HostInfo(host, port);
} else {
hostInfo = null;
}
// initialize the consumer memberIds
consumers = new HashSet<>();
// initialize the client state
state = new ClientState();
}
代码示例来源:origin: org.apache.kafka/kafka-streams
if (userEndPoint != null && !userEndPoint.isEmpty()) {
try {
final String host = getHost(userEndPoint);
final Integer port = getPort(userEndPoint);
内容来源于网络,如有侵权,请联系作者删除!