Search in sources :

Example 1 with EntryEventData

use of com.hazelcast.map.impl.event.EntryEventData in project hazelcast by hazelcast.

the class ReplicatedMapEventPublishingService method fireEntryListenerEvent.

public void fireEntryListenerEvent(Data key, Data oldValue, Data value, EntryEventType eventType, String name, Address caller) {
    Collection<EventRegistration> registrations = eventService.getRegistrations(SERVICE_NAME, name);
    if (registrations.isEmpty()) {
        return;
    }
    EntryEventData eventData = new EntryEventData(name, name, caller, key, value, oldValue, eventType.getType());
    for (EventRegistration registration : registrations) {
        if (!shouldPublish(key, oldValue, value, eventType, registration.getFilter())) {
            continue;
        }
        eventService.publishEvent(SERVICE_NAME, registration, eventData, key.hashCode());
    }
}
Also used : EventRegistration(com.hazelcast.spi.EventRegistration) EntryEventData(com.hazelcast.map.impl.event.EntryEventData)

Example 2 with EntryEventData

use of com.hazelcast.map.impl.event.EntryEventData in project hazelcast by hazelcast.

the class ReplicatedMapEventPublishingService method dispatchEvent.

@Override
public void dispatchEvent(Object event, Object listener) {
    if ((event instanceof EntryEventData)) {
        EntryEventData entryEventData = (EntryEventData) event;
        Member member = getMember(entryEventData);
        EntryEvent entryEvent = createDataAwareEntryEvent(entryEventData, member);
        EntryListener entryListener = (EntryListener) listener;
        switch(entryEvent.getEventType()) {
            case ADDED:
                entryListener.entryAdded(entryEvent);
                break;
            case EVICTED:
                entryListener.entryEvicted(entryEvent);
                break;
            case UPDATED:
                entryListener.entryUpdated(entryEvent);
                break;
            case REMOVED:
                entryListener.entryRemoved(entryEvent);
                break;
            default:
                throw new IllegalArgumentException("event type " + entryEvent.getEventType() + " not supported");
        }
        String mapName = ((EntryEventData) event).getMapName();
        Boolean statisticsEnabled = statisticsMap.get(mapName);
        if (statisticsEnabled == null) {
            ReplicatedMapConfig mapConfig = config.findReplicatedMapConfig(mapName);
            statisticsEnabled = mapConfig.isStatisticsEnabled();
            statisticsMap.put(mapName, statisticsEnabled);
        }
        if (statisticsEnabled) {
            int partitionId = nodeEngine.getPartitionService().getPartitionId(entryEventData.getDataKey());
            ReplicatedRecordStore recordStore = replicatedMapService.getPartitionContainer(partitionId).getRecordStore(mapName);
            if (recordStore instanceof AbstractReplicatedRecordStore) {
                LocalReplicatedMapStatsImpl stats = ((AbstractReplicatedRecordStore) recordStore).getStats();
                stats.incrementReceivedEvents();
            }
        }
    } else if (event instanceof MapEventData) {
        MapEventData mapEventData = (MapEventData) event;
        Member member = getMember(mapEventData);
        MapEvent mapEvent = new MapEvent(mapEventData.getMapName(), member, mapEventData.getEventType(), mapEventData.getNumberOfEntries());
        EntryListener entryListener = (EntryListener) listener;
        EntryEventType type = EntryEventType.getByType(mapEventData.getEventType());
        switch(type) {
            case CLEAR_ALL:
                entryListener.mapCleared(mapEvent);
                break;
            default:
                throw new IllegalArgumentException("event type " + type + " not supported");
        }
    }
}
Also used : AbstractReplicatedRecordStore(com.hazelcast.replicatedmap.impl.record.AbstractReplicatedRecordStore) MapEvent(com.hazelcast.core.MapEvent) MapEventData(com.hazelcast.map.impl.event.MapEventData) EntryListener(com.hazelcast.core.EntryListener) EntryEventType(com.hazelcast.core.EntryEventType) LocalReplicatedMapStatsImpl(com.hazelcast.monitor.impl.LocalReplicatedMapStatsImpl) AbstractReplicatedRecordStore(com.hazelcast.replicatedmap.impl.record.AbstractReplicatedRecordStore) ReplicatedRecordStore(com.hazelcast.replicatedmap.impl.record.ReplicatedRecordStore) DataAwareEntryEvent(com.hazelcast.map.impl.DataAwareEntryEvent) EntryEvent(com.hazelcast.core.EntryEvent) ReplicatedMapConfig(com.hazelcast.config.ReplicatedMapConfig) EntryEventData(com.hazelcast.map.impl.event.EntryEventData) Member(com.hazelcast.core.Member)

Example 3 with EntryEventData

use of com.hazelcast.map.impl.event.EntryEventData in project hazelcast by hazelcast.

the class MultiMapEventsDispatcher method dispatchEntryEventData.

private void dispatchEntryEventData(EventData eventData, EntryListener listener) {
    final EntryEventData entryEventData = (EntryEventData) eventData;
    final Member member = getMemberOrNull(eventData);
    final EntryEvent event = createDataAwareEntryEvent(entryEventData, member);
    dispatch0(event, listener);
    incrementEventStats(event);
}
Also used : EntryEvent(com.hazelcast.core.EntryEvent) DataAwareEntryEvent(com.hazelcast.map.impl.DataAwareEntryEvent) EntryEventData(com.hazelcast.map.impl.event.EntryEventData) Member(com.hazelcast.core.Member)

Example 4 with EntryEventData

use of com.hazelcast.map.impl.event.EntryEventData 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 5 with EntryEventData

use of com.hazelcast.map.impl.event.EntryEventData in project hazelcast by hazelcast.

the class DefaultRecordStore method addEventToQueryCache.

private void addEventToQueryCache(Record record) {
    EntryEventData eventData = new EntryEventData(thisAddress.toString(), name, thisAddress, record.getKey(), mapServiceContext.toData(record.getValue()), null, null, ADDED.getType());
    mapEventPublisher.addEventToQueryCache(eventData);
}
Also used : EntryEventData(com.hazelcast.map.impl.event.EntryEventData)

Aggregations

EntryEventData (com.hazelcast.map.impl.event.EntryEventData)5 EntryEvent (com.hazelcast.core.EntryEvent)2 Member (com.hazelcast.core.Member)2 DataAwareEntryEvent (com.hazelcast.map.impl.DataAwareEntryEvent)2 MapEventData (com.hazelcast.map.impl.event.MapEventData)2 EventRegistration (com.hazelcast.spi.EventRegistration)2 ReplicatedMapConfig (com.hazelcast.config.ReplicatedMapConfig)1 EntryEventType (com.hazelcast.core.EntryEventType)1 EntryListener (com.hazelcast.core.EntryListener)1 MapEvent (com.hazelcast.core.MapEvent)1 LocalReplicatedMapStatsImpl (com.hazelcast.monitor.impl.LocalReplicatedMapStatsImpl)1 Address (com.hazelcast.nio.Address)1 Data (com.hazelcast.nio.serialization.Data)1 AbstractReplicatedRecordStore (com.hazelcast.replicatedmap.impl.record.AbstractReplicatedRecordStore)1 ReplicatedRecordStore (com.hazelcast.replicatedmap.impl.record.ReplicatedRecordStore)1 EventService (com.hazelcast.spi.EventService)1