return addressDef;
}
private Collection<InterfaceDefinition> getInterfaces(final NetworkConfig networkConfig) throws UnknownHostException {
final Map<String, String> addressDomainMap; // address -> domain
final TcpIpConfig tcpIpConfig = networkConfig.getJoin().getTcpIpConfig();
if (tcpIpConfig.isEnabled()) {
addressDomainMap = new LinkedHashMap<String, String>(); // LinkedHashMap is to guarantee order
final Collection<String> possibleAddresses = TcpIpJoiner.getConfigurationMembers(node.config);
for (String possibleAddress : possibleAddresses) {
final String s = AddressUtil.getAddressHolder(possibleAddress).address;
if (AddressUtil.isIpAddress(s)) {
if (!addressDomainMap.containsKey(s)) { // there may be a domain registered for this address
addressDomainMap.put(s, null);
}
} else {
try {
final Collection<String> addresses = resolveDomainNames(s);
for (String address : addresses) {
addressDomainMap.put(address, s);
}
} catch (UnknownHostException e) {
logger.warning("Cannot resolve hostname: '" + s + "'");
}
}
}
} else {
addressDomainMap = Collections.emptyMap();
}
final Collection<InterfaceDefinition> interfaces = new HashSet<InterfaceDefinition>();
if (networkConfig.getInterfaces().isEnabled()) {
final Collection<String> configInterfaces = networkConfig.getInterfaces().getInterfaces();
for (String configInterface : configInterfaces) {
if (AddressUtil.isIpAddress(configInterface)) {
String hostname = findHostnameMatchingInterface(addressDomainMap, configInterface);
interfaces.add(new InterfaceDefinition(hostname, configInterface));
} else {
logger.info("'" + configInterface
+ "' is not an IP address! Removing from interface list.");
}
}
log(Level.INFO, "Interfaces is enabled, trying to pick one address matching " +
"to one of: " + interfaces);
} else if (tcpIpConfig.isEnabled()) {
for (Entry<String, String> entry : addressDomainMap.entrySet()) {
interfaces.add(new InterfaceDefinition(entry.getValue(), entry.getKey()));
}
log(Level.INFO, "Interfaces is disabled, trying to pick one address from TCP-IP config " +
"addresses: " + interfaces);