Search in sources :

Example 1 with MapEventData

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

the class MultiMapEventsDispatcher method dispatchMapEventData.

private void dispatchMapEventData(EventData eventData, EntryListener listener) {
    MapEventData mapEventData = (MapEventData) eventData;
    Member member = getMemberOrNull(eventData);
    if (member == null) {
        return;
    }
    MapEvent event = createMapEvent(mapEventData, member);
    dispatch0(event, listener);
    incrementEventStats(event);
}
Also used : IMapEvent(com.hazelcast.map.IMapEvent) MapEvent(com.hazelcast.map.MapEvent) MapEventData(com.hazelcast.map.impl.event.MapEventData) Member(com.hazelcast.cluster.Member)

Example 2 with MapEventData

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

the class ReplicatedMapEventPublishingService method fireMapClearedEvent.

public void fireMapClearedEvent(int deletedEntrySize, String name) {
    EventService eventService = nodeEngine.getEventService();
    Collection<EventRegistration> registrations = eventService.getRegistrations(SERVICE_NAME, name);
    if (registrations.isEmpty()) {
        return;
    }
    MapEventData mapEventData = new MapEventData(name, name, nodeEngine.getThisAddress(), EntryEventType.CLEAR_ALL.getType(), deletedEntrySize);
    eventService.publishEvent(SERVICE_NAME, registrations, mapEventData, name.hashCode());
}
Also used : EventRegistration(com.hazelcast.spi.impl.eventservice.EventRegistration) EventService(com.hazelcast.spi.impl.eventservice.EventService) MapEventData(com.hazelcast.map.impl.event.MapEventData)

Example 3 with MapEventData

use of com.hazelcast.map.impl.event.MapEventData 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());
        if (type == EntryEventType.CLEAR_ALL) {
            entryListener.mapCleared(mapEvent);
        } else {
            throw new IllegalArgumentException("Unsupported EntryEventType: " + type);
        }
    }
}
Also used : AbstractReplicatedRecordStore(com.hazelcast.replicatedmap.impl.record.AbstractReplicatedRecordStore) MapEvent(com.hazelcast.map.MapEvent) MapEventData(com.hazelcast.map.impl.event.MapEventData) EntryListener(com.hazelcast.core.EntryListener) EntryEventType(com.hazelcast.core.EntryEventType) LocalReplicatedMapStatsImpl(com.hazelcast.internal.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.cluster.Member)

Example 4 with MapEventData

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

the class MultiMapEventsPublisher method publishMultiMapEvent.

public void publishMultiMapEvent(String mapName, EntryEventType eventType, int numberOfEntriesAffected) {
    EventService eventService = nodeEngine.getEventService();
    Collection<EventRegistration> registrations = eventService.getRegistrations(MultiMapService.SERVICE_NAME, mapName);
    if (registrations.isEmpty()) {
        return;
    }
    Address caller = nodeEngine.getThisAddress();
    String source = caller.toString();
    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.impl.eventservice.EventRegistration) Address(com.hazelcast.cluster.Address) EventService(com.hazelcast.spi.impl.eventservice.EventService) MapEventData(com.hazelcast.map.impl.event.MapEventData)

Aggregations

MapEventData (com.hazelcast.map.impl.event.MapEventData)4 Member (com.hazelcast.cluster.Member)2 MapEvent (com.hazelcast.map.MapEvent)2 EventRegistration (com.hazelcast.spi.impl.eventservice.EventRegistration)2 EventService (com.hazelcast.spi.impl.eventservice.EventService)2 Address (com.hazelcast.cluster.Address)1 ReplicatedMapConfig (com.hazelcast.config.ReplicatedMapConfig)1 EntryEvent (com.hazelcast.core.EntryEvent)1 EntryEventType (com.hazelcast.core.EntryEventType)1 EntryListener (com.hazelcast.core.EntryListener)1 LocalReplicatedMapStatsImpl (com.hazelcast.internal.monitor.impl.LocalReplicatedMapStatsImpl)1 IMapEvent (com.hazelcast.map.IMapEvent)1 DataAwareEntryEvent (com.hazelcast.map.impl.DataAwareEntryEvent)1 EntryEventData (com.hazelcast.map.impl.event.EntryEventData)1 AbstractReplicatedRecordStore (com.hazelcast.replicatedmap.impl.record.AbstractReplicatedRecordStore)1 ReplicatedRecordStore (com.hazelcast.replicatedmap.impl.record.ReplicatedRecordStore)1