Search in sources :

Example 1 with DeliveryGuarantee

use of org.infinispan.reactive.publisher.impl.DeliveryGuarantee in project infinispan by infinispan.

the class AbstractCacheStream method performPublisherOperation.

<R> R performPublisherOperation(Function<? super Publisher<T>, ? extends CompletionStage<R>> transformer, Function<? super Publisher<R>, ? extends CompletionStage<R>> finalizer) {
    Function usedTransformer;
    if (intermediateOperations.isEmpty()) {
        usedTransformer = transformer;
    } else {
        usedTransformer = new CacheStreamIntermediateReducer(intermediateOperations, transformer);
    }
    DeliveryGuarantee guarantee = rehashAware ? DeliveryGuarantee.EXACTLY_ONCE : DeliveryGuarantee.AT_MOST_ONCE;
    CompletionStage<R> stage;
    if (toKeyFunction == null) {
        stage = cpm.keyReduction(parallel, segmentsToFilter, keysToFilter, invocationContext, explicitFlags, guarantee, usedTransformer, finalizer);
    } else {
        stage = cpm.entryReduction(parallel, segmentsToFilter, keysToFilter, invocationContext, explicitFlags, guarantee, usedTransformer, finalizer);
    }
    return CompletionStages.join(stage);
}
Also used : Function(java.util.function.Function) DeliveryGuarantee(org.infinispan.reactive.publisher.impl.DeliveryGuarantee)

Example 2 with DeliveryGuarantee

use of org.infinispan.reactive.publisher.impl.DeliveryGuarantee in project infinispan by infinispan.

the class DistributedCacheStream method iterator.

// The next ones are key tracking terminal operators
@Override
public Iterator<R> iterator() {
    log.tracef("Distributed iterator invoked with rehash: %s", rehashAware);
    Function usedTransformer;
    if (intermediateOperations.isEmpty()) {
        usedTransformer = MarshallableFunctions.identity();
    } else {
        usedTransformer = new CacheIntermediatePublisher(intermediateOperations);
    }
    DeliveryGuarantee deliveryGuarantee = rehashAware ? DeliveryGuarantee.EXACTLY_ONCE : DeliveryGuarantee.AT_MOST_ONCE;
    Publisher<R> publisherToSubscribeTo;
    SegmentPublisherSupplier<R> publisher;
    if (toKeyFunction == null) {
        publisher = cpm.keyPublisher(segmentsToFilter, keysToFilter, invocationContext, explicitFlags, deliveryGuarantee, distributedBatchSize, usedTransformer);
    } else {
        publisher = cpm.entryPublisher(segmentsToFilter, keysToFilter, invocationContext, explicitFlags, deliveryGuarantee, distributedBatchSize, usedTransformer);
    }
    CompletionSegmentTracker<R> segmentTracker;
    if (segmentCompletionListener != null) {
        // Tracker relies on ordering that a segment completion occurs
        segmentTracker = new CompletionSegmentTracker<>(segmentCompletionListener);
        publisherToSubscribeTo = Flowable.fromPublisher(publisher.publisherWithSegments()).mapOptional(segmentTracker);
    } else {
        segmentTracker = null;
        publisherToSubscribeTo = publisher.publisherWithoutSegments();
    }
    CloseableIterator<R> realIterator = Closeables.iterator(Flowable.fromPublisher(publisherToSubscribeTo).onErrorResumeNext(RxJavaInterop.cacheExceptionWrapper()), distributedBatchSize);
    onClose(realIterator::close);
    if (segmentTracker != null) {
        return new AbstractIterator<R>() {

            @Override
            protected R getNext() {
                if (realIterator.hasNext()) {
                    R value = realIterator.next();
                    segmentTracker.returningObject(value);
                    return value;
                } else {
                    segmentTracker.onComplete();
                }
                return null;
            }
        };
    }
    return realIterator;
}
Also used : BiFunction(java.util.function.BiFunction) ToLongFunction(java.util.function.ToLongFunction) ToDoubleFunction(java.util.function.ToDoubleFunction) Function(java.util.function.Function) IntFunction(java.util.function.IntFunction) ToIntFunction(java.util.function.ToIntFunction) DeliveryGuarantee(org.infinispan.reactive.publisher.impl.DeliveryGuarantee) AbstractIterator(org.infinispan.commons.util.AbstractIterator)

Aggregations

Function (java.util.function.Function)2 DeliveryGuarantee (org.infinispan.reactive.publisher.impl.DeliveryGuarantee)2 BiFunction (java.util.function.BiFunction)1 IntFunction (java.util.function.IntFunction)1 ToDoubleFunction (java.util.function.ToDoubleFunction)1 ToIntFunction (java.util.function.ToIntFunction)1 ToLongFunction (java.util.function.ToLongFunction)1 AbstractIterator (org.infinispan.commons.util.AbstractIterator)1