本文整理了Java中brooklyn.util.net.Networking.isLocalOnly()
方法的一些代码示例,展示了Networking.isLocalOnly()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Networking.isLocalOnly()
方法的具体详情如下:
包路径:brooklyn.util.net.Networking
类名称:Networking
方法名:isLocalOnly
[英]As #isLocalOnly(InetAddress) but taking a string; does not require the string to be resolvable, and generally treats non-resolvable hostnames as NOT local-only (although they are treated as private by #isPrivateSubnet(String)), although certain well-known hostnames are recognised as local-only
[中]作为#isLocalOnly(InetAddress),但使用字符串;不要求字符串是可解析的,通常将不可解析的主机名视为非本地主机名(尽管它们被#isPrivateSubnet(string)视为私有主机名),尽管某些已知主机名仅被识别为本地主机名
代码示例来源:origin: io.brooklyn/brooklyn-utils-common
/** As {@link #isLocalOnly(InetAddress)} but taking a string;
* does not require the string to be resolvable, and generally treats non-resolvable hostnames as NOT local-only
* (although they are treated as private by {@link #isPrivateSubnet(String)}),
* although certain well-known hostnames are recognised as local-only */
public static boolean isLocalOnly(String hostnameOrIp) {
Preconditions.checkNotNull(hostnameOrIp, "hostnameOrIp");
if ("127.0.0.1".equals(hostnameOrIp)) return true;
if ("localhost".equals(hostnameOrIp)) return true;
if ("localhost.localdomain".equals(hostnameOrIp)) return true;
try {
InetAddress ia = getInetAddressWithFixedName(hostnameOrIp);
return isLocalOnly(ia);
} catch (Exception e) {
log.debug("Networking cannot resolve "+hostnameOrIp+": assuming it is not a local-only address, but it is a private address");
return false;
}
}
代码示例来源:origin: io.brooklyn/brooklyn-locations-jclouds
protected Optional<String> getPrivateAddress() {
if (truth(node.getPrivateAddresses())) {
Iterator<String> pi = node.getPrivateAddresses().iterator();
while (pi.hasNext()) {
String p = pi.next();
// disallow local only addresses
if (Networking.isLocalOnly(p)) continue;
// other things may be public or private, but either way, return it
return Optional.of(p);
}
}
return Optional.absent();
}
内容来源于网络,如有侵权,请联系作者删除!