Search in sources :

Example 46 with EventRegistration

use of com.hazelcast.spi.EventRegistration 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)

Example 47 with EventRegistration

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

the class MapEventPublisherImpl method publishMapPartitionLostEvent.

@Override
public void publishMapPartitionLostEvent(Address caller, String mapName, int partitionId) {
    Collection<EventRegistration> registrations = new LinkedList<EventRegistration>();
    for (EventRegistration registration : getRegistrations(mapName)) {
        if (registration.getFilter() instanceof MapPartitionLostEventFilter) {
            registrations.add(registration);
        }
    }
    if (registrations.isEmpty()) {
        return;
    }
    String thisNodesAddress = getThisNodesAddress();
    MapPartitionEventData eventData = new MapPartitionEventData(thisNodesAddress, mapName, caller, partitionId);
    publishEventInternal(registrations, eventData, partitionId);
}
Also used : EventRegistration(com.hazelcast.spi.EventRegistration) MapPartitionLostEventFilter(com.hazelcast.map.impl.MapPartitionLostEventFilter) LinkedList(java.util.LinkedList)

Example 48 with EventRegistration

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

the class MapEventPublisherImpl method publishEvent.

private void publishEvent(Collection<EventRegistration> registrations, Address caller, String mapName, EntryEventType eventType, Data dataKey, Object oldValue, Object value, Object mergingValue) {
    EntryEventDataCache eventDataCache = filteringStrategy.getEntryEventDataCache();
    int orderKey = pickOrderKey(dataKey);
    for (EventRegistration registration : registrations) {
        EventFilter filter = registration.getFilter();
        // a filtering strategy determines whether the event must be published on the specific
        // event registration and may alter the type of event to be published
        int eventTypeForPublishing = filteringStrategy.doFilter(filter, dataKey, oldValue, value, eventType, mapName);
        if (eventTypeForPublishing == FILTER_DOES_NOT_MATCH) {
            continue;
        }
        EntryEventData eventDataToBePublished = eventDataCache.getOrCreateEventData(mapName, caller, dataKey, value, oldValue, mergingValue, eventTypeForPublishing, isIncludeValue(filter));
        eventService.publishEvent(SERVICE_NAME, registration, eventDataToBePublished, orderKey);
    }
    // if events were generated, execute the post-publish hook on each one
    if (!eventDataCache.isEmpty()) {
        postPublishEvent(eventDataCache.eventDataIncludingValues(), eventDataCache.eventDataExcludingValues());
    }
}
Also used : EventRegistration(com.hazelcast.spi.EventRegistration) EntryEventFilter(com.hazelcast.map.impl.EntryEventFilter) TrueEventFilter(com.hazelcast.spi.impl.eventservice.impl.TrueEventFilter) MapPartitionLostEventFilter(com.hazelcast.map.impl.MapPartitionLostEventFilter) QueryEventFilter(com.hazelcast.map.impl.query.QueryEventFilter) EventFilter(com.hazelcast.spi.EventFilter)

Example 49 with EventRegistration

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

the class MapServiceContextImpl method addPartitionLostListener.

@Override
public String addPartitionLostListener(MapPartitionLostListener listener, String mapName) {
    ListenerAdapter listenerAdapter = new InternalMapPartitionLostListenerAdapter(listener);
    EventFilter filter = new MapPartitionLostEventFilter();
    EventRegistration registration = eventService.registerListener(SERVICE_NAME, mapName, filter, listenerAdapter);
    return registration.getId();
}
Also used : ListenerAdapters.createListenerAdapter(com.hazelcast.map.impl.ListenerAdapters.createListenerAdapter) EventRegistration(com.hazelcast.spi.EventRegistration) EventFilter(com.hazelcast.spi.EventFilter) TrueEventFilter(com.hazelcast.spi.impl.eventservice.impl.TrueEventFilter)

Example 50 with EventRegistration

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

the class MapServiceContextImpl method addLocalPartitionLostListener.

@Override
public String addLocalPartitionLostListener(MapPartitionLostListener listener, String mapName) {
    ListenerAdapter listenerAdapter = new InternalMapPartitionLostListenerAdapter(listener);
    EventFilter filter = new MapPartitionLostEventFilter();
    EventRegistration registration = eventService.registerLocalListener(SERVICE_NAME, mapName, filter, listenerAdapter);
    return registration.getId();
}
Also used : ListenerAdapters.createListenerAdapter(com.hazelcast.map.impl.ListenerAdapters.createListenerAdapter) EventRegistration(com.hazelcast.spi.EventRegistration) EventFilter(com.hazelcast.spi.EventFilter) TrueEventFilter(com.hazelcast.spi.impl.eventservice.impl.TrueEventFilter)

Aggregations

EventRegistration (com.hazelcast.spi.EventRegistration)55 EventService (com.hazelcast.spi.EventService)37 Data (com.hazelcast.nio.serialization.Data)7 EventFilter (com.hazelcast.spi.EventFilter)7 Address (com.hazelcast.nio.Address)5 TrueEventFilter (com.hazelcast.spi.impl.eventservice.impl.TrueEventFilter)5 QueryCacheListenerAdapter (com.hazelcast.map.impl.querycache.QueryCacheListenerAdapter)4 CachePartitionLostEventFilter (com.hazelcast.cache.impl.event.CachePartitionLostEventFilter)3 ClientEndpoint (com.hazelcast.client.ClientEndpoint)3 CollectionEventFilter (com.hazelcast.collection.impl.collection.CollectionEventFilter)3 EntryEventFilter (com.hazelcast.map.impl.EntryEventFilter)3 MapPartitionLostEventFilter (com.hazelcast.map.impl.MapPartitionLostEventFilter)3 MapEventData (com.hazelcast.map.impl.event.MapEventData)3 Registration (com.hazelcast.spi.impl.eventservice.impl.Registration)3 InternalCachePartitionLostListenerAdapter (com.hazelcast.cache.impl.event.InternalCachePartitionLostListenerAdapter)2 InitialMembershipEvent (com.hazelcast.core.InitialMembershipEvent)2 ItemListener (com.hazelcast.core.ItemListener)2 Member (com.hazelcast.core.Member)2 MigrationEvent (com.hazelcast.core.MigrationEvent)2 MemberImpl (com.hazelcast.instance.MemberImpl)2