use of com.hazelcast.spi.partitiongroup.MemberGroup 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;
}
use of com.hazelcast.spi.partitiongroup.MemberGroup in project hazelcast by hazelcast.
the class HostAwareMemberGroupFactory method createInternalMemberGroups.
@Override
protected Set<MemberGroup> createInternalMemberGroups(Collection<? extends Member> allMembers) {
Map<String, MemberGroup> groups = createHashMap(allMembers.size());
for (Member member : allMembers) {
Address address = ((MemberImpl) member).getAddress();
MemberGroup group = groups.get(address.getHost());
if (group == null) {
group = new DefaultMemberGroup();
groups.put(address.getHost(), group);
}
group.addMember(member);
}
return new HashSet<MemberGroup>(groups.values());
}
use of com.hazelcast.spi.partitiongroup.MemberGroup in project hazelcast by hazelcast.
the class PartitionStateGeneratorTest method testCustomPartitionStateGenerator.
@Test
public void testCustomPartitionStateGenerator() throws Exception {
final MemberGroupFactory memberGroupFactory = new MemberGroupFactory() {
public Collection<MemberGroup> createMemberGroups(Collection<? extends Member> members) {
MemberGroup[] g = new MemberGroup[4];
for (int i = 0; i < g.length; i++) {
g[i] = new DefaultMemberGroup();
}
for (Member member : members) {
Address address = member.getAddress();
if (even(address.getHost().hashCode()) && even(address.getPort())) {
g[0].addMember(member);
} else if (even(address.getHost().hashCode()) && !even(address.getPort())) {
g[1].addMember(member);
} else if (!even(address.getHost().hashCode()) && even(address.getPort())) {
g[2].addMember(member);
} else if (!even(address.getHost().hashCode()) && !even(address.getPort())) {
g[3].addMember(member);
}
}
List<MemberGroup> list = new LinkedList<MemberGroup>();
for (MemberGroup memberGroup : g) {
if (memberGroup.size() > 0) {
list.add(memberGroup);
}
}
return list;
}
boolean even(int k) {
return k % 2 == 0;
}
};
test(memberGroupFactory);
}
use of com.hazelcast.spi.partitiongroup.MemberGroup in project hazelcast by hazelcast.
the class MemberGroupFactoryTest method testHostAwareMemberGroupFactoryCreateMemberGroups.
@Test
public void testHostAwareMemberGroupFactoryCreateMemberGroups() {
MemberGroupFactory groupFactory = new HostAwareMemberGroupFactory();
Collection<Member> members = createMembers();
Collection<MemberGroup> memberGroups = groupFactory.createMemberGroups(members);
assertEquals("Member Groups: " + String.valueOf(memberGroups), 8, memberGroups.size());
for (MemberGroup memberGroup : memberGroups) {
assertEquals("Member Group: " + String.valueOf(memberGroup), 2, memberGroup.size());
}
}
use of com.hazelcast.spi.partitiongroup.MemberGroup in project hazelcast by hazelcast.
the class MemberGroupFactoryTest method testNodeMetadataAwareMemberGroupFactoryCreateMemberGroups.
@Test
public void testNodeMetadataAwareMemberGroupFactoryCreateMemberGroups() {
MemberGroupFactory groupFactory = new NodeAwareMemberGroupFactory();
Collection<Member> members = createMembersWithNodeAwareMetadata();
Collection<MemberGroup> memberGroups = groupFactory.createMemberGroups(members);
assertEquals("Member Groups: " + String.valueOf(memberGroups), 3, memberGroups.size());
for (MemberGroup memberGroup : memberGroups) {
assertEquals("Member Group: " + String.valueOf(memberGroup), 1, memberGroup.size());
}
}
Aggregations