Search in sources :

Example 1 with DiscoveryStrategy

use of com.hazelcast.spi.discovery.DiscoveryStrategy in project hazelcast by hazelcast.

the class SPIAwareMemberGroupFactory method createInternalMemberGroups.

@Override
protected Set<MemberGroup> createInternalMemberGroups(Collection<? extends Member> allMembers) {
    Set<MemberGroup> memberGroups = new HashSet<MemberGroup>();
    for (Member member : allMembers) {
        try {
            if (member.localMember()) {
                DefaultDiscoveryService defaultDiscoveryService = (DefaultDiscoveryService) discoveryService;
                // If no discovery strategy is found fail-fast
                if (!defaultDiscoveryService.getDiscoveryStrategies().iterator().hasNext()) {
                    throw new RuntimeException("Could not load any Discovery Strategy, please " + "check service definitions under META_INF.services folder. ");
                } else {
                    for (DiscoveryStrategy discoveryStrategy : defaultDiscoveryService.getDiscoveryStrategies()) {
                        checkNotNull(discoveryStrategy.getPartitionGroupStrategy());
                        Iterable<MemberGroup> spiGroupsIterator = discoveryStrategy.getPartitionGroupStrategy().getMemberGroups();
                        for (MemberGroup group : spiGroupsIterator) {
                            memberGroups.add(group);
                        }
                        return memberGroups;
                    }
                }
            }
        } catch (Exception e) {
            if (e instanceof ValidationException) {
                throw new InvalidConfigurationException("Invalid configuration", e);
            } else {
                throw new RuntimeException("Failed to configure discovery strategies", e);
            }
        }
    }
    return memberGroups;
}
Also used : ValidationException(com.hazelcast.config.properties.ValidationException) DefaultDiscoveryService(com.hazelcast.spi.discovery.impl.DefaultDiscoveryService) Member(com.hazelcast.core.Member) InvalidConfigurationException(com.hazelcast.config.InvalidConfigurationException) ValidationException(com.hazelcast.config.properties.ValidationException) HashSet(java.util.HashSet) DiscoveryStrategy(com.hazelcast.spi.discovery.DiscoveryStrategy) InvalidConfigurationException(com.hazelcast.config.InvalidConfigurationException)

Example 2 with DiscoveryStrategy

use of com.hazelcast.spi.discovery.DiscoveryStrategy 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

InvalidConfigurationException (com.hazelcast.config.InvalidConfigurationException)2 ValidationException (com.hazelcast.config.properties.ValidationException)2 DiscoveryStrategy (com.hazelcast.spi.discovery.DiscoveryStrategy)2 DiscoveryConfig (com.hazelcast.config.DiscoveryConfig)1 DiscoveryStrategyConfig (com.hazelcast.config.DiscoveryStrategyConfig)1 HazelcastException (com.hazelcast.core.HazelcastException)1 Member (com.hazelcast.core.Member)1 DiscoveryStrategyFactory (com.hazelcast.spi.discovery.DiscoveryStrategyFactory)1 DefaultDiscoveryService (com.hazelcast.spi.discovery.impl.DefaultDiscoveryService)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1