Search in sources :

Example 1 with AddressTranslator

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

the class ClientDiscoverySpiTest method test_discovery_address_translator_with_public_ip.

@Test
public void test_discovery_address_translator_with_public_ip() 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, true);
    Address publicAddress = new Address("127.0.0.1", 50001);
    Address privateAddress = new Address("127.0.0.1", 1);
    // Enforce refresh of the internal mapping
    assertEquals(publicAddress, translator.translate(privateAddress));
}
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 2 with AddressTranslator

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

the class DefaultClientConnectionManagerFactory method createConnectionManager.

@Override
public ClientConnectionManager createConnectionManager(ClientConfig config, HazelcastClientInstanceImpl client, DiscoveryService discoveryService) {
    LoggingService loggingService = client.getLoggingService();
    ILogger logger = loggingService.getLogger(HazelcastClient.class);
    ClientAwsConfig awsConfig = config.getNetworkConfig().getAwsConfig();
    AddressTranslator addressTranslator;
    if (awsConfig != null && awsConfig.isEnabled()) {
        try {
            addressTranslator = new AwsAddressTranslator(awsConfig, loggingService);
        } catch (NoClassDefFoundError e) {
            logger.warning("hazelcast-aws.jar might be missing!");
            throw e;
        }
    } else if (discoveryService != null) {
        addressTranslator = new DiscoveryAddressTranslator(discoveryService, client.getProperties().getBoolean(ClientProperty.DISCOVERY_SPI_PUBLIC_IP_ENABLED));
    } else {
        addressTranslator = new DefaultAddressTranslator();
    }
    return new ClientConnectionManagerImpl(client, addressTranslator);
}
Also used : AddressTranslator(com.hazelcast.client.connection.AddressTranslator) DefaultAddressTranslator(com.hazelcast.client.spi.impl.DefaultAddressTranslator) AwsAddressTranslator(com.hazelcast.client.spi.impl.AwsAddressTranslator) DiscoveryAddressTranslator(com.hazelcast.client.spi.impl.discovery.DiscoveryAddressTranslator) AwsAddressTranslator(com.hazelcast.client.spi.impl.AwsAddressTranslator) ClientConnectionManagerImpl(com.hazelcast.client.connection.nio.ClientConnectionManagerImpl) DefaultAddressTranslator(com.hazelcast.client.spi.impl.DefaultAddressTranslator) LoggingService(com.hazelcast.logging.LoggingService) ILogger(com.hazelcast.logging.ILogger) DiscoveryAddressTranslator(com.hazelcast.client.spi.impl.discovery.DiscoveryAddressTranslator) ClientAwsConfig(com.hazelcast.client.config.ClientAwsConfig)

Example 3 with AddressTranslator

use of com.hazelcast.client.connection.AddressTranslator 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)

Aggregations

AddressTranslator (com.hazelcast.client.connection.AddressTranslator)3 ClientConfig (com.hazelcast.client.config.ClientConfig)2 ClientNetworkConfig (com.hazelcast.client.config.ClientNetworkConfig)2 XmlClientConfigBuilder (com.hazelcast.client.config.XmlClientConfigBuilder)2 DiscoveryConfig (com.hazelcast.config.DiscoveryConfig)2 Address (com.hazelcast.nio.Address)2 DefaultDiscoveryService (com.hazelcast.spi.discovery.impl.DefaultDiscoveryService)2 DefaultDiscoveryServiceProvider (com.hazelcast.spi.discovery.impl.DefaultDiscoveryServiceProvider)2 DiscoveryService (com.hazelcast.spi.discovery.integration.DiscoveryService)2 DiscoveryServiceProvider (com.hazelcast.spi.discovery.integration.DiscoveryServiceProvider)2 QuickTest (com.hazelcast.test.annotation.QuickTest)2 InputStream (java.io.InputStream)2 Test (org.junit.Test)2 ClientAwsConfig (com.hazelcast.client.config.ClientAwsConfig)1 ClientConnectionManagerImpl (com.hazelcast.client.connection.nio.ClientConnectionManagerImpl)1 AwsAddressTranslator (com.hazelcast.client.spi.impl.AwsAddressTranslator)1 DefaultAddressTranslator (com.hazelcast.client.spi.impl.DefaultAddressTranslator)1 DiscoveryAddressTranslator (com.hazelcast.client.spi.impl.discovery.DiscoveryAddressTranslator)1 ILogger (com.hazelcast.logging.ILogger)1 LoggingService (com.hazelcast.logging.LoggingService)1