Search in sources :

Example 1 with AddressPicker

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));
    }
}
Also used : AddressPicker(com.hazelcast.instance.AddressPicker) Address(com.hazelcast.cluster.Address) Config(com.hazelcast.config.Config) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 2 with AddressPicker

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);
    }
}
Also used : Address(com.hazelcast.cluster.Address) Iterator(java.util.Iterator) EndpointQualifier(com.hazelcast.instance.EndpointQualifier) AddressPicker(com.hazelcast.instance.AddressPicker) NetworkInterface(java.net.NetworkInterface) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) UUID(java.util.UUID) Node(com.hazelcast.instance.impl.Node) ServerSocketChannel(java.nio.channels.ServerSocketChannel) ConcurrentMap(java.util.concurrent.ConcurrentMap) SocketException(java.net.SocketException) ILogger(com.hazelcast.logging.ILogger) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) EmptyStatement.ignore(com.hazelcast.internal.util.EmptyStatement.ignore) Map(java.util.Map) Nonnull(javax.annotation.Nonnull) Collections(java.util.Collections) Nullable(javax.annotation.Nullable) SocketException(java.net.SocketException) Address(com.hazelcast.cluster.Address) EndpointQualifier(com.hazelcast.instance.EndpointQualifier) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map) ServerSocketChannel(java.nio.channels.ServerSocketChannel)

Aggregations

Address (com.hazelcast.cluster.Address)2 AddressPicker (com.hazelcast.instance.AddressPicker)2 Config (com.hazelcast.config.Config)1 EndpointQualifier (com.hazelcast.instance.EndpointQualifier)1 Node (com.hazelcast.instance.impl.Node)1 EmptyStatement.ignore (com.hazelcast.internal.util.EmptyStatement.ignore)1 ILogger (com.hazelcast.logging.ILogger)1 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)1 QuickTest (com.hazelcast.test.annotation.QuickTest)1 NetworkInterface (java.net.NetworkInterface)1 SocketException (java.net.SocketException)1 ServerSocketChannel (java.nio.channels.ServerSocketChannel)1 Collections (java.util.Collections)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 Set (java.util.Set)1 UUID (java.util.UUID)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1