Search in sources :

Example 16 with EventFilter

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

the class MapServiceContextImpl method addPartitionLostListener.

@Override
public UUID 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.impl.eventservice.EventRegistration) EventFilter(com.hazelcast.spi.impl.eventservice.EventFilter)

Example 17 with EventFilter

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

the class ReplicatedMapProxy method addEntryListener.

@Nonnull
@Override
public UUID addEntryListener(@Nonnull EntryListener<K, V> listener, @Nonnull Predicate<K, V> predicate, @Nullable K key) {
    checkNotNull(listener, NULL_LISTENER_IS_NOT_ALLOWED);
    checkNotNull(predicate, NULL_PREDICATE_IS_NOT_ALLOWED);
    EventFilter eventFilter = new ReplicatedQueryEventFilter(serializationService.toData(key), predicate);
    return eventPublishingService.addLocalEventListener(listener, eventFilter, name);
}
Also used : ReplicatedQueryEventFilter(com.hazelcast.replicatedmap.impl.record.ReplicatedQueryEventFilter) ReplicatedQueryEventFilter(com.hazelcast.replicatedmap.impl.record.ReplicatedQueryEventFilter) TrueEventFilter(com.hazelcast.spi.impl.eventservice.impl.TrueEventFilter) ReplicatedEntryEventFilter(com.hazelcast.replicatedmap.impl.record.ReplicatedEntryEventFilter) EventFilter(com.hazelcast.spi.impl.eventservice.EventFilter) Nonnull(javax.annotation.Nonnull)

Example 18 with EventFilter

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

the class ReplicatedMapProxy method addEntryListener.

@Nonnull
@Override
public UUID addEntryListener(@Nonnull EntryListener<K, V> listener, @Nullable K key) {
    checkNotNull(listener, NULL_LISTENER_IS_NOT_ALLOWED);
    EventFilter eventFilter = new ReplicatedEntryEventFilter(serializationService.toData(key));
    return eventPublishingService.addLocalEventListener(listener, eventFilter, name);
}
Also used : ReplicatedEntryEventFilter(com.hazelcast.replicatedmap.impl.record.ReplicatedEntryEventFilter) ReplicatedQueryEventFilter(com.hazelcast.replicatedmap.impl.record.ReplicatedQueryEventFilter) TrueEventFilter(com.hazelcast.spi.impl.eventservice.impl.TrueEventFilter) ReplicatedEntryEventFilter(com.hazelcast.replicatedmap.impl.record.ReplicatedEntryEventFilter) EventFilter(com.hazelcast.spi.impl.eventservice.EventFilter) Nonnull(javax.annotation.Nonnull)

Example 19 with EventFilter

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

the class DefaultQueryCache method addEntryListenerInternal.

private UUID addEntryListenerInternal(MapListener listener, K key, boolean includeValue) {
    checkNotNull(listener, "listener cannot be null");
    Data keyData = toData(key);
    EventFilter filter = new EntryEventFilter(keyData, includeValue);
    QueryCacheEventService eventService = getEventService();
    String mapName = delegate.getName();
    return eventService.addListener(mapName, cacheId, listener, filter);
}
Also used : QueryCacheEventService(com.hazelcast.map.impl.querycache.QueryCacheEventService) EntryEventFilter(com.hazelcast.map.impl.EntryEventFilter) Data(com.hazelcast.internal.serialization.Data) EntryEventFilter(com.hazelcast.map.impl.EntryEventFilter) QueryEventFilter(com.hazelcast.map.impl.query.QueryEventFilter) EventFilter(com.hazelcast.spi.impl.eventservice.EventFilter)

Example 20 with EventFilter

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

the class NodeQueryCacheEventService method publishLocalEvent.

// TODO needs refactoring.
private void publishLocalEvent(String cacheId, Object eventData, Extractors extractors) {
    Collection<EventRegistration> eventRegistrations = getRegistrations(cacheId);
    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 = cacheId.hashCode();
        } else if (eventDataToPublish instanceof LocalEntryEventData) {
            LocalEntryEventData localEntryEventData = (LocalEntryEventData) eventDataToPublish;
            if (localEntryEventData.getEventType() != EventLostEvent.EVENT_TYPE) {
                EventFilter filter = registration.getFilter();
                if (!canPassFilter(localEntryEventData, filter, extractors)) {
                    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.impl.eventservice.EventRegistration) LocalEntryEventData(com.hazelcast.map.impl.querycache.event.LocalEntryEventData) EventRegistration(com.hazelcast.spi.impl.eventservice.EventRegistration) Registration(com.hazelcast.spi.impl.eventservice.impl.Registration) 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.internal.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.impl.eventservice.EventFilter) LocalCacheWideEventData(com.hazelcast.map.impl.querycache.event.LocalCacheWideEventData)

Aggregations

EventFilter (com.hazelcast.spi.impl.eventservice.EventFilter)21 EntryEventFilter (com.hazelcast.map.impl.EntryEventFilter)7 EventRegistration (com.hazelcast.spi.impl.eventservice.EventRegistration)7 TrueEventFilter (com.hazelcast.spi.impl.eventservice.impl.TrueEventFilter)6 QueryEventFilter (com.hazelcast.map.impl.query.QueryEventFilter)5 ListenerAdapters.createListenerAdapter (com.hazelcast.map.impl.ListenerAdapters.createListenerAdapter)3 QueryCacheEventService (com.hazelcast.map.impl.querycache.QueryCacheEventService)3 ReplicatedEntryEventFilter (com.hazelcast.replicatedmap.impl.record.ReplicatedEntryEventFilter)3 ReplicatedQueryEventFilter (com.hazelcast.replicatedmap.impl.record.ReplicatedQueryEventFilter)3 Nonnull (javax.annotation.Nonnull)3 CachePartitionLostEventFilter (com.hazelcast.cache.impl.event.CachePartitionLostEventFilter)2 InternalCachePartitionLostListenerAdapter (com.hazelcast.cache.impl.event.InternalCachePartitionLostListenerAdapter)2 Data (com.hazelcast.internal.serialization.Data)2 MapPartitionLostEventFilter (com.hazelcast.map.impl.MapPartitionLostEventFilter)2 UUID (java.util.UUID)2 CacheService (com.hazelcast.cache.impl.CacheService)1 ICacheService (com.hazelcast.cache.impl.ICacheService)1 CachePartitionLostListener (com.hazelcast.cache.impl.event.CachePartitionLostListener)1 ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)1 CacheAddPartitionLostListenerCodec (com.hazelcast.client.impl.protocol.codec.CacheAddPartitionLostListenerCodec)1