Search in sources :

Example 1 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 2 with QueryCacheEventData

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

the class PublisherCreateOperation method replayEventsOnResultSet.

/**
     * Replay the events on returned result-set which are generated during `runInitialQuery` call.
     */
private void replayEventsOnResultSet(final QueryResult queryResult) throws Exception {
    Collection<Object> resultCollection = readAccumulators();
    for (Object result : resultCollection) {
        if (result == null) {
            continue;
        }
        Object toObject = mapServiceContext.toObject(result);
        List<QueryCacheEventData> eventDataList = (List<QueryCacheEventData>) toObject;
        for (QueryCacheEventData eventData : eventDataList) {
            QueryResultRow entry = createQueryResultEntry(eventData);
            add(queryResult, entry);
        }
    }
}
Also used : QueryResultRow(com.hazelcast.map.impl.query.QueryResultRow) ArrayList(java.util.ArrayList) List(java.util.List) QueryCacheEventData(com.hazelcast.map.impl.querycache.event.QueryCacheEventData)

Example 3 with QueryCacheEventData

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

the class PublisherCreateOperation method createQueryResultEntry.

private QueryResultRow createQueryResultEntry(QueryCacheEventData eventData) {
    Data dataKey = eventData.getDataKey();
    Data dataNewValue = eventData.getDataNewValue();
    return new QueryResultRow(dataKey, dataNewValue);
}
Also used : QueryResultRow(com.hazelcast.map.impl.query.QueryResultRow) QueryCacheEventData(com.hazelcast.map.impl.querycache.event.QueryCacheEventData) Data(com.hazelcast.nio.serialization.Data)

Example 4 with QueryCacheEventData

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

the class SubscriberAccumulatorHandler method handle.

@Override
public void handle(QueryCacheEventData eventData, boolean ignored) {
    eventData.setSerializationService(serializationService);
    Data keyData = eventData.getDataKey();
    Data valueData = includeValue ? eventData.getDataNewValue() : null;
    int eventType = eventData.getEventType();
    EntryEventType entryEventType = EntryEventType.getByType(eventType);
    switch(entryEventType) {
        case ADDED:
        case UPDATED:
        case MERGED:
            queryCache.setInternal(keyData, valueData, false, entryEventType);
            break;
        case REMOVED:
        case EVICTED:
            queryCache.deleteInternal(keyData, false, entryEventType);
            break;
        // TODO if we want strongly consistent clear & evict, removal can be made based on sequence and partition-id.
        case CLEAR_ALL:
        case EVICT_ALL:
            queryCache.clearInternal(entryEventType);
            break;
        default:
            throw new IllegalArgumentException("Not a known type EntryEventType." + entryEventType);
    }
}
Also used : EntryEventType(com.hazelcast.core.EntryEventType) Data(com.hazelcast.nio.serialization.Data) QueryCacheEventData(com.hazelcast.map.impl.querycache.event.QueryCacheEventData)

Example 5 with QueryCacheEventData

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

the class PublisherAccumulatorHandler method sendToSubscriber.

private void sendToSubscriber(Map<Integer, List<QueryCacheEventData>> map) {
    Set<Map.Entry<Integer, List<QueryCacheEventData>>> entries = map.entrySet();
    for (Map.Entry<Integer, List<QueryCacheEventData>> entry : entries) {
        Integer partitionId = entry.getKey();
        List<QueryCacheEventData> eventData = entry.getValue();
        String thisNodesAddress = getThisNodesAddress();
        BatchEventData batchEventData = new BatchEventData(eventData, thisNodesAddress, partitionId);
        processor.process(batchEventData);
    }
}
Also used : BatchEventData(com.hazelcast.map.impl.querycache.event.BatchEventData) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) 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