use of com.hazelcast.cp.event.CPGroupAvailabilityEvent in project hazelcast by hazelcast.
the class RaftService method publishGroupAvailabilityEvents.
private void publishGroupAvailabilityEvents(MemberImpl removedMember) {
ClusterService clusterService = nodeEngine.getClusterService();
if (clusterService.getClusterVersion().isUnknownOrLessThan(Versions.V4_1)) {
return;
}
// they will be the ones that keep track of unreachable CP members.
for (CPGroupId groupId : metadataGroupManager.getActiveGroupIds()) {
CPGroupSummary group = metadataGroupManager.getGroup(groupId);
Collection<CPMember> missing = new ArrayList<>();
boolean availabilityDecreased = false;
for (CPMember member : group.members()) {
if (member.getAddress().equals(removedMember.getAddress())) {
// Group's availability decreased because of this removed member
availabilityDecreased = true;
missing.add(member);
} else if (clusterService.getMember(member.getAddress()) == null) {
missing.add(member);
}
}
if (availabilityDecreased) {
CPGroupAvailabilityEvent e = new CPGroupAvailabilityEventImpl(group.id(), group.members(), missing);
nodeEngine.getEventService().publishEvent(SERVICE_NAME, EVENT_TOPIC_AVAILABILITY, e, EVENT_TOPIC_AVAILABILITY.hashCode());
}
}
}
use of com.hazelcast.cp.event.CPGroupAvailabilityEvent in project hazelcast by hazelcast.
the class RaftService method dispatchEvent.
@Override
public void dispatchEvent(Object e, EventListener l) {
long now = Clock.currentTimeMillis();
recentAvailabilityEvents.values().removeIf(expirationTime -> expirationTime < now);
if (e instanceof CPMembershipEvent) {
CPMembershipEvent event = (CPMembershipEvent) e;
CPMembershipListener listener = (CPMembershipListener) l;
switch(event.getType()) {
case ADDED:
listener.memberAdded(event);
break;
case REMOVED:
listener.memberRemoved(event);
break;
default:
throw new IllegalArgumentException("Unhandled event: " + event);
}
return;
}
if (e instanceof CPGroupAvailabilityEvent) {
CPGroupAvailabilityEvent event = (CPGroupAvailabilityEvent) e;
if (recentAvailabilityEvents.putIfAbsent(new CPGroupAvailabilityEventKey(event, l), now + AVAILABILITY_EVENTS_DEDUPLICATION_PERIOD) != null) {
return;
}
CPGroupAvailabilityListener listener = (CPGroupAvailabilityListener) l;
if (event.isMajorityAvailable()) {
listener.availabilityDecreased(event);
} else {
listener.majorityLost(event);
}
return;
}
throw new IllegalArgumentException("Unhandled event: " + e);
}
Aggregations