Search in sources :

Example 1 with UnlockOptions

use of com.couchbase.client.java.kv.UnlockOptions in project couchbase-jvm-clients by couchbase.

the class AsyncCollection method unlockRequest.

/**
 * Helper method to create the unlock request.
 *
 * @param id the id of the document.
 * @param cas the CAS value which is needed to unlock it.
 * @param options the options to customize.
 * @return the unlock request.
 */
UnlockRequest unlockRequest(final String id, final long cas, final UnlockOptions options) {
    notNullOrEmpty(id, "Id", () -> ReducedKeyValueErrorContext.create(id, collectionIdentifier));
    notNull(options, "UnlockOptions", () -> ReducedKeyValueErrorContext.create(id, collectionIdentifier));
    if (cas == 0) {
        throw new InvalidArgumentException("CAS cannot be 0", null, ReducedKeyValueErrorContext.create(id, collectionIdentifier));
    }
    UnlockOptions.Built opts = options.build();
    Duration timeout = opts.timeout().orElse(environment.timeoutConfig().kvTimeout());
    RetryStrategy retryStrategy = opts.retryStrategy().orElse(environment.retryStrategy());
    RequestSpan span = environment.requestTracer().requestSpan(TracingIdentifiers.SPAN_REQUEST_KV_UNLOCK, opts.parentSpan().orElse(null));
    UnlockRequest request = new UnlockRequest(timeout, coreContext, collectionIdentifier, retryStrategy, id, cas, span);
    request.context().clientContext(opts.clientContext());
    return request;
}
Also used : InvalidArgumentException(com.couchbase.client.core.error.InvalidArgumentException) UnlockOptions(com.couchbase.client.java.kv.UnlockOptions) Duration(java.time.Duration) RetryStrategy(com.couchbase.client.core.retry.RetryStrategy) UnlockRequest(com.couchbase.client.core.msg.kv.UnlockRequest) RequestSpan(com.couchbase.client.core.cnc.RequestSpan)

Aggregations

RequestSpan (com.couchbase.client.core.cnc.RequestSpan)1 InvalidArgumentException (com.couchbase.client.core.error.InvalidArgumentException)1 UnlockRequest (com.couchbase.client.core.msg.kv.UnlockRequest)1 RetryStrategy (com.couchbase.client.core.retry.RetryStrategy)1 UnlockOptions (com.couchbase.client.java.kv.UnlockOptions)1 Duration (java.time.Duration)1