Search in sources :

Example 1 with EventFilter

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

the class CacheAddPartitionLostListenerMessageTask method call.

@Override
protected Object call() {
    final ClientEndpoint endpoint = getEndpoint();
    CachePartitionLostListener listener = new CachePartitionLostListener() {

        @Override
        public void partitionLost(CachePartitionLostEvent event) {
            if (endpoint.isAlive()) {
                ClientMessage eventMessage = CacheAddPartitionLostListenerCodec.encodeCachePartitionLostEvent(event.getPartitionId(), event.getMember().getUuid());
                sendClientMessage(null, eventMessage);
            }
        }
    };
    InternalCachePartitionLostListenerAdapter listenerAdapter = new InternalCachePartitionLostListenerAdapter(listener);
    EventFilter filter = new CachePartitionLostEventFilter();
    CacheService service = getService(CacheService.SERVICE_NAME);
    EventService eventService = service.getNodeEngine().getEventService();
    EventRegistration registration;
    if (parameters.localOnly) {
        registration = eventService.registerLocalListener(ICacheService.SERVICE_NAME, parameters.name, filter, listenerAdapter);
    } else {
        registration = eventService.registerListener(ICacheService.SERVICE_NAME, parameters.name, filter, listenerAdapter);
    }
    String registrationId = registration.getId();
    endpoint.addListenerDestroyAction(CacheService.SERVICE_NAME, parameters.name, registrationId);
    return registrationId;
}
Also used : CachePartitionLostListener(com.hazelcast.cache.impl.event.CachePartitionLostListener) EventRegistration(com.hazelcast.spi.EventRegistration) CachePartitionLostEvent(com.hazelcast.cache.impl.event.CachePartitionLostEvent) EventService(com.hazelcast.spi.EventService) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) ClientEndpoint(com.hazelcast.client.ClientEndpoint) CachePartitionLostEventFilter(com.hazelcast.cache.impl.event.CachePartitionLostEventFilter) CachePartitionLostEventFilter(com.hazelcast.cache.impl.event.CachePartitionLostEventFilter) EventFilter(com.hazelcast.spi.EventFilter) InternalCachePartitionLostListenerAdapter(com.hazelcast.cache.impl.event.InternalCachePartitionLostListenerAdapter) CacheService(com.hazelcast.cache.impl.CacheService) ICacheService(com.hazelcast.cache.impl.ICacheService)

Example 2 with EventFilter

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

the class AbstractMapAddEntryListenerMessageTask method call.

@Override
protected Object call() {
    final ClientEndpoint endpoint = getEndpoint();
    final MapService mapService = getService(MapService.SERVICE_NAME);
    Object listener = newMapListener();
    MapServiceContext mapServiceContext = mapService.getMapServiceContext();
    String name = getDistributedObjectName();
    EventFilter eventFilter = getEventFilter();
    String registrationId;
    if (isLocalOnly()) {
        registrationId = mapServiceContext.addLocalEventListener(listener, eventFilter, name);
    } else {
        registrationId = mapServiceContext.addEventListener(listener, eventFilter, name);
    }
    endpoint.addListenerDestroyAction(MapService.SERVICE_NAME, name, registrationId);
    return registrationId;
}
Also used : ClientEndpoint(com.hazelcast.client.ClientEndpoint) MapService(com.hazelcast.map.impl.MapService) EventFilter(com.hazelcast.spi.EventFilter) MapServiceContext(com.hazelcast.map.impl.MapServiceContext)

Example 3 with EventFilter

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

the class QueryCacheEventPublisher method convertQueryCacheEventDataOrNull.

private QueryCacheEventData convertQueryCacheEventDataOrNull(PartitionAccumulatorRegistry registry, Data dataKey, Data dataNewValue, Data dataOldValue, int eventTypeId, int partitionId) {
    EventFilter eventFilter = registry.getEventFilter();
    EntryEventType eventType = EntryEventType.getByType(eventTypeId);
    // filtering strategy
    if (filteringStrategy instanceof DefaultEntryEventFilteringStrategy) {
        eventType = getCQCEventTypeOrNull(eventType, eventFilter, dataKey, dataNewValue, dataOldValue);
    } else {
        int producedEventTypeId = filteringStrategy.doFilter(eventFilter, dataKey, dataOldValue, dataNewValue, eventType, null);
        if (producedEventTypeId == FilteringStrategy.FILTER_DOES_NOT_MATCH) {
            eventType = null;
        } else {
            eventType = EntryEventType.getByType(producedEventTypeId);
        }
    }
    if (eventType == null) {
        return null;
    }
    boolean includeValue = isIncludeValue(eventFilter);
    return newQueryCacheEventDataBuilder(includeValue).withPartitionId(partitionId).withDataKey(dataKey).withDataNewValue(dataNewValue).withEventType(eventType.getType()).withDataOldValue(dataOldValue).withSerializationService((serializationService)).build();
}
Also used : EntryEventType(com.hazelcast.core.EntryEventType) EventFilter(com.hazelcast.spi.EventFilter)

Example 4 with EventFilter

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

the class MapEventPublisherImpl method publishMapEvent.

@Override
public void publishMapEvent(Address caller, String mapName, EntryEventType eventType, int numberOfEntriesAffected) {
    Collection<EventRegistration> mapsListenerRegistrations = getRegistrations(mapName);
    if (isEmpty(mapsListenerRegistrations)) {
        return;
    }
    Collection<EventRegistration> registrations = null;
    for (EventRegistration registration : mapsListenerRegistrations) {
        EventFilter filter = registration.getFilter();
        if (filter instanceof EventListenerFilter) {
            if (!filter.eval(eventType.getType())) {
                continue;
            }
        }
        if (!(filter instanceof MapPartitionLostEventFilter)) {
            if (registrations == null) {
                registrations = new ArrayList<EventRegistration>();
            }
            registrations.add(registration);
        }
    }
    if (isEmpty(registrations)) {
        return;
    }
    String source = getThisNodesAddress();
    MapEventData mapEventData = new MapEventData(source, mapName, caller, eventType.getType(), numberOfEntriesAffected);
    publishEventInternal(registrations, mapEventData, mapName.hashCode());
}
Also used : EventRegistration(com.hazelcast.spi.EventRegistration) MapPartitionLostEventFilter(com.hazelcast.map.impl.MapPartitionLostEventFilter) 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) EventListenerFilter(com.hazelcast.map.impl.EventListenerFilter)

Example 5 with EventFilter

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

the class NodeQueryCacheEventService method publishLocalEvent.

// TODO needs refactoring.
private void publishLocalEvent(String mapName, String cacheName, Object eventData) {
    String listenerName = generateListenerName(mapName, cacheName);
    Collection<EventRegistration> eventRegistrations = getRegistrations(listenerName);
    if (eventRegistrations.isEmpty()) {
        return;
    }
    for (EventRegistration eventRegistration : eventRegistrations) {
        Registration registration = (Registration) eventRegistration;
        Object listener = registration.getListener();
        if (!(listener instanceof QueryCacheListenerAdapter)) {
            continue;
        }
        Object eventDataToPublish = eventData;
        int orderKey = -1;
        if (eventDataToPublish instanceof LocalCacheWideEventData) {
            orderKey = listenerName.hashCode();
        } else if (eventDataToPublish instanceof LocalEntryEventData) {
            LocalEntryEventData localEntryEventData = (LocalEntryEventData) eventDataToPublish;
            if (localEntryEventData.getEventType() != EventLostEvent.EVENT_TYPE) {
                EventFilter filter = registration.getFilter();
                if (!canPassFilter(localEntryEventData, filter)) {
                    continue;
                } else {
                    boolean includeValue = isIncludeValue(filter);
                    eventDataToPublish = includeValue ? localEntryEventData : localEntryEventData.cloneWithoutValue();
                    Data keyData = localEntryEventData.getKeyData();
                    orderKey = keyData == null ? -1 : keyData.hashCode();
                }
            }
        }
        publishEventInternal(registration, eventDataToPublish, orderKey);
    }
}
Also used : EventRegistration(com.hazelcast.spi.EventRegistration) LocalEntryEventData(com.hazelcast.map.impl.querycache.event.LocalEntryEventData) Registration(com.hazelcast.spi.impl.eventservice.impl.Registration) EventRegistration(com.hazelcast.spi.EventRegistration) QueryCacheListenerAdapter(com.hazelcast.map.impl.querycache.QueryCacheListenerAdapter) LocalCacheWideEventData(com.hazelcast.map.impl.querycache.event.LocalCacheWideEventData) EventData(com.hazelcast.map.impl.event.EventData) Data(com.hazelcast.nio.serialization.Data) LocalEntryEventData(com.hazelcast.map.impl.querycache.event.LocalEntryEventData) EntryEventFilter(com.hazelcast.map.impl.EntryEventFilter) TrueEventFilter(com.hazelcast.spi.impl.eventservice.impl.TrueEventFilter) EventFilter(com.hazelcast.spi.EventFilter) LocalCacheWideEventData(com.hazelcast.map.impl.querycache.event.LocalCacheWideEventData)

Aggregations

EventFilter (com.hazelcast.spi.EventFilter)20 TrueEventFilter (com.hazelcast.spi.impl.eventservice.impl.TrueEventFilter)8 EntryEventFilter (com.hazelcast.map.impl.EntryEventFilter)7 EventRegistration (com.hazelcast.spi.EventRegistration)7 QueryEventFilter (com.hazelcast.map.impl.query.QueryEventFilter)5 QueryCacheEventService (com.hazelcast.map.impl.querycache.QueryCacheEventService)3 ReplicatedEntryEventFilter (com.hazelcast.replicatedmap.impl.record.ReplicatedEntryEventFilter)3 ReplicatedQueryEventFilter (com.hazelcast.replicatedmap.impl.record.ReplicatedQueryEventFilter)3 CachePartitionLostEventFilter (com.hazelcast.cache.impl.event.CachePartitionLostEventFilter)2 InternalCachePartitionLostListenerAdapter (com.hazelcast.cache.impl.event.InternalCachePartitionLostListenerAdapter)2 ClientEndpoint (com.hazelcast.client.ClientEndpoint)2 ListenerAdapters.createListenerAdapter (com.hazelcast.map.impl.ListenerAdapters.createListenerAdapter)2 MapPartitionLostEventFilter (com.hazelcast.map.impl.MapPartitionLostEventFilter)2 Data (com.hazelcast.nio.serialization.Data)2 CacheService (com.hazelcast.cache.impl.CacheService)1 ICacheService (com.hazelcast.cache.impl.ICacheService)1 CachePartitionLostEvent (com.hazelcast.cache.impl.event.CachePartitionLostEvent)1 CachePartitionLostListener (com.hazelcast.cache.impl.event.CachePartitionLostListener)1 ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)1 EntryListenerConfig (com.hazelcast.config.EntryListenerConfig)1