use of com.hazelcast.spi.discovery.DiscoveryStrategyFactory in project hazelcast by hazelcast.
the class DiscoveryTest method test_DiscoveryConfigReadOnly_addDiscoveryStrategyConfig.
@Test
public void test_DiscoveryConfigReadOnly_addDiscoveryStrategyConfig() {
DiscoveryConfig discoveryConfig = new DiscoveryConfig();
DiscoveryStrategyFactory discoveryStrategyFactory = new TestDiscoveryStrategyFactory();
DiscoveryStrategyConfig discoveryStrategyConfig = new DiscoveryStrategyConfig(discoveryStrategyFactory);
discoveryConfig.addDiscoveryStrategyConfig(discoveryStrategyConfig);
assertSame(discoveryStrategyConfig, discoveryConfig.getDiscoveryStrategyConfigs().iterator().next());
}
use of com.hazelcast.spi.discovery.DiscoveryStrategyFactory in project hazelcast by hazelcast.
the class DiscoveryStrategyConfigTest method test_DiscoveryStrategyFactory_constructor_factory.
@Test
public void test_DiscoveryStrategyFactory_constructor_factory() {
DiscoveryStrategyFactory discoveryStrategyFactory = new TestDiscoveryStrategyFactory();
DiscoveryStrategyConfig discoveryStrategyConfig = new DiscoveryStrategyConfig(discoveryStrategyFactory);
assertSame(discoveryStrategyFactory, discoveryStrategyConfig.getDiscoveryStrategyFactory());
assertNull(discoveryStrategyConfig.getClassName());
assertEquals(0, discoveryStrategyConfig.getProperties().size());
}
use of com.hazelcast.spi.discovery.DiscoveryStrategyFactory in project hazelcast by hazelcast.
the class DefaultDiscoveryService method loadDiscoveryStrategies.
private Iterable<DiscoveryStrategy> loadDiscoveryStrategies(DiscoveryServiceSettings settings) {
DiscoveryConfig discoveryConfig = settings.getDiscoveryConfig();
ClassLoader configClassLoader = settings.getConfigClassLoader();
try {
Collection<DiscoveryStrategyConfig> discoveryStrategyConfigs = new ArrayList<DiscoveryStrategyConfig>(discoveryConfig.getDiscoveryStrategyConfigs());
Iterator<DiscoveryStrategyFactory> iterator = ServiceLoader.iterator(DiscoveryStrategyFactory.class, SERVICE_LOADER_TAG, configClassLoader);
// Collect possible factories
List<DiscoveryStrategyFactory> factories = new ArrayList<DiscoveryStrategyFactory>();
while (iterator.hasNext()) {
factories.add(iterator.next());
}
for (DiscoveryStrategyConfig config : discoveryStrategyConfigs) {
DiscoveryStrategyFactory factory = config.getDiscoveryStrategyFactory();
if (factory != null) {
factories.add(factory);
}
}
List<DiscoveryStrategy> discoveryStrategies = new ArrayList<DiscoveryStrategy>();
for (DiscoveryStrategyFactory factory : factories) {
DiscoveryStrategy discoveryStrategy = buildDiscoveryStrategy(factory, discoveryStrategyConfigs);
if (discoveryStrategy != null) {
discoveryStrategies.add(discoveryStrategy);
}
}
return discoveryStrategies;
} catch (Exception e) {
if (e instanceof ValidationException) {
throw new InvalidConfigurationException("Invalid configuration", e);
} else {
throw new RuntimeException("Failed to configure discovery strategies", e);
}
}
}
Aggregations