|
@@ -27,6 +27,7 @@ import java.util.Collections;
|
|
|
import java.util.List;
|
|
|
import java.util.Random;
|
|
|
|
|
|
+import org.apache.zookeeper.common.HostNameUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
@@ -116,18 +117,10 @@ public final class StaticHostProvider implements HostProvider {
|
|
|
InetAddress resolvedAddresses[] = InetAddress.getAllByName((ia!=null) ? ia.getHostAddress():
|
|
|
address.getHostName());
|
|
|
for (InetAddress resolvedAddress : resolvedAddresses) {
|
|
|
- // If hostName is null but the address is not, we can tell that
|
|
|
- // the hostName is an literal IP address. Then we can set the host string as the hostname
|
|
|
- // safely to avoid reverse DNS lookup.
|
|
|
- // As far as i know, the only way to check if the hostName is null is use toString().
|
|
|
- // Both the two implementations of InetAddress are final class, so we can trust the return value of
|
|
|
- // the toString() method.
|
|
|
- if (resolvedAddress.toString().startsWith("/") && resolvedAddress.getAddress() != null) {
|
|
|
- tmpList.add(new InetSocketAddress(InetAddress.getByAddress(address.getHostName(),
|
|
|
- resolvedAddress.getAddress()), address.getPort()));
|
|
|
- } else {
|
|
|
- tmpList.add(new InetSocketAddress(resolvedAddress.getHostAddress(), address.getPort()));
|
|
|
- }
|
|
|
+ tmpList.add(new InetSocketAddress(InetAddress.getByAddress(
|
|
|
+ HostNameUtils.getHostString(address),
|
|
|
+ resolvedAddress.getAddress()),
|
|
|
+ address.getPort()));
|
|
|
}
|
|
|
}
|
|
|
Collections.shuffle(tmpList, sourceOfRandomness);
|