com.couchbase.client.java.batch.ReactiveBatchHelper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of java-client Show documentation
Show all versions of java-client Show documentation
The official Couchbase Java SDK
/*
* Copyright (c) 2020 Couchbase, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.couchbase.client.java.batch;
import com.couchbase.client.core.Core;
import com.couchbase.client.core.Reactor;
import com.couchbase.client.core.annotation.Stability;
import com.couchbase.client.core.config.BucketConfig;
import com.couchbase.client.core.config.CouchbaseBucketConfig;
import com.couchbase.client.core.config.NodeInfo;
import com.couchbase.client.core.env.CoreEnvironment;
import com.couchbase.client.core.io.CollectionIdentifier;
import com.couchbase.client.core.msg.kv.MultiObserveViaCasRequest;
import com.couchbase.client.core.msg.kv.MultiObserveViaCasResponse;
import com.couchbase.client.core.msg.kv.ObserveViaCasResponse;
import com.couchbase.client.core.node.KeyValueLocator;
import com.couchbase.client.core.node.NodeIdentifier;
import com.couchbase.client.java.Collection;
import com.couchbase.client.java.kv.GetResult;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import reactor.util.function.Tuple2;
import reactor.util.function.Tuples;
import java.nio.charset.StandardCharsets;
import java.time.Duration;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.function.Predicate;
/**
* This helper class provides methods that make performing batch operations easy and comfortable.
*/
@Stability.Volatile
public class ReactiveBatchHelper {
private static final Predicate PMGET_PREDICATE = s ->
s == ObserveViaCasResponse.ObserveStatus.FOUND_PERSISTED
|| s == ObserveViaCasResponse.ObserveStatus.FOUND_NOT_PERSISTED;
/**
* First checks if the given IDs exist and if so fetches their contents.
*
* Please take into consideration when using this API that it only makes sense to use it if of the many ids provided
* only a small subset comes back. (So let's say you give it 1000 IDs but you only expect 50 to be there or so).
* Otherwise if all are most of them are there, just use a bulk get with the reactive API directly - you won't see
* much benefit in this case.
*
* @param collection the collection to perform the fetch on.
* @param ids the document IDs to fetch.
* @return a Map of the document IDs as the key and the result (if found).
*/
@Stability.Volatile
public static Mono