Search in sources :

Example 1 with GetAndTouchRequest

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

the class AsyncCollection method getAndTouchRequest.

/**
 * Helper method for get and touch requests.
 *
 * @param id the document id which is used to uniquely identify it.
 * @param expiry the new expiration time for the document.
 * @param opts custom options to change the default behavior.
 * @return the get and touch request.
 */
@Stability.Internal
GetAndTouchRequest getAndTouchRequest(final String id, final Expiry expiry, final GetAndTouchOptions.Built opts) {
    notNullOrEmpty(id, "Id", () -> ReducedKeyValueErrorContext.create(id, collectionIdentifier));
    notNull(expiry, "Expiry", () -> 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_TOUCH, opts.parentSpan().orElse(null));
    long encodedExpiry = expiry.encode();
    GetAndTouchRequest request = new GetAndTouchRequest(id, timeout, coreContext, collectionIdentifier, retryStrategy, encodedExpiry, span);
    request.context().clientContext(opts.clientContext());
    return request;
}
Also used : GetAndTouchRequest(com.couchbase.client.core.msg.kv.GetAndTouchRequest) Duration(java.time.Duration) RetryStrategy(com.couchbase.client.core.retry.RetryStrategy) RequestSpan(com.couchbase.client.core.cnc.RequestSpan)

Example 2 with GetAndTouchRequest

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

the class ReactiveCollection method getAndTouch.

/**
 * Fetches a full document and resets its expiration time to the value provided with custom
 * options.
 *
 * @param id the document id which is used to uniquely identify it.
 * @param expiry the new expiration time for the document.
 * @param options custom options to change the default behavior.
 * @return a {@link Mono} completing once loaded or failed.
 */
public Mono<GetResult> getAndTouch(final String id, final Duration expiry, final GetAndTouchOptions options) {
    return Mono.defer(() -> {
        GetAndTouchOptions.Built opts = options.build();
        final Transcoder transcoder = opts.transcoder() == null ? environment().transcoder() : opts.transcoder();
        GetAndTouchRequest request = asyncCollection.getAndTouchRequest(id, Expiry.relative(expiry), opts);
        return Reactor.wrap(request, GetAccessor.getAndTouch(core, request, transcoder), true);
    });
}
Also used : GetAndTouchRequest(com.couchbase.client.core.msg.kv.GetAndTouchRequest) GetAndTouchOptions(com.couchbase.client.java.kv.GetAndTouchOptions) Transcoder(com.couchbase.client.java.codec.Transcoder)

Aggregations

GetAndTouchRequest (com.couchbase.client.core.msg.kv.GetAndTouchRequest)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 GetAndTouchOptions (com.couchbase.client.java.kv.GetAndTouchOptions)1 Duration (java.time.Duration)1