use of com.couchbase.client.core.msg.kv.ObserveViaSeqnoRequest in project couchbase-jvm-clients by couchbase.
the class Observe method viaMutationToken.
private static Flux<ObserveItem> viaMutationToken(final int bucketReplicas, final ObserveContext ctx, final RequestSpan parent) {
if (!ctx.mutationToken().isPresent()) {
throw new IllegalStateException("MutationToken is not present, this is a bug!");
}
Duration timeout = ctx.timeout();
RetryStrategy retryStrategy = ctx.retryStrategy();
MutationToken mutationToken = ctx.mutationToken().get();
String id = ctx.key();
List<ObserveViaSeqnoRequest> requests = new ArrayList<>();
if (ctx.persistTo() != ObservePersistTo.NONE) {
final RequestSpan span = ctx.environment().requestTracer().requestSpan(TracingIdentifiers.SPAN_REQUEST_KV_OBSERVE, parent);
requests.add(new ObserveViaSeqnoRequest(timeout, ctx, ctx.collectionIdentifier(), retryStrategy, 0, true, mutationToken.partitionUUID(), id, span));
}
if (ctx.persistTo().touchesReplica() || ctx.replicateTo().touchesReplica()) {
for (short i = 1; i <= bucketReplicas; i++) {
final RequestSpan span = ctx.environment().requestTracer().requestSpan(TracingIdentifiers.SPAN_REQUEST_KV_OBSERVE, parent);
requests.add(new ObserveViaSeqnoRequest(timeout, ctx, ctx.collectionIdentifier(), retryStrategy, i, false, mutationToken.partitionUUID(), id, span));
}
}
return Flux.fromIterable(requests).flatMap(request -> {
ctx.core().send(request);
return Reactor.wrap(request, request.response(), true).onErrorResume(t -> Mono.empty()).doFinally(signalType -> request.context().logicallyComplete());
}).map(response -> ObserveItem.fromMutationToken(mutationToken, response));
}
Aggregations