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 + "]");
}
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);
}
}
}
}
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()));
}
}
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);
}
}
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;
}
Aggregations