use of com.hazelcast.spi.partitiongroup.MemberGroup in project hazelcast by hazelcast.
the class PartitionStateGeneratorImpl method createNodeGroups.
private Queue<NodeGroup> createNodeGroups(Collection<MemberGroup> memberGroups) {
Queue<NodeGroup> nodeGroups = new LinkedList<>();
if (memberGroups == null || memberGroups.isEmpty()) {
return nodeGroups;
}
for (MemberGroup memberGroup : memberGroups) {
NodeGroup nodeGroup;
if (memberGroup.size() == 0) {
continue;
}
if (memberGroup instanceof SingleMemberGroup || memberGroup.size() == 1) {
nodeGroup = new SingleNodeGroup();
Member next = memberGroup.iterator().next();
nodeGroup.addNode(PartitionReplica.from(next));
} else {
nodeGroup = new DefaultNodeGroup();
Iterator<Member> iter = memberGroup.iterator();
while (iter.hasNext()) {
Member next = iter.next();
nodeGroup.addNode(PartitionReplica.from(next));
}
}
nodeGroups.add(nodeGroup);
}
return nodeGroups;
}
use of com.hazelcast.spi.partitiongroup.MemberGroup in project hazelcast by hazelcast.
the class PlacementAwareMemberGroupFactory method createInternalMemberGroups.
@Override
protected Set<MemberGroup> createInternalMemberGroups(Collection<? extends Member> allMembers) {
Map<String, MemberGroup> groups = createHashMap(allMembers.size());
for (Member member : allMembers) {
String placementInfo = member.getAttribute(PartitionGroupMetaData.PARTITION_GROUP_PLACEMENT);
if (placementInfo == null) {
throw new IllegalArgumentException("Not enough metadata information is provided. " + "A group name indicating the placement group must be provided with " + "PLACEMENT_AWARE partition group.");
}
MemberGroup group = groups.get(placementInfo);
if (group == null) {
group = new DefaultMemberGroup();
groups.put(placementInfo, group);
}
group.addMember(member);
}
return new HashSet<>(groups.values());
}
use of com.hazelcast.spi.partitiongroup.MemberGroup in project hazelcast by hazelcast.
the class ZoneAwareMemberGroupFactory method createInternalMemberGroups.
@Override
protected Set<MemberGroup> createInternalMemberGroups(Collection<? extends Member> allMembers) {
Map<String, MemberGroup> groups = createHashMap(allMembers.size());
for (Member member : allMembers) {
final String zoneInfo = member.getAttribute(PartitionGroupMetaData.PARTITION_GROUP_ZONE);
if (zoneInfo == null) {
throw new IllegalArgumentException("Not enough metadata information is provided. " + "Availability zone information must be provided with ZONE_AWARE partition group.");
}
MemberGroup group = groups.get(zoneInfo);
if (group == null) {
group = new DefaultMemberGroup();
groups.put(zoneInfo, group);
}
group.addMember(member);
}
return new HashSet<>(groups.values());
}
use of com.hazelcast.spi.partitiongroup.MemberGroup in project hazelcast by hazelcast.
the class PartitionStateManager method updateMemberGroupsSize.
void updateMemberGroupsSize() {
final Collection<MemberGroup> groups = createMemberGroups();
int size = 0;
for (MemberGroup group : groups) {
if (group.size() > 0) {
size++;
}
}
memberGroupsSize = size;
}
use of com.hazelcast.spi.partitiongroup.MemberGroup in project hazelcast by hazelcast.
the class BackupSafeMemberGroupFactory method createMemberGroups.
@Override
public final Collection<MemberGroup> createMemberGroups(Collection<? extends Member> members) {
Collection<MemberGroup> groups = createInternalMemberGroups(members);
if (groups.size() == 1 && members.size() > 1) {
// If there are more than one members and just one group
// then split members into two groups to guarantee at least the first backup.
MemberGroup group1 = groups.iterator().next();
MemberGroup group2 = new DefaultMemberGroup();
int sizePerGroup = group1.size() / 2;
Iterator<Member> iter = group1.iterator();
while (group2.size() < sizePerGroup && iter.hasNext()) {
group2.addMember(iter.next());
iter.remove();
}
groups.add(group2);
}
return groups;
}
Aggregations