Search in sources :

Example 6 with Accumulator

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) {
    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
            QueryCacheEventData eventData = createEndOfSequenceEvent(partitionId);
            processor.process(eventData);
        }
    }
}
Also used : Accumulator(com.hazelcast.map.impl.querycache.accumulator.Accumulator) QueryCacheContext(com.hazelcast.map.impl.querycache.QueryCacheContext) QueryCacheEventData(com.hazelcast.map.impl.querycache.event.QueryCacheEventData)

Example 7 with Accumulator

use of com.hazelcast.map.impl.querycache.accumulator.Accumulator in project hazelcast by hazelcast.

the class QueryCacheUtilTest method getAccumulatorOrNull_whenNoAccumulatorsRegistered_thenReturnNull.

@Test
public void getAccumulatorOrNull_whenNoAccumulatorsRegistered_thenReturnNull() {
    Accumulator accumulator = getAccumulatorOrNull(context, "myMap", "myCache", -1);
    assertNull(accumulator);
}
Also used : Accumulator(com.hazelcast.map.impl.querycache.accumulator.Accumulator) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 8 with Accumulator

use of com.hazelcast.map.impl.querycache.accumulator.Accumulator 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 9 with Accumulator

use of com.hazelcast.map.impl.querycache.accumulator.Accumulator in project hazelcast by hazelcast.

the class QueryCacheEventPublisher method hintMapEvent.

// TODO known issue: Locked keys will also be cleared from the query-cache after calling a map-wide event like clear/evictAll
public void hintMapEvent(Address caller, String mapName, EntryEventType eventType, int numberOfEntriesAffected, int partitionId) {
    // this collection contains all defined query-caches on this map.
    Collection<PartitionAccumulatorRegistry> partitionAccumulatorRegistries = getPartitionAccumulatorRegistries(mapName);
    for (PartitionAccumulatorRegistry accumulatorRegistry : partitionAccumulatorRegistries) {
        Accumulator accumulator = accumulatorRegistry.getOrCreate(partitionId);
        QueryCacheEventData singleEventData = newQueryCacheEventDataBuilder(false).withPartitionId(partitionId).withEventType(eventType.getType()).build();
        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) QueryCacheEventData(com.hazelcast.map.impl.querycache.event.QueryCacheEventData)

Aggregations

Accumulator (com.hazelcast.map.impl.querycache.accumulator.Accumulator)9 QueryCacheContext (com.hazelcast.map.impl.querycache.QueryCacheContext)5 QueryCacheEventData (com.hazelcast.map.impl.querycache.event.QueryCacheEventData)4 DefaultQueryCacheEventData (com.hazelcast.map.impl.querycache.event.DefaultQueryCacheEventData)2 Sequenced (com.hazelcast.map.impl.querycache.event.sequence.Sequenced)2 PartitionAccumulatorRegistry (com.hazelcast.map.impl.querycache.publisher.PartitionAccumulatorRegistry)2 QueryCacheEventService (com.hazelcast.map.impl.querycache.QueryCacheEventService)1 EventPublisherAccumulatorProcessor (com.hazelcast.map.impl.querycache.publisher.EventPublisherAccumulatorProcessor)1 PublisherAccumulatorHandler (com.hazelcast.map.impl.querycache.publisher.PublisherAccumulatorHandler)1 Data (com.hazelcast.nio.serialization.Data)1 ParallelTest (com.hazelcast.test.annotation.ParallelTest)1 QuickTest (com.hazelcast.test.annotation.QuickTest)1 Map (java.util.Map)1 Test (org.junit.Test)1