handle failure on interface check if its up (seems to happen on jdk 7)

This commit is contained in:
kimchy 2011-07-08 21:58:39 +03:00
parent 61ad8b614a
commit 9464208f83
1 changed files with 22 additions and 5 deletions

View File

@ -26,8 +26,20 @@ import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.os.OsUtils;
import java.lang.reflect.Method;
import java.net.*;
import java.util.*;
import java.net.Inet4Address;
import java.net.Inet6Address;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
* @author kimchy (shay.banon)
@ -123,8 +135,13 @@ public abstract class NetworkUtils {
}
for (NetworkInterface intf : intfsList) {
try {
if (!intf.isUp() || intf.isLoopback())
continue;
} catch (Exception e) {
// might happen when calling on a network interface that does not exists
continue;
}
address = getFirstNonLoopbackAddress(intf, ip_version);
if (address != null) {
return address;