use of com.hazelcast.cp.event.CPMembershipEvent 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);
}
use of com.hazelcast.cp.event.CPMembershipEvent in project hazelcast by hazelcast.
the class MetadataRaftGroupManager method sendMembershipEvents.
private void sendMembershipEvents(Collection<CPMemberInfo> currentMembers, Collection<CPMemberInfo> newMembers) {
if (!isMetadataGroupLeader()) {
return;
}
EventService eventService = nodeEngine.getEventService();
Collection<CPMemberInfo> addedMembers = new LinkedHashSet<>(newMembers);
addedMembers.removeAll(currentMembers);
for (CPMemberInfo member : addedMembers) {
CPMembershipEvent event = new CPMembershipEventImpl(member, EventType.ADDED);
eventService.publishEvent(SERVICE_NAME, EVENT_TOPIC_MEMBERSHIP, event, EVENT_TOPIC_MEMBERSHIP.hashCode());
}
Collection<CPMemberInfo> removedMembers = new LinkedHashSet<>(currentMembers);
removedMembers.removeAll(newMembers);
for (CPMemberInfo member : removedMembers) {
CPMembershipEvent event = new CPMembershipEventImpl(member, EventType.REMOVED);
eventService.publishEvent(SERVICE_NAME, EVENT_TOPIC_MEMBERSHIP, event, EVENT_TOPIC_MEMBERSHIP.hashCode());
}
}
Aggregations