Search in sources :

Example 6 with DiscoveryStrategyFactory

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());
}
Also used : DiscoveryStrategyFactory(com.hazelcast.spi.discovery.DiscoveryStrategyFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 7 with DiscoveryStrategyFactory

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());
}
Also used : DiscoveryStrategyFactory(com.hazelcast.spi.discovery.DiscoveryStrategyFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 8 with DiscoveryStrategyFactory

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);
        }
    }
}
Also used : ValidationException(com.hazelcast.config.properties.ValidationException) DiscoveryStrategyConfig(com.hazelcast.config.DiscoveryStrategyConfig) ArrayList(java.util.ArrayList) InvalidConfigurationException(com.hazelcast.config.InvalidConfigurationException) HazelcastException(com.hazelcast.core.HazelcastException) ValidationException(com.hazelcast.config.properties.ValidationException) DiscoveryStrategy(com.hazelcast.spi.discovery.DiscoveryStrategy) InvalidConfigurationException(com.hazelcast.config.InvalidConfigurationException) DiscoveryStrategyFactory(com.hazelcast.spi.discovery.DiscoveryStrategyFactory) DiscoveryConfig(com.hazelcast.config.DiscoveryConfig)

Aggregations

DiscoveryStrategyFactory (com.hazelcast.spi.discovery.DiscoveryStrategyFactory)8 QuickTest (com.hazelcast.test.annotation.QuickTest)7 Test (org.junit.Test)7 ParallelTest (com.hazelcast.test.annotation.ParallelTest)5 DiscoveryConfig (com.hazelcast.config.DiscoveryConfig)3 DiscoveryStrategyConfig (com.hazelcast.config.DiscoveryStrategyConfig)3 ClientConfig (com.hazelcast.client.config.ClientConfig)2 ClientNetworkConfig (com.hazelcast.client.config.ClientNetworkConfig)2 AwsConfig (com.hazelcast.config.AwsConfig)2 Config (com.hazelcast.config.Config)2 InterfacesConfig (com.hazelcast.config.InterfacesConfig)2 JoinConfig (com.hazelcast.config.JoinConfig)2 HazelcastInstance (com.hazelcast.core.HazelcastInstance)2 DiscoveryNode (com.hazelcast.spi.discovery.DiscoveryNode)2 SimpleDiscoveryNode (com.hazelcast.spi.discovery.SimpleDiscoveryNode)2 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)2 InvalidConfigurationException (com.hazelcast.config.InvalidConfigurationException)1 ValidationException (com.hazelcast.config.properties.ValidationException)1 HazelcastException (com.hazelcast.core.HazelcastException)1 DiscoveryStrategy (com.hazelcast.spi.discovery.DiscoveryStrategy)1