Search in sources :

Example 26 with EventRegistration

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

the class MultiMapEventsPublisher method publishEntryEvent.

public final void publishEntryEvent(String multiMapName, EntryEventType eventType, Data key, Object newValue, Object oldValue) {
    EventService eventService = nodeEngine.getEventService();
    Collection<EventRegistration> registrations = eventService.getRegistrations(MultiMapService.SERVICE_NAME, multiMapName);
    for (EventRegistration registration : registrations) {
        MultiMapEventFilter filter = (MultiMapEventFilter) registration.getFilter();
        if (filter.getKey() == null || filter.getKey().equals(key)) {
            Data dataNewValue = filter.isIncludeValue() ? nodeEngine.toData(newValue) : null;
            Data dataOldValue = filter.isIncludeValue() ? nodeEngine.toData(oldValue) : null;
            final Address caller = nodeEngine.getThisAddress();
            final String source = caller.toString();
            EntryEventData event = new EntryEventData(source, multiMapName, caller, key, dataNewValue, dataOldValue, eventType.getType());
            eventService.publishEvent(MultiMapService.SERVICE_NAME, registration, event, multiMapName.hashCode());
        }
    }
}
Also used : EventRegistration(com.hazelcast.spi.EventRegistration) Address(com.hazelcast.nio.Address) EntryEventData(com.hazelcast.map.impl.event.EntryEventData) EventService(com.hazelcast.spi.EventService) MapEventData(com.hazelcast.map.impl.event.MapEventData) Data(com.hazelcast.nio.serialization.Data) EntryEventData(com.hazelcast.map.impl.event.EntryEventData)

Example 27 with EventRegistration

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

the class MultiMapService method addListener.

public String addListener(String name, EventListener listener, Data key, boolean includeValue, boolean local) {
    EventService eventService = nodeEngine.getEventService();
    EventRegistration registration;
    final MultiMapEventFilter filter = new MultiMapEventFilter(includeValue, key);
    if (local) {
        registration = eventService.registerLocalListener(SERVICE_NAME, name, filter, listener);
    } else {
        registration = eventService.registerListener(SERVICE_NAME, name, filter, listener);
    }
    return registration.getId();
}
Also used : EventRegistration(com.hazelcast.spi.EventRegistration) EventService(com.hazelcast.spi.EventService)

Example 28 with EventRegistration

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

the class CollectionOperation method publishEvent.

protected void publishEvent(ItemEventType eventType, Data data) {
    EventService eventService = getNodeEngine().getEventService();
    Collection<EventRegistration> registrations = eventService.getRegistrations(getServiceName(), name);
    final Address address = getNodeEngine().getThisAddress();
    for (EventRegistration registration : registrations) {
        CollectionEventFilter filter = (CollectionEventFilter) registration.getFilter();
        final boolean includeValue = filter.isIncludeValue();
        CollectionEvent event = new CollectionEvent(name, includeValue ? data : null, eventType, address);
        eventService.publishEvent(getServiceName(), registration, event, name.hashCode());
    }
}
Also used : CollectionEventFilter(com.hazelcast.collection.impl.collection.CollectionEventFilter) EventRegistration(com.hazelcast.spi.EventRegistration) Address(com.hazelcast.nio.Address) CollectionEvent(com.hazelcast.collection.impl.collection.CollectionEvent) EventService(com.hazelcast.spi.EventService)

Example 29 with EventRegistration

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

the class BatchInvalidator method sendInvalidations.

private void sendInvalidations(String dataStructureName, List<Invalidation> invalidations) {
    // There will always be at least one listener which listens invalidations. This is the reason behind eager creation
    // of BatchNearCacheInvalidation instance here. There is a causality between listener and invalidation. Only if we have
    // a listener, we can have an invalidation, otherwise invalidations are not generated.
    Invalidation invalidation = new BatchNearCacheInvalidation(dataStructureName, invalidations);
    Collection<EventRegistration> registrations = eventService.getRegistrations(serviceName, dataStructureName);
    for (EventRegistration registration : registrations) {
        if (eventFilter.apply(registration)) {
            // find worker queue of striped executor by using subscribers' address.
            // we want to send all batch invalidations belonging to same subscriber go into
            // the same workers queue.
            int orderKey = registration.getSubscriber().hashCode();
            eventService.publishEvent(serviceName, registration, invalidation, orderKey);
        }
    }
}
Also used : EventRegistration(com.hazelcast.spi.EventRegistration)

Example 30 with EventRegistration

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

the class Invalidator method sendImmediately.

protected final void sendImmediately(Invalidation invalidation, int orderKey) {
    String dataStructureName = invalidation.getName();
    Collection<EventRegistration> registrations = eventService.getRegistrations(serviceName, dataStructureName);
    for (EventRegistration registration : registrations) {
        if (eventFilter.apply(registration)) {
            eventService.publishEvent(serviceName, registration, invalidation, orderKey);
        }
    }
}
Also used : EventRegistration(com.hazelcast.spi.EventRegistration)

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