Search in sources :

Example 6 with ClientNetworkConfig

use of com.hazelcast.client.config.ClientNetworkConfig 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 7 with ClientNetworkConfig

use of com.hazelcast.client.config.ClientNetworkConfig in project hazelcast by hazelcast.

the class HazelcastClientInstanceImpl method initListenerService.

private ClientListenerServiceImpl initListenerService() {
    int eventQueueCapacity = properties.getInteger(ClientProperty.EVENT_QUEUE_CAPACITY);
    int eventThreadCount = properties.getInteger(ClientProperty.EVENT_THREAD_COUNT);
    final ClientNetworkConfig networkConfig = config.getNetworkConfig();
    if (networkConfig.isSmartRouting()) {
        return new ClientSmartListenerService(this, eventThreadCount, eventQueueCapacity);
    } else {
        return new ClientNonSmartListenerService(this, eventThreadCount, eventQueueCapacity);
    }
}
Also used : ClientSmartListenerService(com.hazelcast.client.spi.impl.listener.ClientSmartListenerService) ClientNonSmartListenerService(com.hazelcast.client.spi.impl.listener.ClientNonSmartListenerService) ClientNetworkConfig(com.hazelcast.client.config.ClientNetworkConfig)

Example 8 with ClientNetworkConfig

use of com.hazelcast.client.config.ClientNetworkConfig in project bazel by bazelbuild.

the class ConcurrentMapFactory method createHazelcast.

public static ConcurrentMap<String, byte[]> createHazelcast(RemoteOptions options) {
    HazelcastInstance instance;
    if (options.hazelcastClientConfig != null) {
        try {
            ClientConfig config = new XmlClientConfigBuilder(options.hazelcastClientConfig).build();
            instance = HazelcastClient.newHazelcastClient(config);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    } else if (options.hazelcastNode != null) {
        // If --hazelcast_node is specified then create a client instance.
        ClientConfig config = new ClientConfig();
        ClientNetworkConfig net = config.getNetworkConfig();
        net.addAddress(options.hazelcastNode.split(","));
        instance = HazelcastClient.newHazelcastClient(config);
    } else if (options.hazelcastStandaloneListenPort != 0) {
        Config config = new Config();
        config.getNetworkConfig().setPort(options.hazelcastStandaloneListenPort).getJoin().getMulticastConfig().setEnabled(false);
        instance = Hazelcast.newHazelcastInstance(config);
    } else {
        // Otherwise create a default instance. This is going to look at
        // -Dhazelcast.config=some-hazelcast.xml for configuration.
        instance = Hazelcast.newHazelcastInstance();
    }
    return instance.getMap(HAZELCAST_CACHE_NAME);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) XmlClientConfigBuilder(com.hazelcast.client.config.XmlClientConfigBuilder) Config(com.hazelcast.config.Config) ClientConfig(com.hazelcast.client.config.ClientConfig) ClientNetworkConfig(com.hazelcast.client.config.ClientNetworkConfig) IOException(java.io.IOException) ClientConfig(com.hazelcast.client.config.ClientConfig) ClientNetworkConfig(com.hazelcast.client.config.ClientNetworkConfig)

Example 9 with ClientNetworkConfig

use of com.hazelcast.client.config.ClientNetworkConfig in project hazelcast by hazelcast.

the class ClientDiscoverySpiTest method test_discovery_address_translator.

@Test
public void test_discovery_address_translator() throws Exception {
    String xmlFileName = "hazelcast-client-discovery-spi-test.xml";
    InputStream xmlResource = ClientDiscoverySpiTest.class.getClassLoader().getResourceAsStream(xmlFileName);
    ClientConfig clientConfig = new XmlClientConfigBuilder(xmlResource).build();
    ClientNetworkConfig networkConfig = clientConfig.getNetworkConfig();
    DiscoveryConfig discoveryConfig = networkConfig.getDiscoveryConfig();
    DiscoveryServiceProvider provider = new DefaultDiscoveryServiceProvider();
    DiscoveryService discoveryService = provider.newDiscoveryService(buildDiscoveryServiceSettings(discoveryConfig));
    AddressTranslator translator = new DiscoveryAddressTranslator(discoveryService, false);
    Address address = new Address("127.0.0.1", 50001);
    assertNull(translator.translate(null));
    assertEquals(address, translator.translate(address));
    // Enforce refresh of the internal mapping
    assertEquals(address, translator.translate(address));
}
Also used : Address(com.hazelcast.nio.Address) InputStream(java.io.InputStream) DiscoveryServiceProvider(com.hazelcast.spi.discovery.integration.DiscoveryServiceProvider) DefaultDiscoveryServiceProvider(com.hazelcast.spi.discovery.impl.DefaultDiscoveryServiceProvider) AddressTranslator(com.hazelcast.client.connection.AddressTranslator) DefaultDiscoveryServiceProvider(com.hazelcast.spi.discovery.impl.DefaultDiscoveryServiceProvider) XmlClientConfigBuilder(com.hazelcast.client.config.XmlClientConfigBuilder) ClientConfig(com.hazelcast.client.config.ClientConfig) DiscoveryConfig(com.hazelcast.config.DiscoveryConfig) DiscoveryService(com.hazelcast.spi.discovery.integration.DiscoveryService) DefaultDiscoveryService(com.hazelcast.spi.discovery.impl.DefaultDiscoveryService) ClientNetworkConfig(com.hazelcast.client.config.ClientNetworkConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 10 with ClientNetworkConfig

use of com.hazelcast.client.config.ClientNetworkConfig in project hazelcast by hazelcast.

the class ClientDiscoverySpiTest method test_enabled_whenDiscoveryConfigIsNull.

@Test(expected = IllegalArgumentException.class)
public void test_enabled_whenDiscoveryConfigIsNull() {
    ClientConfig config = new ClientConfig();
    config.setProperty(GroupProperty.DISCOVERY_SPI_ENABLED.getName(), "true");
    ClientNetworkConfig networkConfig = config.getNetworkConfig();
    networkConfig.setDiscoveryConfig(null);
}
Also used : ClientConfig(com.hazelcast.client.config.ClientConfig) ClientNetworkConfig(com.hazelcast.client.config.ClientNetworkConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

ClientNetworkConfig (com.hazelcast.client.config.ClientNetworkConfig)18 ClientConfig (com.hazelcast.client.config.ClientConfig)13 QuickTest (com.hazelcast.test.annotation.QuickTest)9 Test (org.junit.Test)9 DefaultDiscoveryServiceProvider (com.hazelcast.spi.discovery.impl.DefaultDiscoveryServiceProvider)6 DiscoveryService (com.hazelcast.spi.discovery.integration.DiscoveryService)6 DiscoveryServiceProvider (com.hazelcast.spi.discovery.integration.DiscoveryServiceProvider)6 XmlClientConfigBuilder (com.hazelcast.client.config.XmlClientConfigBuilder)5 DiscoveryConfig (com.hazelcast.config.DiscoveryConfig)5 Address (com.hazelcast.nio.Address)5 DefaultDiscoveryService (com.hazelcast.spi.discovery.impl.DefaultDiscoveryService)5 InputStream (java.io.InputStream)4 DiscoveryServiceSettings (com.hazelcast.spi.discovery.integration.DiscoveryServiceSettings)3 ClientAwsConfig (com.hazelcast.client.config.ClientAwsConfig)2 AddressTranslator (com.hazelcast.client.connection.AddressTranslator)2 ILogger (com.hazelcast.logging.ILogger)2 InetSocketAddress (java.net.InetSocketAddress)2 HazelcastClient (com.hazelcast.client.HazelcastClient)1 AddressProvider (com.hazelcast.client.connection.AddressProvider)1 AwsAddressProvider (com.hazelcast.client.spi.impl.AwsAddressProvider)1