Search in sources :

Example 1 with Sequenced

use of com.hazelcast.map.impl.querycache.event.sequence.Sequenced 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);
}
Also used : Accumulator(com.hazelcast.map.impl.querycache.accumulator.Accumulator) QueryCacheEventService(com.hazelcast.map.impl.querycache.QueryCacheEventService) EventPublisherAccumulatorProcessor(com.hazelcast.map.impl.querycache.publisher.EventPublisherAccumulatorProcessor) Sequenced(com.hazelcast.map.impl.querycache.event.sequence.Sequenced) PublisherAccumulatorHandler(com.hazelcast.map.impl.querycache.publisher.PublisherAccumulatorHandler) QueryCacheContext(com.hazelcast.map.impl.querycache.QueryCacheContext)

Example 2 with Sequenced

use of com.hazelcast.map.impl.querycache.event.sequence.Sequenced 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();
}
Also used : Accumulator(com.hazelcast.map.impl.querycache.accumulator.Accumulator) Sequenced(com.hazelcast.map.impl.querycache.event.sequence.Sequenced) QueryCacheContext(com.hazelcast.map.impl.querycache.QueryCacheContext)

Example 3 with Sequenced

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

the class BasicAccumulator method createAccumulatorHandler.

@SuppressWarnings("unchecked")
private AccumulatorHandler<E> createAccumulatorHandler(QueryCacheContext context, AccumulatorInfo info) {
    QueryCacheEventService queryCacheEventService = context.getQueryCacheEventService();
    AccumulatorProcessor<Sequenced> processor = createAccumulatorProcessor(info, queryCacheEventService);
    return (AccumulatorHandler<E>) new PublisherAccumulatorHandler(context, processor);
}
Also used : QueryCacheEventService(com.hazelcast.map.impl.querycache.QueryCacheEventService) Sequenced(com.hazelcast.map.impl.querycache.event.sequence.Sequenced) PublisherAccumulatorHandler(com.hazelcast.map.impl.querycache.publisher.PublisherAccumulatorHandler) PublisherAccumulatorHandler(com.hazelcast.map.impl.querycache.publisher.PublisherAccumulatorHandler)

Example 4 with Sequenced

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

the class CyclicBufferTest method testBufferRead_withSequence.

@Test
public void testBufferRead_withSequence() {
    int maxCapacity = nextPowerOfTwo(10);
    int itemCount = 4;
    CyclicBuffer<TestSequenced> buffer = new DefaultCyclicBuffer<TestSequenced>(maxCapacity);
    for (int i = 1; i <= itemCount; i++) {
        buffer.add(new TestSequenced(i));
    }
    long readFromSequence = 1L;
    do {
        Sequenced sequenced = buffer.get(readFromSequence);
        if (sequenced == null) {
            break;
        }
        if (readFromSequence + 1 > itemCount) {
            break;
        }
        readFromSequence++;
    } while (true);
    assertEquals("read count should be = " + readFromSequence, readFromSequence, itemCount);
}
Also used : Sequenced(com.hazelcast.map.impl.querycache.event.sequence.Sequenced) DefaultCyclicBuffer(com.hazelcast.map.impl.querycache.accumulator.DefaultCyclicBuffer) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 5 with Sequenced

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

the class DefaultCyclicBuffer method init.

private void init(int maxSize) {
    this.capacity = nextPowerOfTwo(maxSize);
    this.buffer = (E[]) new Sequenced[capacity];
    this.tailSequence = new AtomicLong(UNAVAILABLE);
    this.headSequence = new AtomicLong(UNAVAILABLE);
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) Sequenced(com.hazelcast.map.impl.querycache.event.sequence.Sequenced)

Aggregations

Sequenced (com.hazelcast.map.impl.querycache.event.sequence.Sequenced)5 QueryCacheContext (com.hazelcast.map.impl.querycache.QueryCacheContext)2 QueryCacheEventService (com.hazelcast.map.impl.querycache.QueryCacheEventService)2 Accumulator (com.hazelcast.map.impl.querycache.accumulator.Accumulator)2 PublisherAccumulatorHandler (com.hazelcast.map.impl.querycache.publisher.PublisherAccumulatorHandler)2 DefaultCyclicBuffer (com.hazelcast.map.impl.querycache.accumulator.DefaultCyclicBuffer)1 EventPublisherAccumulatorProcessor (com.hazelcast.map.impl.querycache.publisher.EventPublisherAccumulatorProcessor)1 ParallelTest (com.hazelcast.test.annotation.ParallelTest)1 QuickTest (com.hazelcast.test.annotation.QuickTest)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 Test (org.junit.Test)1