use of com.hazelcast.instance.AddressPicker in project hazelcast by hazelcast.
the class IpVersionPreferenceTest method testBindAddress.
@Test
public void testBindAddress() throws Exception {
ruleSysPropPreferHzIpv4.setOrClearProperty(hazelcastIpv4 == null ? null : String.valueOf(hazelcastIpv4));
ruleSysPropPreferIpv4Stack.setOrClearProperty(javaIpv4 == null ? null : String.valueOf(javaIpv4));
ruleSysPropPreferIpv6Addresses.setOrClearProperty(javaIpv6 == null ? null : String.valueOf(javaIpv6));
boolean expectedIPv6 = !getOrDefault(hazelcastIpv4, true) && !getOrDefault(javaIpv4, false) && getOrDefault(javaIpv6, false);
if (expectedIPv6) {
assumeNotNull(findIPv6NonLoopbackInterface());
}
DefaultAddressPicker addressPicker = new DefaultAddressPicker(new Config(), Logger.getLogger(AddressPicker.class));
try {
addressPicker.pickAddress();
Address bindAddress = addressPicker.getBindAddress(MEMBER);
assertEquals("Bind address: " + bindAddress, expectedIPv6, bindAddress.isIPv6());
} finally {
IOUtil.closeResource(addressPicker.getServerSocketChannel(MEMBER));
}
}
use of com.hazelcast.instance.AddressPicker in project hazelcast by hazelcast.
the class LocalAddressRegistry method registerLocalAddresses.
private void registerLocalAddresses(UUID thisUuid, AddressPicker addressPicker) {
LinkedAddresses addresses = LinkedAddresses.getResolvedAddresses(addressPicker.getPublicAddress(EndpointQualifier.MEMBER));
for (Map.Entry<EndpointQualifier, Address> addressEntry : addressPicker.getBindAddressMap().entrySet()) {
addresses.addAllResolvedAddresses(addressPicker.getPublicAddress(addressEntry.getKey()));
addresses.addAllResolvedAddresses(addressEntry.getValue());
ServerSocketChannel serverSocketChannel = addressPicker.getServerSocketChannel(addressEntry.getKey());
if (serverSocketChannel != null && serverSocketChannel.socket().getInetAddress().isAnyLocalAddress()) {
int port = addressEntry.getValue().getPort();
try {
Collections.list(NetworkInterface.getNetworkInterfaces()).forEach(networkInterface -> Collections.list(networkInterface.getInetAddresses()).forEach(inetAddress -> addresses.addAllResolvedAddresses(new Address(inetAddress, port))));
} catch (SocketException e) {
ignore(e);
}
}
localUuid = thisUuid;
localAddresses = addresses;
}
if (logger.isFineEnabled()) {
logger.fine(localAddresses + " are registered for the local member with local uuid=" + localUuid);
}
}
Aggregations