Search in sources :

Example 21 with EventRegistration

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

the class CacheEventHandler method publishEvent.

void publishEvent(CacheEventContext cacheEventContext) {
    final EventService eventService = nodeEngine.getEventService();
    final String cacheName = cacheEventContext.getCacheName();
    final Collection<EventRegistration> candidates = eventService.getRegistrations(SERVICE_NAME, cacheName);
    if (candidates.isEmpty()) {
        return;
    }
    final Object eventData;
    final CacheEventType eventType = cacheEventContext.getEventType();
    switch(eventType) {
        case CREATED:
        case UPDATED:
        case REMOVED:
        case EXPIRED:
            final CacheEventData cacheEventData = new CacheEventDataImpl(cacheName, eventType, cacheEventContext.getDataKey(), cacheEventContext.getDataValue(), cacheEventContext.getDataOldValue(), cacheEventContext.isOldValueAvailable());
            CacheEventSet eventSet = new CacheEventSet(eventType, cacheEventContext.getCompletionId());
            eventSet.addEventData(cacheEventData);
            eventData = eventSet;
            break;
        case EVICTED:
        case INVALIDATED:
            eventData = new CacheEventDataImpl(cacheName, eventType, cacheEventContext.getDataKey(), null, null, false);
            break;
        case COMPLETED:
            CacheEventData completedEventData = new CacheEventDataImpl(cacheName, eventType, cacheEventContext.getDataKey(), cacheEventContext.getDataValue(), null, false);
            eventSet = new CacheEventSet(eventType, cacheEventContext.getCompletionId());
            eventSet.addEventData(completedEventData);
            eventData = eventSet;
            break;
        default:
            throw new IllegalArgumentException("Event Type not defined to create an eventData during publish : " + eventType.name());
    }
    eventService.publishEvent(SERVICE_NAME, candidates, eventData, cacheEventContext.getOrderKey());
}
Also used : EventRegistration(com.hazelcast.spi.EventRegistration) EventService(com.hazelcast.spi.EventService)

Example 22 with EventRegistration

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

the class CacheEventHandler method publishEvent.

void publishEvent(String cacheName, CacheEventSet eventSet, int orderKey) {
    final EventService eventService = nodeEngine.getEventService();
    final Collection<EventRegistration> candidates = eventService.getRegistrations(SERVICE_NAME, cacheName);
    if (candidates.isEmpty()) {
        return;
    }
    eventService.publishEvent(SERVICE_NAME, candidates, eventSet, orderKey);
}
Also used : EventRegistration(com.hazelcast.spi.EventRegistration) EventService(com.hazelcast.spi.EventService)

Example 23 with EventRegistration

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

the class NodeQueryCacheEventService method sendEventToSubscriber.

@Override
public void sendEventToSubscriber(String name, Object eventData, int orderKey) {
    Collection<EventRegistration> eventRegistrations = getRegistrations(name);
    if (eventRegistrations.isEmpty()) {
        return;
    }
    for (EventRegistration eventRegistration : eventRegistrations) {
        Registration registration = (Registration) eventRegistration;
        Object listener = registration.getListener();
        if (listener instanceof QueryCacheListenerAdapter) {
            continue;
        }
        publishEventInternal(registration, eventData, orderKey);
    }
}
Also used : EventRegistration(com.hazelcast.spi.EventRegistration) Registration(com.hazelcast.spi.impl.eventservice.impl.Registration) EventRegistration(com.hazelcast.spi.EventRegistration) QueryCacheListenerAdapter(com.hazelcast.map.impl.querycache.QueryCacheListenerAdapter)

Example 24 with EventRegistration

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

the class NodeQueryCacheEventService method hasListener.

@Override
public boolean hasListener(String mapName, String cacheName) {
    String listenerName = generateListenerName(mapName, cacheName);
    Collection<EventRegistration> eventRegistrations = getRegistrations(listenerName);
    if (eventRegistrations.isEmpty()) {
        return false;
    }
    for (EventRegistration eventRegistration : eventRegistrations) {
        Registration registration = (Registration) eventRegistration;
        Object listener = registration.getListener();
        if (listener instanceof QueryCacheListenerAdapter) {
            return true;
        }
    }
    return false;
}
Also used : EventRegistration(com.hazelcast.spi.EventRegistration) Registration(com.hazelcast.spi.impl.eventservice.impl.Registration) EventRegistration(com.hazelcast.spi.EventRegistration) QueryCacheListenerAdapter(com.hazelcast.map.impl.querycache.QueryCacheListenerAdapter)

Example 25 with EventRegistration

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

the class MultiMapEventsPublisher method publishMultiMapEvent.

public void publishMultiMapEvent(String mapName, EntryEventType eventType, int numberOfEntriesAffected) {
    final EventService eventService = nodeEngine.getEventService();
    final Collection<EventRegistration> registrations = eventService.getRegistrations(MultiMapService.SERVICE_NAME, mapName);
    if (registrations.isEmpty()) {
        return;
    }
    final Address caller = nodeEngine.getThisAddress();
    final String source = caller.toString();
    final MapEventData mapEventData = new MapEventData(source, mapName, caller, eventType.getType(), numberOfEntriesAffected);
    eventService.publishEvent(MultiMapService.SERVICE_NAME, registrations, mapEventData, mapName.hashCode());
}
Also used : EventRegistration(com.hazelcast.spi.EventRegistration) Address(com.hazelcast.nio.Address) EventService(com.hazelcast.spi.EventService) MapEventData(com.hazelcast.map.impl.event.MapEventData)

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