use of com.hazelcast.map.impl.querycache.accumulator.Accumulator in project hazelcast by hazelcast.
the class AccumulatorConsumerOperation method run.
@Override
public void run() throws Exception {
QueryCacheContext context = getQueryCacheContext();
QueryCacheEventService queryCacheEventService = context.getQueryCacheEventService();
EventPublisherAccumulatorProcessor processor = new EventPublisherAccumulatorProcessor(queryCacheEventService);
AccumulatorHandler<Sequenced> handler = new PublisherAccumulatorHandler(context, processor);
int processed = 0;
do {
Accumulator accumulator = accumulators.poll();
if (accumulator == null) {
break;
}
if (isLocal()) {
// consume the accumulator if only this node is the owner
// of accumulators partition
publishAccumulator(processor, handler, accumulator);
} else {
// if the accumulator is not local, it should be a leftover
// stayed after partition migrations and remove that accumulator
removeAccumulator(context, accumulator);
}
processed++;
} while (processed <= maxProcessableAccumulatorCount);
}
use of com.hazelcast.map.impl.querycache.accumulator.Accumulator in project hazelcast by hazelcast.
the class ReadAndResetAccumulatorOperation method run.
@Override
public void run() throws Exception {
QueryCacheContext context = getQueryCacheContext();
Map<Integer, Accumulator> accumulators = getAccumulators(context, name, cacheName);
Accumulator<Sequenced> accumulator = accumulators.get(getPartitionId());
if (accumulator.isEmpty()) {
return;
}
eventDataList = new ArrayList<Sequenced>(accumulator.size());
for (Sequenced sequenced : accumulator) {
eventDataList.add(sequenced);
}
accumulator.reset();
}
use of com.hazelcast.map.impl.querycache.accumulator.Accumulator in project hazelcast by hazelcast.
the class DefaultQueryCache method tryRecover.
@Override
public boolean tryRecover() {
SubscriberContext subscriberContext = context.getSubscriberContext();
MapSubscriberRegistry mapSubscriberRegistry = subscriberContext.getMapSubscriberRegistry();
SubscriberRegistry subscriberRegistry = mapSubscriberRegistry.getOrNull(mapName);
if (subscriberRegistry == null) {
return true;
}
Accumulator accumulator = subscriberRegistry.getOrNull(cacheName);
if (accumulator == null) {
return true;
}
SubscriberAccumulator subscriberAccumulator = (SubscriberAccumulator) accumulator;
ConcurrentMap<Integer, Long> brokenSequences = subscriberAccumulator.getBrokenSequences();
if (brokenSequences.isEmpty()) {
return true;
}
return isTryRecoverSucceeded(brokenSequences);
}
use of com.hazelcast.map.impl.querycache.accumulator.Accumulator in project hazelcast by hazelcast.
the class AccumulatorSweeper method flushAccumulator.
public static void flushAccumulator(PublisherContext publisherContext, int partitionId) {
QueryCacheEventData endOfSequenceEvent = createEndOfSequenceEvent(partitionId);
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();
Accumulator accumulator = accumulatorMap.get(partitionId);
if (accumulator == null) {
continue;
}
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
processor.process(endOfSequenceEvent);
}
}
}
use of com.hazelcast.map.impl.querycache.accumulator.Accumulator 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();
// 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, mapName);
if (singleEventData == null) {
continue;
}
Accumulator accumulator = registry.getOrCreate(partitionId);
accumulator.accumulate(singleEventData);
}
}
Aggregations