use of com.hazelcast.config.TcpIpConfig in project hazelcast by hazelcast.
the class DefaultAddressPicker method getInterfaces.
private Collection<InterfaceDefinition> getInterfaces() throws UnknownHostException {
NetworkConfig networkConfig = config.getNetworkConfig();
// address -> domain
Map<String, String> addressDomainMap;
TcpIpConfig tcpIpConfig = networkConfig.getJoin().getTcpIpConfig();
if (tcpIpConfig.isEnabled()) {
// LinkedHashMap is to guarantee order
addressDomainMap = new LinkedHashMap<String, String>();
Collection<String> possibleAddresses = TcpIpJoiner.getConfigurationMembers(config);
for (String possibleAddress : possibleAddresses) {
String addressHolder = AddressUtil.getAddressHolder(possibleAddress).getAddress();
if (AddressUtil.isIpAddress(addressHolder)) {
// there may be a domain registered for this address
if (!addressDomainMap.containsKey(addressHolder)) {
addressDomainMap.put(addressHolder, null);
}
} else {
try {
Collection<String> addresses = resolveDomainNames(addressHolder);
for (String address : addresses) {
addressDomainMap.put(address, addressHolder);
}
} catch (UnknownHostException e) {
logger.warning("Cannot resolve hostname: '" + addressHolder + "'");
}
}
}
} else {
addressDomainMap = Collections.emptyMap();
}
Collection<InterfaceDefinition> interfaces = new HashSet<InterfaceDefinition>();
if (networkConfig.getInterfaces().isEnabled()) {
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.");
}
}
logger.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()));
}
logger.info("Interfaces is disabled, trying to pick one address from TCP-IP config addresses: " + interfaces);
}
return interfaces;
}
use of com.hazelcast.config.TcpIpConfig in project hazelcast by hazelcast.
the class TcpIpJoiner method getConfigurationMembers.
public static Collection<String> getConfigurationMembers(Config config) {
final TcpIpConfig tcpIpConfig = config.getNetworkConfig().getJoin().getTcpIpConfig();
final Collection<String> configMembers = tcpIpConfig.getMembers();
final Set<String> possibleMembers = new HashSet<String>();
for (String member : configMembers) {
// split members defined in tcp-ip configuration by comma(,) semi-colon(;) space( ).
String[] members = member.split("[,; ]");
Collections.addAll(possibleMembers, members);
}
return possibleMembers;
}
Aggregations