use of com.hazelcast.internal.util.AddressUtil.AddressMatcher in project hazelcast by hazelcast.
the class AddressUtilTest method testGetMatchingIpv4Addresses_whenDashForLastPart.
@Test
public void testGetMatchingIpv4Addresses_whenDashForLastPart() {
AddressMatcher addressMatcher = AddressUtil.getAddressMatcher("192.168.1.1-42");
Collection<String> actual = AddressUtil.getMatchingIpv4Addresses(addressMatcher);
assertEquals(42, actual.size());
}
use of com.hazelcast.internal.util.AddressUtil.AddressMatcher in project hazelcast by hazelcast.
the class AddressUtilTest method testGetMatchingIpv4Addresses_whenIPv6AsMatcher.
@Test(expected = IllegalArgumentException.class)
public void testGetMatchingIpv4Addresses_whenIPv6AsMatcher() {
AddressMatcher addressMatcher = AddressUtil.getAddressMatcher("2001:db8:85a3:0:0:8a2e:370:7334");
AddressUtil.getMatchingIpv4Addresses(addressMatcher);
}
use of com.hazelcast.internal.util.AddressUtil.AddressMatcher in project hazelcast by hazelcast.
the class AddressUtilTest method testAddressMatcher.
@Test
public void testAddressMatcher() {
AddressMatcher address;
address = AddressUtil.getAddressMatcher("fe80::62c5:*:fe05:480a%en0");
assertTrue(address.isIPv6());
assertEquals("fe80:0:0:0:62c5:*:fe05:480a", address.getAddress());
address = AddressUtil.getAddressMatcher("192.168.1.1");
assertTrue(address instanceof Ip4AddressMatcher);
assertEquals("192.168.1.1", address.getAddress());
address = AddressUtil.getAddressMatcher("::ffff:192.0.2.128");
assertTrue(address.isIPv4());
assertEquals("192.0.2.128", address.getAddress());
}
use of com.hazelcast.internal.util.AddressUtil.AddressMatcher in project hazelcast by hazelcast.
the class TcpIpJoiner method getPossibleAddresses.
@SuppressWarnings({ "checkstyle:npathcomplexity", "checkstyle:cyclomaticcomplexity" })
protected Collection<Address> getPossibleAddresses() {
final Collection<String> possibleMembers = getMembers();
final Set<Address> possibleAddresses = new HashSet<>();
final NetworkConfig networkConfig = getActiveMemberNetworkConfig(config);
for (String possibleMember : possibleMembers) {
AddressHolder addressHolder = AddressUtil.getAddressHolder(possibleMember);
try {
boolean portIsDefined = addressHolder.getPort() != -1 || !networkConfig.isPortAutoIncrement();
int count = portIsDefined ? 1 : maxPortTryCount;
int port = addressHolder.getPort() != -1 ? addressHolder.getPort() : networkConfig.getPort();
AddressMatcher addressMatcher = null;
try {
addressMatcher = AddressUtil.getAddressMatcher(addressHolder.getAddress());
} catch (InvalidAddressException ignore) {
ignore(ignore);
}
if (addressMatcher != null) {
final Collection<String> matchedAddresses;
if (addressMatcher.isIPv4()) {
matchedAddresses = AddressUtil.getMatchingIpv4Addresses(addressMatcher);
} else {
// for IPv6 we are not doing wildcard matching
matchedAddresses = Collections.singleton(addressHolder.getAddress());
}
for (String matchedAddress : matchedAddresses) {
addPossibleAddresses(possibleAddresses, null, InetAddress.getByName(matchedAddress), port, count);
}
} else {
final String host = addressHolder.getAddress();
final InterfacesConfig interfaces = networkConfig.getInterfaces();
if (interfaces.isEnabled()) {
final InetAddress[] inetAddresses = InetAddress.getAllByName(host);
for (InetAddress inetAddress : inetAddresses) {
if (AddressUtil.matchAnyInterface(inetAddress.getHostAddress(), interfaces.getInterfaces())) {
addPossibleAddresses(possibleAddresses, host, inetAddress, port, count);
}
}
} else {
addPossibleAddresses(possibleAddresses, host, null, port, count);
}
}
} catch (UnknownHostException e) {
logger.warning("Cannot resolve hostname '" + addressHolder.getAddress() + "'. Please make sure host is valid and reachable.");
if (logger.isFineEnabled()) {
logger.fine("Error during resolving possible target!", e);
}
}
}
possibleAddresses.remove(node.getThisAddress());
return possibleAddresses;
}
use of com.hazelcast.internal.util.AddressUtil.AddressMatcher in project hazelcast by hazelcast.
the class AddressUtilTest method testGetMatchingIpv4Addresses_whenWildcardForLastPart.
@Test
public void testGetMatchingIpv4Addresses_whenWildcardForLastPart() {
AddressMatcher addressMatcher = AddressUtil.getAddressMatcher("192.168.1.*");
Collection<String> actual = AddressUtil.getMatchingIpv4Addresses(addressMatcher);
assertEquals(256, actual.size());
}
Aggregations