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));
}
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);
}
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));
}
Aggregations