Search in sources :

Example 16 with EntryEventType

use of com.hazelcast.core.EntryEventType in project hazelcast by hazelcast.

the class PartitionWideEntryOperation method runWithPartitionScanForNative.

// TODO unify this method with `runWithPartitionScan`
private void runWithPartitionScanForNative() {
    // if we reach here, it means we didn't manage to leverage index and we fall-back to full-partition scan
    int totalEntryCount = recordStore.size();
    responses = new MapEntries(totalEntryCount);
    Queue<Object> outComes = new LinkedList<>();
    operator = operator(this, entryProcessor, getPredicate());
    recordStore.forEach((key, record) -> {
        Data dataKey = toHeapData(key);
        Data response = operator.operateOnKey(dataKey).getResult();
        if (response != null) {
            responses.add(dataKey, response);
        }
        EntryEventType eventType = operator.getEventType();
        if (eventType != null) {
            outComes.add(dataKey);
            outComes.add(operator.getOldValue());
            outComes.add(operator.getByPreferringDataNewValue());
            outComes.add(eventType);
            outComes.add(operator.getEntry().getNewTtl());
        }
    }, false);
    // in this case, iteration can miss some entries.
    while (!outComes.isEmpty()) {
        Data dataKey = (Data) outComes.poll();
        Object oldValue = outComes.poll();
        Object newValue = outComes.poll();
        EntryEventType eventType = (EntryEventType) outComes.poll();
        long newTtl = (long) outComes.poll();
        operator.init(dataKey, oldValue, newValue, null, eventType, null, newTtl).doPostOperateOps();
    }
}
Also used : EntryEventType(com.hazelcast.core.EntryEventType) MapEntries(com.hazelcast.map.impl.MapEntries) ToHeapDataConverter.toHeapData(com.hazelcast.internal.util.ToHeapDataConverter.toHeapData) Data(com.hazelcast.internal.serialization.Data) LinkedList(java.util.LinkedList)

Example 17 with EntryEventType

use of com.hazelcast.core.EntryEventType in project hazelcast by hazelcast.

the class AbstractEvictableRecordStore method doPostEvictionOperations.

@Override
public void doPostEvictionOperations(Data dataKey, Object value, ExpiryReason expiryReason) {
    if (eventService.hasEventRegistration(SERVICE_NAME, name)) {
        EntryEventType eventType = expiryReason != NOT_EXPIRED ? EXPIRED : EVICTED;
        mapEventPublisher.publishEvent(thisAddress, name, eventType, dataKey, value, null);
    }
    if (expiryReason == MAX_IDLE_SECONDS) {
        // only send expired key to back-up if
        // it is expired according to idleness.
        expirySystem.accumulateOrSendExpiredKey(dataKey, value.hashCode());
    }
}
Also used : EntryEventType(com.hazelcast.core.EntryEventType)

Example 18 with EntryEventType

use of com.hazelcast.core.EntryEventType 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 19 with EntryEventType

use of com.hazelcast.core.EntryEventType in project hazelcast by hazelcast.

the class MapListenerFlagOperator method setAndGetAllListenerFlags.

/**
 * Sets and gets all listener flags.
 */
private static int setAndGetAllListenerFlags() {
    int listenerFlags = 0;
    EntryEventType[] values = EntryEventType.values();
    for (EntryEventType eventType : values) {
        listenerFlags = listenerFlags | eventType.getType();
    }
    return listenerFlags;
}
Also used : EntryEventType(com.hazelcast.core.EntryEventType)

Example 20 with EntryEventType

use of com.hazelcast.core.EntryEventType in project hazelcast by hazelcast.

the class InternalMapListenerAdapter method onEvent.

@Override
public void onEvent(IMapEvent event) {
    EntryEventType eventType = event.getEventType();
    if (eventType == null) {
        return;
    }
    ListenerAdapter listenerAdapter = listenerAdapters[eventType.ordinal()];
    if (listenerAdapter == null) {
        return;
    }
    listenerAdapter.onEvent(event);
}
Also used : EntryEventType(com.hazelcast.core.EntryEventType)

Aggregations

EntryEventType (com.hazelcast.core.EntryEventType)24 Data (com.hazelcast.internal.serialization.Data)3 EntryEvent (com.hazelcast.core.EntryEvent)2 ToHeapDataConverter.toHeapData (com.hazelcast.internal.util.ToHeapDataConverter.toHeapData)2 EntryEventData (com.hazelcast.map.impl.event.EntryEventData)2 Record (com.hazelcast.map.impl.record.Record)2 LinkedList (java.util.LinkedList)2 Map (java.util.Map)2 CacheEventData (com.hazelcast.cache.impl.CacheEventData)1 CacheEventSet (com.hazelcast.cache.impl.CacheEventSet)1 Member (com.hazelcast.cluster.Member)1 CollectionEvent (com.hazelcast.collection.impl.collection.CollectionEvent)1 QueueEvent (com.hazelcast.collection.impl.queue.QueueEvent)1 ReplicatedMapConfig (com.hazelcast.config.ReplicatedMapConfig)1 EntryListener (com.hazelcast.core.EntryListener)1 LocalReplicatedMapStatsImpl (com.hazelcast.internal.monitor.impl.LocalReplicatedMapStatsImpl)1 ConstructorFunction (com.hazelcast.internal.util.ConstructorFunction)1 EventLostEvent (com.hazelcast.map.EventLostEvent)1 MapEvent (com.hazelcast.map.MapEvent)1 DataAwareEntryEvent (com.hazelcast.map.impl.DataAwareEntryEvent)1