Search in sources :

Example 1 with DefaultQueryCacheEventData

use of com.hazelcast.map.impl.querycache.event.DefaultQueryCacheEventData in project hazelcast by hazelcast.

the class QueryCacheEventPublisher method addEventToQueryCache.

public void addEventToQueryCache(Object eventData) {
    checkInstanceOf(EventData.class, eventData, "eventData");
    String mapName = ((EventData) eventData).getMapName();
    int eventType = ((EventData) eventData).getEventType();
    // only handling EVICTED event for that key is sufficient
    if (EXPIRED.getType() == eventType) {
        return;
    }
    // this collection contains all defined query-caches on an IMap
    Collection<PartitionAccumulatorRegistry> partitionAccumulatorRegistries = getPartitionAccumulatorRegistries(mapName);
    if (isEmpty(partitionAccumulatorRegistries)) {
        return;
    }
    if (!(eventData instanceof EntryEventData)) {
        return;
    }
    EntryEventData entryEvenData = (EntryEventData) eventData;
    Data dataKey = entryEvenData.getDataKey();
    Data dataNewValue = entryEvenData.getDataNewValue();
    Data dataOldValue = entryEvenData.getDataOldValue();
    int partitionId = queryCacheContext.getPartitionId(entryEvenData.dataKey);
    for (PartitionAccumulatorRegistry registry : partitionAccumulatorRegistries) {
        DefaultQueryCacheEventData singleEventData = (DefaultQueryCacheEventData) convertQueryCacheEventDataOrNull(registry, dataKey, dataNewValue, dataOldValue, eventType, partitionId);
        if (singleEventData == null) {
            continue;
        }
        Accumulator accumulator = registry.getOrCreate(partitionId);
        accumulator.accumulate(singleEventData);
    }
}
Also used : Accumulator(com.hazelcast.map.impl.querycache.accumulator.Accumulator) PartitionAccumulatorRegistry(com.hazelcast.map.impl.querycache.publisher.PartitionAccumulatorRegistry) DefaultQueryCacheEventData(com.hazelcast.map.impl.querycache.event.DefaultQueryCacheEventData) Data(com.hazelcast.nio.serialization.Data) DefaultQueryCacheEventData(com.hazelcast.map.impl.querycache.event.DefaultQueryCacheEventData) QueryCacheEventData(com.hazelcast.map.impl.querycache.event.QueryCacheEventData) DefaultQueryCacheEventData(com.hazelcast.map.impl.querycache.event.DefaultQueryCacheEventData) QueryCacheEventData(com.hazelcast.map.impl.querycache.event.QueryCacheEventData)

Aggregations

Accumulator (com.hazelcast.map.impl.querycache.accumulator.Accumulator)1 DefaultQueryCacheEventData (com.hazelcast.map.impl.querycache.event.DefaultQueryCacheEventData)1 QueryCacheEventData (com.hazelcast.map.impl.querycache.event.QueryCacheEventData)1 PartitionAccumulatorRegistry (com.hazelcast.map.impl.querycache.publisher.PartitionAccumulatorRegistry)1 Data (com.hazelcast.nio.serialization.Data)1