Search in sources :

Example 1 with MembershipServiceEvent

use of com.hazelcast.spi.MembershipServiceEvent in project hazelcast by hazelcast.

the class ClusterServiceImpl method sendMembershipEventNotifications.

private void sendMembershipEventNotifications(MemberImpl member, Set<Member> members, final boolean added) {
    int eventType = added ? MembershipEvent.MEMBER_ADDED : MembershipEvent.MEMBER_REMOVED;
    MembershipEvent membershipEvent = new MembershipEvent(this, 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, new Runnable() {

                public void run() {
                    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.EventRegistration) MembershipServiceEvent(com.hazelcast.spi.MembershipServiceEvent) InitialMembershipEvent(com.hazelcast.core.InitialMembershipEvent) MembershipEvent(com.hazelcast.core.MembershipEvent) MembershipAwareService(com.hazelcast.spi.MembershipAwareService) EventService(com.hazelcast.spi.EventService)

Aggregations

InitialMembershipEvent (com.hazelcast.core.InitialMembershipEvent)1 MembershipEvent (com.hazelcast.core.MembershipEvent)1 EventRegistration (com.hazelcast.spi.EventRegistration)1 EventService (com.hazelcast.spi.EventService)1 MembershipAwareService (com.hazelcast.spi.MembershipAwareService)1 MembershipServiceEvent (com.hazelcast.spi.MembershipServiceEvent)1