Search in sources :

Example 1 with AddressProvider

use of com.hazelcast.client.connection.AddressProvider in project hazelcast by hazelcast.

the class TestHazelcastFactory method newHazelcastClient.

public HazelcastInstance newHazelcastClient(ClientConfig config) {
    if (!mockNetwork) {
        return HazelcastClient.newHazelcastClient(config);
    }
    if (config == null) {
        config = new XmlClientConfigBuilder().build();
    }
    ClassLoader tccl = Thread.currentThread().getContextClassLoader();
    HazelcastClientProxy proxy;
    try {
        if (tccl == ClassLoader.getSystemClassLoader()) {
            Thread.currentThread().setContextClassLoader(HazelcastClient.class.getClassLoader());
        }
        ClientConnectionManagerFactory clientConnectionManagerFactory = clientRegistry.createClientServiceFactory("127.0.0.1", CLIENT_PORTS);
        AddressProvider testAddressProvider = createAddressProvider(config);
        HazelcastClientInstanceImpl client = new HazelcastClientInstanceImpl(config, clientConnectionManagerFactory, testAddressProvider);
        client.start();
        clients.add(client);
        OutOfMemoryErrorDispatcher.registerClient(client);
        proxy = new HazelcastClientProxy(client);
    } finally {
        Thread.currentThread().setContextClassLoader(tccl);
    }
    return proxy;
}
Also used : AddressProvider(com.hazelcast.client.connection.AddressProvider) XmlClientConfigBuilder(com.hazelcast.client.config.XmlClientConfigBuilder) ClientConnectionManagerFactory(com.hazelcast.client.impl.ClientConnectionManagerFactory) HazelcastClientInstanceImpl(com.hazelcast.client.impl.HazelcastClientInstanceImpl) HazelcastClient(com.hazelcast.client.HazelcastClient) HazelcastClientProxy(com.hazelcast.client.impl.HazelcastClientProxy)

Example 2 with AddressProvider

use of com.hazelcast.client.connection.AddressProvider in project hazelcast by hazelcast.

the class HazelcastClientInstanceImpl method createAddressProviders.

private Collection<AddressProvider> createAddressProviders(AddressProvider externalAddressProvider) {
    ClientNetworkConfig networkConfig = getClientConfig().getNetworkConfig();
    final ClientAwsConfig awsConfig = networkConfig.getAwsConfig();
    Collection<AddressProvider> addressProviders = new LinkedList<AddressProvider>();
    addressProviders.add(new DefaultAddressProvider(networkConfig));
    if (externalAddressProvider != null) {
        addressProviders.add(externalAddressProvider);
    }
    if (discoveryService != null) {
        addressProviders.add(new DiscoveryAddressProvider(discoveryService, loggingService));
    }
    if (awsConfig != null && awsConfig.isEnabled()) {
        try {
            addressProviders.add(new AwsAddressProvider(awsConfig, loggingService));
        } catch (NoClassDefFoundError e) {
            ILogger logger = loggingService.getLogger(HazelcastClient.class);
            logger.warning("hazelcast-aws.jar might be missing!");
            throw e;
        }
    }
    return addressProviders;
}
Also used : AwsAddressProvider(com.hazelcast.client.spi.impl.AwsAddressProvider) DefaultAddressProvider(com.hazelcast.client.spi.impl.DefaultAddressProvider) AddressProvider(com.hazelcast.client.connection.AddressProvider) DiscoveryAddressProvider(com.hazelcast.client.spi.impl.discovery.DiscoveryAddressProvider) AwsAddressProvider(com.hazelcast.client.spi.impl.AwsAddressProvider) DiscoveryAddressProvider(com.hazelcast.client.spi.impl.discovery.DiscoveryAddressProvider) DefaultAddressProvider(com.hazelcast.client.spi.impl.DefaultAddressProvider) HazelcastClient(com.hazelcast.client.HazelcastClient) ILogger(com.hazelcast.logging.ILogger) ClientAwsConfig(com.hazelcast.client.config.ClientAwsConfig) LinkedList(java.util.LinkedList) ClientNetworkConfig(com.hazelcast.client.config.ClientNetworkConfig)

Example 3 with AddressProvider

use of com.hazelcast.client.connection.AddressProvider in project hazelcast by hazelcast.

the class TestHazelcastFactory method createAddressProvider.

private AddressProvider createAddressProvider(ClientConfig config) {
    List<String> userConfiguredAddresses = config.getNetworkConfig().getAddresses();
    if (!userConfiguredAddresses.contains("localhost")) {
        // addresses are set explicitly, don't add more addresses
        return null;
    }
    return new AddressProvider() {

        @Override
        public Collection<InetSocketAddress> loadAddresses() {
            Collection<InetSocketAddress> inetAddresses = new ArrayList<InetSocketAddress>();
            for (Address address : getKnownAddresses()) {
                Collection<InetSocketAddress> addresses = AddressHelper.getPossibleSocketAddresses(address.getPort(), address.getHost(), 3);
                inetAddresses.addAll(addresses);
            }
            return inetAddresses;
        }
    };
}
Also used : AddressProvider(com.hazelcast.client.connection.AddressProvider) Address(com.hazelcast.nio.Address) InetSocketAddress(java.net.InetSocketAddress) InetSocketAddress(java.net.InetSocketAddress) ArrayList(java.util.ArrayList)

Example 4 with AddressProvider

use of com.hazelcast.client.connection.AddressProvider in project hazelcast by hazelcast.

the class ClusterListenerSupport method getSocketAddresses.

private Collection<InetSocketAddress> getSocketAddresses() {
    final List<InetSocketAddress> socketAddresses = new LinkedList<InetSocketAddress>();
    Collection<Member> memberList = getMemberList();
    for (Member member : memberList) {
        socketAddresses.add(member.getSocketAddress());
    }
    for (AddressProvider addressProvider : addressProviders) {
        socketAddresses.addAll(addressProvider.loadAddresses());
    }
    if (shuffleMemberList) {
        Collections.shuffle(socketAddresses);
    }
    return socketAddresses;
}
Also used : AddressProvider(com.hazelcast.client.connection.AddressProvider) InetSocketAddress(java.net.InetSocketAddress) Member(com.hazelcast.core.Member) LinkedList(java.util.LinkedList)

Aggregations

AddressProvider (com.hazelcast.client.connection.AddressProvider)4 HazelcastClient (com.hazelcast.client.HazelcastClient)2 InetSocketAddress (java.net.InetSocketAddress)2 LinkedList (java.util.LinkedList)2 ClientAwsConfig (com.hazelcast.client.config.ClientAwsConfig)1 ClientNetworkConfig (com.hazelcast.client.config.ClientNetworkConfig)1 XmlClientConfigBuilder (com.hazelcast.client.config.XmlClientConfigBuilder)1 ClientConnectionManagerFactory (com.hazelcast.client.impl.ClientConnectionManagerFactory)1 HazelcastClientInstanceImpl (com.hazelcast.client.impl.HazelcastClientInstanceImpl)1 HazelcastClientProxy (com.hazelcast.client.impl.HazelcastClientProxy)1 AwsAddressProvider (com.hazelcast.client.spi.impl.AwsAddressProvider)1 DefaultAddressProvider (com.hazelcast.client.spi.impl.DefaultAddressProvider)1 DiscoveryAddressProvider (com.hazelcast.client.spi.impl.discovery.DiscoveryAddressProvider)1 Member (com.hazelcast.core.Member)1 ILogger (com.hazelcast.logging.ILogger)1 Address (com.hazelcast.nio.Address)1 ArrayList (java.util.ArrayList)1