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);
}
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;
}
Aggregations