use of com.hazelcast.spi.discovery.impl.DefaultDiscoveryServiceProvider 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));
}
use of com.hazelcast.spi.discovery.impl.DefaultDiscoveryServiceProvider in project hazelcast by hazelcast.
the class ClusterDiscoveryServiceBuilder method initDiscoveryService.
private DiscoveryService initDiscoveryService(ClientConfig config) {
// Prevent confusing behavior where the DiscoveryService is started
// and strategies are resolved but the AddressProvider is never registered
List<DiscoveryStrategyConfig> aliasedDiscoveryConfigs = ClientAliasedDiscoveryConfigUtils.createDiscoveryStrategyConfigs(config);
if (!properties.getBoolean(ClientProperty.DISCOVERY_SPI_ENABLED) && aliasedDiscoveryConfigs.isEmpty() && !config.getNetworkConfig().isAutoDetectionEnabled()) {
return null;
}
ILogger logger = loggingService.getLogger(DiscoveryService.class);
ClientNetworkConfig networkConfig = config.getNetworkConfig();
DiscoveryConfig discoveryConfig = new DiscoveryConfigReadOnly(networkConfig.getDiscoveryConfig());
DiscoveryServiceProvider factory = discoveryConfig.getDiscoveryServiceProvider();
if (factory == null) {
factory = new DefaultDiscoveryServiceProvider();
}
boolean isAutoDetectionEnabled = networkConfig.isAutoDetectionEnabled();
DiscoveryServiceSettings settings = new DiscoveryServiceSettings().setConfigClassLoader(config.getClassLoader()).setLogger(logger).setDiscoveryMode(DiscoveryMode.Client).setAliasedDiscoveryConfigs(aliasedDiscoveryConfigs).setDiscoveryConfig(discoveryConfig).setAutoDetectionEnabled(isAutoDetectionEnabled);
DiscoveryService discoveryService = factory.newDiscoveryService(settings);
if (isAutoDetectionEnabled && isEmptyDiscoveryStrategies(discoveryService)) {
return null;
}
discoveryService.start();
return discoveryService;
}
use of com.hazelcast.spi.discovery.impl.DefaultDiscoveryServiceProvider in project hazelcast by hazelcast.
the class ClientDiscoverySpiTest method testNodeFilter_from_xml.
@Test
public void testNodeFilter_from_xml() 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));
discoveryService.start();
discoveryService.discoverNodes();
discoveryService.destroy();
Field nodeFilterField = DefaultDiscoveryService.class.getDeclaredField("nodeFilter");
nodeFilterField.setAccessible(true);
TestNodeFilter nodeFilter = (TestNodeFilter) nodeFilterField.get(discoveryService);
assertEquals(4, nodeFilter.getNodes().size());
}
use of com.hazelcast.spi.discovery.impl.DefaultDiscoveryServiceProvider in project hazelcast by hazelcast.
the class Node method createDiscoveryService.
public DiscoveryService createDiscoveryService(DiscoveryConfig discoveryConfig, List<DiscoveryStrategyConfig> aliasedDiscoveryConfigs, boolean isAutoDetectionEnabled, Member localMember) {
DiscoveryServiceProvider factory = discoveryConfig.getDiscoveryServiceProvider();
if (factory == null) {
factory = new DefaultDiscoveryServiceProvider();
}
ILogger logger = getLogger(DiscoveryService.class);
DiscoveryServiceSettings settings = new DiscoveryServiceSettings().setConfigClassLoader(configClassLoader).setLogger(logger).setDiscoveryMode(DiscoveryMode.Member).setDiscoveryConfig(discoveryConfig).setAliasedDiscoveryConfigs(aliasedDiscoveryConfigs).setAutoDetectionEnabled(isAutoDetectionEnabled).setDiscoveryNode(new SimpleDiscoveryNode(localMember.getAddress(), localMember.getAttributes()));
return factory.newDiscoveryService(settings);
}
Aggregations