Search in sources :

Example 1 with PartitionGroupStrategy

use of com.hazelcast.spi.partitiongroup.PartitionGroupStrategy in project hazelcast by hazelcast.

the class SPIAwareMemberGroupFactory method createInternalMemberGroups.

@Override
protected Set<MemberGroup> createInternalMemberGroups(Collection<? extends Member> allMembers) {
    Set<MemberGroup> memberGroups = createHashSet(allMembers.size());
    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()) {
                        PartitionGroupStrategy groupStrategy = discoveryStrategy.getPartitionGroupStrategy(allMembers);
                        if (groupStrategy == null) {
                            groupStrategy = discoveryStrategy.getPartitionGroupStrategy();
                        }
                        checkNotNull(groupStrategy);
                        for (MemberGroup group : groupStrategy.getMemberGroups()) {
                            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 : MemberGroup(com.hazelcast.spi.partitiongroup.MemberGroup) ValidationException(com.hazelcast.config.properties.ValidationException) PartitionGroupStrategy(com.hazelcast.spi.partitiongroup.PartitionGroupStrategy) DefaultDiscoveryService(com.hazelcast.spi.discovery.impl.DefaultDiscoveryService) Member(com.hazelcast.cluster.Member) InvalidConfigurationException(com.hazelcast.config.InvalidConfigurationException) ValidationException(com.hazelcast.config.properties.ValidationException) DiscoveryStrategy(com.hazelcast.spi.discovery.DiscoveryStrategy) InvalidConfigurationException(com.hazelcast.config.InvalidConfigurationException)

Aggregations

Member (com.hazelcast.cluster.Member)1 InvalidConfigurationException (com.hazelcast.config.InvalidConfigurationException)1 ValidationException (com.hazelcast.config.properties.ValidationException)1 DiscoveryStrategy (com.hazelcast.spi.discovery.DiscoveryStrategy)1 DefaultDiscoveryService (com.hazelcast.spi.discovery.impl.DefaultDiscoveryService)1 MemberGroup (com.hazelcast.spi.partitiongroup.MemberGroup)1 PartitionGroupStrategy (com.hazelcast.spi.partitiongroup.PartitionGroupStrategy)1