Search in sources :

Example 6 with QueryCacheEventData

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

the class MapAddListenerMessageTask method getEventData.

private ClientMessage getEventData(IMapEvent iMapEvent) {
    if (iMapEvent instanceof SingleIMapEvent) {
        QueryCacheEventData eventData = ((SingleIMapEvent) iMapEvent).getEventData();
        ClientMessage clientMessage = ContinuousQueryAddListenerCodec.encodeQueryCacheSingleEvent(eventData);
        int partitionId = eventData.getPartitionId();
        clientMessage.setPartitionId(partitionId);
        return clientMessage;
    }
    if (iMapEvent instanceof BatchIMapEvent) {
        BatchIMapEvent batchIMapEvent = (BatchIMapEvent) iMapEvent;
        BatchEventData batchEventData = batchIMapEvent.getBatchEventData();
        int partitionId = batchEventData.getPartitionId();
        ClientMessage clientMessage = ContinuousQueryAddListenerCodec.encodeQueryCacheBatchEvent(batchEventData.getEvents(), batchEventData.getSource(), partitionId);
        clientMessage.setPartitionId(partitionId);
        return clientMessage;
    }
    throw new IllegalArgumentException("Unexpected event type found = [" + iMapEvent + "]");
}
Also used : BatchEventData(com.hazelcast.map.impl.querycache.event.BatchEventData) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) BatchIMapEvent(com.hazelcast.map.impl.querycache.event.BatchIMapEvent) SingleIMapEvent(com.hazelcast.map.impl.querycache.event.SingleIMapEvent) QueryCacheEventData(com.hazelcast.map.impl.querycache.event.QueryCacheEventData) ClientEndpoint(com.hazelcast.client.ClientEndpoint)

Example 7 with QueryCacheEventData

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

the class AccumulatorSweeper method flushAllAccumulators.

public static void flushAllAccumulators(PublisherContext publisherContext) {
    QueryCacheContext context = publisherContext.getContext();
    EventPublisherAccumulatorProcessor processor = new EventPublisherAccumulatorProcessor(context.getQueryCacheEventService());
    PublisherAccumulatorHandler handler = new PublisherAccumulatorHandler(context, processor);
    MapPublisherRegistry mapPublisherRegistry = publisherContext.getMapPublisherRegistry();
    Map<String, PublisherRegistry> allPublisherRegistryMap = mapPublisherRegistry.getAll();
    for (PublisherRegistry publisherRegistry : allPublisherRegistryMap.values()) {
        Map<String, PartitionAccumulatorRegistry> accumulatorRegistryMap = publisherRegistry.getAll();
        for (PartitionAccumulatorRegistry accumulatorRegistry : accumulatorRegistryMap.values()) {
            Map<Integer, Accumulator> accumulatorMap = accumulatorRegistry.getAll();
            for (Map.Entry<Integer, Accumulator> entry : accumulatorMap.entrySet()) {
                Integer partitionId = entry.getKey();
                Accumulator accumulator = entry.getValue();
                processor.setInfo(accumulator.getInfo());
                // give 0 to delay-time in order to fetch all events in the accumulator
                accumulator.poll(handler, 0, TimeUnit.SECONDS);
                // send end event
                QueryCacheEventData eventData = createEndOfSequenceEvent(partitionId);
                processor.process(eventData);
            }
        }
    }
}
Also used : Accumulator(com.hazelcast.map.impl.querycache.accumulator.Accumulator) QueryCacheContext(com.hazelcast.map.impl.querycache.QueryCacheContext) Map(java.util.Map) QueryCacheEventData(com.hazelcast.map.impl.querycache.event.QueryCacheEventData)

Example 8 with QueryCacheEventData

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

the class CoalescingPublisherAccumulator method setSequence.

private void setSequence(QueryCacheEventData eventData) {
    Data dataKey = eventData.getDataKey();
    Long sequence = index.get(dataKey);
    if (sequence != null) {
        eventData.setSequence(sequence);
    } else {
        long nextSequence = partitionSequencer.nextSequence();
        eventData.setSequence(nextSequence);
        index.put(dataKey, nextSequence);
    }
    if (logger.isFinestEnabled()) {
        logger.finest(format("Added to index key=%s, sequence=%d, indexSize=%d", eventData.getKey(), eventData.getSequence(), index.size()));
    }
}
Also used : Data(com.hazelcast.nio.serialization.Data) QueryCacheEventData(com.hazelcast.map.impl.querycache.event.QueryCacheEventData) BatchEventData(com.hazelcast.map.impl.querycache.event.BatchEventData)

Example 9 with QueryCacheEventData

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

the class PublisherAccumulatorHandler method process.

private void process() {
    Queue<QueryCacheEventData> eventCollection = this.eventCollection;
    if (eventCollection.isEmpty()) {
        return;
    }
    if (eventCollection.size() < 2) {
        QueryCacheEventData eventData = eventCollection.poll();
        processor.process(eventData);
    } else {
        sendInBatches(eventCollection);
    }
}
Also used : QueryCacheEventData(com.hazelcast.map.impl.querycache.event.QueryCacheEventData)

Example 10 with QueryCacheEventData

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

the class PublisherAccumulatorHandler method createPartitionToEventDataMap.

private Map<Integer, List<QueryCacheEventData>> createPartitionToEventDataMap(Queue<QueryCacheEventData> events) {
    if (events.isEmpty()) {
        return Collections.emptyMap();
    }
    Map<Integer, List<QueryCacheEventData>> map = new HashMap<Integer, List<QueryCacheEventData>>();
    do {
        QueryCacheEventData eventData = events.poll();
        if (eventData == null) {
            break;
        }
        int partitionId = eventData.getPartitionId();
        List<QueryCacheEventData> eventDataList = map.get(partitionId);
        if (eventDataList == null) {
            eventDataList = new ArrayList<QueryCacheEventData>();
            map.put(partitionId, eventDataList);
        }
        eventDataList.add(eventData);
    } while (true);
    return map;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) QueryCacheEventData(com.hazelcast.map.impl.querycache.event.QueryCacheEventData)

Aggregations

QueryCacheEventData (com.hazelcast.map.impl.querycache.event.QueryCacheEventData)12 BatchEventData (com.hazelcast.map.impl.querycache.event.BatchEventData)4 Accumulator (com.hazelcast.map.impl.querycache.accumulator.Accumulator)3 Data (com.hazelcast.nio.serialization.Data)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 QueryResultRow (com.hazelcast.map.impl.query.QueryResultRow)2 QueryCacheContext (com.hazelcast.map.impl.querycache.QueryCacheContext)2 BatchIMapEvent (com.hazelcast.map.impl.querycache.event.BatchIMapEvent)2 SingleIMapEvent (com.hazelcast.map.impl.querycache.event.SingleIMapEvent)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 ClientEndpoint (com.hazelcast.client.ClientEndpoint)1 ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)1 EntryEventType (com.hazelcast.core.EntryEventType)1 DefaultQueryCacheEventData (com.hazelcast.map.impl.querycache.event.DefaultQueryCacheEventData)1 PartitionAccumulatorRegistry (com.hazelcast.map.impl.querycache.publisher.PartitionAccumulatorRegistry)1