Search in sources :

Example 1 with MembershipAwareService

use of com.hazelcast.internal.services.MembershipAwareService in project hazelcast by hazelcast.

the class MembershipManager method sendMembershipEventNotifications.

private void sendMembershipEventNotifications(MemberImpl member, Set<Member> members, final boolean added) {
    int eventType = added ? MembershipEvent.MEMBER_ADDED : MembershipEvent.MEMBER_REMOVED;
    node.getNodeExtension().getAuditlogService().eventBuilder(added ? AuditlogTypeIds.CLUSTER_MEMBER_ADDED : AuditlogTypeIds.CLUSTER_MEMBER_REMOVED).message("Membership changed").addParameter("memberAddress", member.getAddress()).log();
    MembershipEvent membershipEvent = new MembershipEvent(clusterService, member, eventType, members);
    Collection<MembershipAwareService> membershipAwareServices = nodeEngine.getServices(MembershipAwareService.class);
    if (membershipAwareServices != null && !membershipAwareServices.isEmpty()) {
        final MembershipServiceEvent event = new MembershipServiceEvent(membershipEvent);
        for (final MembershipAwareService service : membershipAwareServices) {
            nodeEngine.getExecutionService().execute(MEMBERSHIP_EVENT_EXECUTOR_NAME, () -> {
                if (added) {
                    service.memberAdded(event);
                } else {
                    service.memberRemoved(event);
                }
            });
        }
    }
    EventService eventService = nodeEngine.getEventService();
    Collection<EventRegistration> registrations = eventService.getRegistrations(SERVICE_NAME, SERVICE_NAME);
    for (EventRegistration reg : registrations) {
        eventService.publishEvent(SERVICE_NAME, reg, membershipEvent, reg.getId().hashCode());
    }
}
Also used : EventRegistration(com.hazelcast.spi.impl.eventservice.EventRegistration) MembershipServiceEvent(com.hazelcast.internal.services.MembershipServiceEvent) MembershipEvent(com.hazelcast.cluster.MembershipEvent) MembershipAwareService(com.hazelcast.internal.services.MembershipAwareService) EventService(com.hazelcast.spi.impl.eventservice.EventService)

Aggregations

MembershipEvent (com.hazelcast.cluster.MembershipEvent)1 MembershipAwareService (com.hazelcast.internal.services.MembershipAwareService)1 MembershipServiceEvent (com.hazelcast.internal.services.MembershipServiceEvent)1 EventRegistration (com.hazelcast.spi.impl.eventservice.EventRegistration)1 EventService (com.hazelcast.spi.impl.eventservice.EventService)1