use of cz.o2.proxima.functional.UnaryPredicate in project proxima-platform by O2-Czech-Republic.
the class ListCommitLog method pushToObserverBulk.
private ObserveHandle pushToObserverBulk(@Nonnull String name, UnaryPredicate<Integer> allowOffsetPredicate, CommitLogObserver observer) {
observer.onRepartition(asRepartitionContext(Collections.singletonList(PARTITION)));
Consumer consumer = CONSUMERS.get(uuid).computeIfAbsent(name, k -> new Consumer(uuid, name, watermarkEstimator));
ListObserveHandle handle = new ListObserveHandle(uuid, name);
Set<Integer> consumerFedOffsets = Collections.synchronizedSet(new HashSet<>());
pushTo((element, offset) -> {
if (handle.isClosed()) {
return false;
}
final CommitLogObserver.OffsetCommitter committer = (succ, exc) -> {
if (exc != null) {
observer.onError(exc);
}
};
final boolean acceptable;
OnNextContext context = null;
synchronized (consumer) {
acceptable = (externalizableOffsets || !consumer.getAckedOffsets().contains(offset) && !consumer.getInflightOffsets().contains(offset)) && allowOffsetPredicate.apply(offset);
if (acceptable) {
context = consumer.asOnNextContextBulk(committer, offset, consumerFedOffsets);
}
}
if (acceptable) {
return observer.onNext(element, context);
}
return true;
}, externalizableOffsets ? () -> true : allMatchOffset(consumer::isAcked), observer::onCompleted, observer::onCancelled);
return handle;
}
Aggregations