Search in sources :

Example 1 with Addresses

use of com.hazelcast.client.impl.connection.Addresses in project hazelcast by hazelcast.

the class DefaultAddressProvider method loadAddresses.

@Override
public Addresses loadAddresses() {
    List<String> configuredAddresses = networkConfig.getAddresses();
    if (configuredAddresses.isEmpty()) {
        configuredAddresses.add("127.0.0.1");
    }
    Addresses addresses = new Addresses();
    for (String address : configuredAddresses) {
        addresses.addAll(AddressHelper.getSocketAddresses(address));
    }
    return addresses;
}
Also used : Addresses(com.hazelcast.client.impl.connection.Addresses)

Example 2 with Addresses

use of com.hazelcast.client.impl.connection.Addresses in project hazelcast by hazelcast.

the class AddressHelper method toAddresses.

private static Addresses toAddresses(List<Address> addressList) {
    Addresses result = new Addresses();
    if (addressList.size() > 0) {
        result.primary().add(addressList.remove(0));
        result.secondary().addAll(addressList);
    }
    return result;
}
Also used : Addresses(com.hazelcast.client.impl.connection.Addresses)

Example 3 with Addresses

use of com.hazelcast.client.impl.connection.Addresses in project hazelcast by hazelcast.

the class TcpClientConnectionManager method getPossibleMemberAddresses.

Collection<Address> getPossibleMemberAddresses(AddressProvider addressProvider) {
    Collection<Address> addresses = new LinkedHashSet<>();
    try {
        Addresses result = addressProvider.loadAddresses();
        if (shuffleMemberList) {
            // The relative order between primary and secondary addresses should not be changed.
            // so we shuffle the lists separately and then add them to the final list so that
            // secondary addresses are not tried before all primary addresses have been tried.
            // Otherwise we can get startup delays.
            Collections.shuffle(result.primary());
            Collections.shuffle(result.secondary());
        }
        addresses.addAll(result.primary());
        addresses.addAll(result.secondary());
    } catch (NullPointerException e) {
        throw e;
    } catch (Exception e) {
        logger.warning("Exception from AddressProvider: " + addressProvider, e);
    }
    return addresses;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Addresses(com.hazelcast.client.impl.connection.Addresses) Address(com.hazelcast.cluster.Address) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress) HazelcastException(com.hazelcast.core.HazelcastException) HazelcastClientNotActiveException(com.hazelcast.client.HazelcastClientNotActiveException) IOException(java.io.IOException) AuthenticationException(com.hazelcast.client.AuthenticationException) HazelcastClientOfflineException(com.hazelcast.client.HazelcastClientOfflineException) EOFException(java.io.EOFException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) ClientNotAllowedInClusterException(com.hazelcast.client.ClientNotAllowedInClusterException) InvalidConfigurationException(com.hazelcast.config.InvalidConfigurationException) TargetDisconnectedException(com.hazelcast.spi.exception.TargetDisconnectedException)

Example 4 with Addresses

use of com.hazelcast.client.impl.connection.Addresses in project hazelcast by hazelcast.

the class DefaultAddressProviderTest method whenExplicitPorts.

@Test
public void whenExplicitPorts() throws UnknownHostException {
    ClientNetworkConfig config = new ClientNetworkConfig();
    config.addAddress("10.0.0.1:5703");
    config.addAddress("10.0.0.1:5702");
    DefaultAddressProvider provider = new DefaultAddressProvider(config);
    Addresses addresses = provider.loadAddresses();
    assertPrimary(addresses, new Address("10.0.0.1", 5703), new Address("10.0.0.1", 5702));
    assertSecondaryEmpty(addresses);
}
Also used : Addresses(com.hazelcast.client.impl.connection.Addresses) Address(com.hazelcast.cluster.Address) ClientNetworkConfig(com.hazelcast.client.config.ClientNetworkConfig) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 5 with Addresses

use of com.hazelcast.client.impl.connection.Addresses in project hazelcast by hazelcast.

the class DefaultAddressProviderTest method whenMix.

@Test
public void whenMix() throws UnknownHostException {
    ClientNetworkConfig config = new ClientNetworkConfig();
    config.addAddress("10.0.0.1:5701");
    config.addAddress("10.0.0.1:5702");
    config.addAddress("10.0.0.2");
    DefaultAddressProvider provider = new DefaultAddressProvider(config);
    Addresses addresses = provider.loadAddresses();
    assertPrimary(addresses, new Address("10.0.0.1", 5701), new Address("10.0.0.1", 5702), new Address("10.0.0.2", 5701));
    assertSecondary(addresses, new Address("10.0.0.2", 5702), new Address("10.0.0.2", 5703));
}
Also used : Addresses(com.hazelcast.client.impl.connection.Addresses) Address(com.hazelcast.cluster.Address) ClientNetworkConfig(com.hazelcast.client.config.ClientNetworkConfig) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

Addresses (com.hazelcast.client.impl.connection.Addresses)9 Address (com.hazelcast.cluster.Address)6 ClientNetworkConfig (com.hazelcast.client.config.ClientNetworkConfig)5 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)5 QuickTest (com.hazelcast.test.annotation.QuickTest)5 Test (org.junit.Test)5 AuthenticationException (com.hazelcast.client.AuthenticationException)1 ClientNotAllowedInClusterException (com.hazelcast.client.ClientNotAllowedInClusterException)1 HazelcastClientNotActiveException (com.hazelcast.client.HazelcastClientNotActiveException)1 HazelcastClientOfflineException (com.hazelcast.client.HazelcastClientOfflineException)1 AddressProvider (com.hazelcast.client.impl.connection.AddressProvider)1 DiscoveryStrategyConfig (com.hazelcast.config.DiscoveryStrategyConfig)1 InvalidConfigurationException (com.hazelcast.config.InvalidConfigurationException)1 HazelcastException (com.hazelcast.core.HazelcastException)1 TargetDisconnectedException (com.hazelcast.spi.exception.TargetDisconnectedException)1 HazelcastProperties (com.hazelcast.spi.properties.HazelcastProperties)1 EOFException (java.io.EOFException)1 IOException (java.io.IOException)1 InetSocketAddress (java.net.InetSocketAddress)1 SocketAddress (java.net.SocketAddress)1