Search in sources :

Example 1 with GetAndLockRequest

use of com.couchbase.client.core.msg.kv.GetAndLockRequest in project couchbase-jvm-clients by couchbase.

the class ReactiveCollection method getAndLock.

/**
 * Fetches a full document and write-locks it for the given duration with custom options.
 * <p>
 * Note that the client does not enforce an upper limit on the {@link Duration} lockTime. The maximum lock time
 * by default on the server is 30 seconds. Any value larger than 30 seconds will be capped down by the server to
 * the default lock time, which is 15 seconds unless modified on the server side.
 *
 * @param id the document id which is used to uniquely identify it.
 * @param lockTime how long to write-lock the document for (any duration > 30s will be capped to server default of 15s).
 * @param options custom options to change the default behavior.
 * @return a {@link Mono} completing once loaded or failed.
 */
public Mono<GetResult> getAndLock(final String id, final Duration lockTime, final GetAndLockOptions options) {
    return Mono.defer(() -> {
        GetAndLockOptions.Built opts = options.build();
        final Transcoder transcoder = opts.transcoder() == null ? environment().transcoder() : opts.transcoder();
        GetAndLockRequest request = asyncCollection.getAndLockRequest(id, lockTime, opts);
        return Reactor.wrap(request, GetAccessor.getAndLock(core, request, transcoder), true);
    });
}
Also used : GetAndLockRequest(com.couchbase.client.core.msg.kv.GetAndLockRequest) GetAndLockOptions(com.couchbase.client.java.kv.GetAndLockOptions) Transcoder(com.couchbase.client.java.codec.Transcoder)

Example 2 with GetAndLockRequest

use of com.couchbase.client.core.msg.kv.GetAndLockRequest in project couchbase-jvm-clients by couchbase.

the class AsyncCollection method getAndLockRequest.

/**
 * Helper method to create the get and lock request.
 *
 * @param id the document id which is used to uniquely identify it.
 * @param lockTime how long to lock the document for.  Any values above 30 seconds will be
 *                 treated as 30 seconds.
 * @param opts custom options to change the default behavior.
 * @return the get and lock request.
 */
@Stability.Internal
GetAndLockRequest getAndLockRequest(final String id, final Duration lockTime, final GetAndLockOptions.Built opts) {
    notNullOrEmpty(id, "Id", () -> ReducedKeyValueErrorContext.create(id, collectionIdentifier));
    notNull(lockTime, "LockTime", () -> ReducedKeyValueErrorContext.create(id, collectionIdentifier));
    Duration timeout = opts.timeout().orElse(environment.timeoutConfig().kvTimeout());
    RetryStrategy retryStrategy = opts.retryStrategy().orElse(environment.retryStrategy());
    RequestSpan span = environment.requestTracer().requestSpan(TracingIdentifiers.SPAN_REQUEST_KV_GET_AND_LOCK, opts.parentSpan().orElse(null));
    GetAndLockRequest request = new GetAndLockRequest(id, timeout, coreContext, collectionIdentifier, retryStrategy, lockTime, span);
    request.context().clientContext(opts.clientContext());
    return request;
}
Also used : GetAndLockRequest(com.couchbase.client.core.msg.kv.GetAndLockRequest) Duration(java.time.Duration) RetryStrategy(com.couchbase.client.core.retry.RetryStrategy) RequestSpan(com.couchbase.client.core.cnc.RequestSpan)

Aggregations

GetAndLockRequest (com.couchbase.client.core.msg.kv.GetAndLockRequest)2 RequestSpan (com.couchbase.client.core.cnc.RequestSpan)1 RetryStrategy (com.couchbase.client.core.retry.RetryStrategy)1 Transcoder (com.couchbase.client.java.codec.Transcoder)1 GetAndLockOptions (com.couchbase.client.java.kv.GetAndLockOptions)1 Duration (java.time.Duration)1