Search in sources :

Example 26 with RetryStrategy

use of com.couchbase.client.core.retry.RetryStrategy in project couchbase-jvm-clients by couchbase.

the class AsyncBinaryCollection method prependRequest.

PrependRequest prependRequest(final String id, final byte[] content, final PrependOptions.Built opts) {
    notNullOrEmpty(id, "Id", () -> ReducedKeyValueErrorContext.create(id, collectionIdentifier));
    notNull(content, "Content", () -> ReducedKeyValueErrorContext.create(id, collectionIdentifier));
    Duration timeout = decideKvTimeout(opts, environment.timeoutConfig());
    RetryStrategy retryStrategy = opts.retryStrategy().orElse(environment.retryStrategy());
    RequestSpan span = environment.requestTracer().requestSpan(TracingIdentifiers.SPAN_REQUEST_KV_PREPEND, opts.parentSpan().orElse(null));
    PrependRequest request = new PrependRequest(timeout, coreContext, collectionIdentifier, retryStrategy, id, content, opts.cas(), opts.durabilityLevel(), span);
    request.context().clientContext(opts.clientContext());
    return request;
}
Also used : Duration(java.time.Duration) PrependRequest(com.couchbase.client.core.msg.kv.PrependRequest) RetryStrategy(com.couchbase.client.core.retry.RetryStrategy) RequestSpan(com.couchbase.client.core.cnc.RequestSpan)

Example 27 with RetryStrategy

use of com.couchbase.client.core.retry.RetryStrategy in project couchbase-jvm-clients by couchbase.

the class AsyncBinaryCollection method incrementRequest.

IncrementRequest incrementRequest(final String id, final IncrementOptions.Built opts) {
    notNullOrEmpty(id, "Id", () -> ReducedKeyValueErrorContext.create(id, collectionIdentifier));
    Duration timeout = decideKvTimeout(opts, environment.timeoutConfig());
    RetryStrategy retryStrategy = opts.retryStrategy().orElse(environment.retryStrategy());
    RequestSpan span = environment.requestTracer().requestSpan(TracingIdentifiers.SPAN_REQUEST_KV_INCREMENT, opts.parentSpan().orElse(null));
    long expiry = opts.expiry().encode();
    IncrementRequest request = new IncrementRequest(timeout, coreContext, collectionIdentifier, retryStrategy, id, opts.delta(), opts.initial(), expiry, opts.durabilityLevel(), span);
    request.context().clientContext(opts.clientContext());
    return request;
}
Also used : IncrementRequest(com.couchbase.client.core.msg.kv.IncrementRequest) Duration(java.time.Duration) RetryStrategy(com.couchbase.client.core.retry.RetryStrategy) RequestSpan(com.couchbase.client.core.cnc.RequestSpan)

Example 28 with RetryStrategy

use of com.couchbase.client.core.retry.RetryStrategy in project couchbase-jvm-clients by couchbase.

the class AsyncCluster method queryRequest.

/**
 * Helper method to construct the query request.
 *
 * @param statement the statement of the query.
 * @param options the options.
 * @return the constructed query request.
 */
QueryRequest queryRequest(final String statement, final QueryOptions.Built options) {
    notNullOrEmpty(statement, "Statement", () -> new ReducedQueryErrorContext(statement));
    Duration timeout = options.timeout().orElse(environment.get().timeoutConfig().queryTimeout());
    RetryStrategy retryStrategy = options.retryStrategy().orElse(environment.get().retryStrategy());
    final JsonObject query = JsonObject.create();
    query.put("statement", statement);
    query.put("timeout", encodeDurationToMs(timeout));
    options.injectParams(query);
    final byte[] queryBytes = query.toString().getBytes(StandardCharsets.UTF_8);
    final String clientContextId = query.getString("client_context_id");
    final RequestSpan span = environment().requestTracer().requestSpan(TracingIdentifiers.SPAN_REQUEST_QUERY, options.parentSpan().orElse(null));
    QueryRequest request = new QueryRequest(timeout, core.context(), retryStrategy, authenticator, statement, queryBytes, options.readonly(), clientContextId, span, null, null, null);
    request.context().clientContext(options.clientContext());
    return request;
}
Also used : QueryRequest(com.couchbase.client.core.msg.query.QueryRequest) JsonObject(com.couchbase.client.java.json.JsonObject) Duration(java.time.Duration) ConnectionStringUtil.asConnectionString(com.couchbase.client.core.util.ConnectionStringUtil.asConnectionString) ConnectionStringUtil.checkConnectionString(com.couchbase.client.core.util.ConnectionStringUtil.checkConnectionString) ConnectionString(com.couchbase.client.core.util.ConnectionString) ReducedQueryErrorContext(com.couchbase.client.core.error.context.ReducedQueryErrorContext) RetryStrategy(com.couchbase.client.core.retry.RetryStrategy) RequestSpan(com.couchbase.client.core.cnc.RequestSpan)

Example 29 with RetryStrategy

use of com.couchbase.client.core.retry.RetryStrategy in project couchbase-jvm-clients by couchbase.

the class AsyncCluster method analyticsRequest.

/**
 * Helper method to craft an analytics request.
 *
 * @param statement the statement to use.
 * @param opts the built analytics options.
 * @return the created analytics request.
 */
AnalyticsRequest analyticsRequest(final String statement, final AnalyticsOptions.Built opts) {
    notNullOrEmpty(statement, "Statement", () -> new ReducedAnalyticsErrorContext(statement));
    Duration timeout = opts.timeout().orElse(environment.get().timeoutConfig().analyticsTimeout());
    RetryStrategy retryStrategy = opts.retryStrategy().orElse(environment.get().retryStrategy());
    JsonObject query = JsonObject.create();
    query.put("statement", statement);
    query.put("timeout", encodeDurationToMs(timeout));
    opts.injectParams(query);
    final byte[] queryBytes = query.toString().getBytes(StandardCharsets.UTF_8);
    final String clientContextId = query.getString("client_context_id");
    final RequestSpan span = environment().requestTracer().requestSpan(TracingIdentifiers.SPAN_REQUEST_ANALYTICS, opts.parentSpan().orElse(null));
    AnalyticsRequest request = new AnalyticsRequest(timeout, core.context(), retryStrategy, authenticator, queryBytes, opts.priority(), opts.readonly(), clientContextId, statement, span, null, null);
    request.context().clientContext(opts.clientContext());
    return request;
}
Also used : ReducedAnalyticsErrorContext(com.couchbase.client.core.error.context.ReducedAnalyticsErrorContext) AnalyticsRequest(com.couchbase.client.core.msg.analytics.AnalyticsRequest) JsonObject(com.couchbase.client.java.json.JsonObject) Duration(java.time.Duration) ConnectionStringUtil.asConnectionString(com.couchbase.client.core.util.ConnectionStringUtil.asConnectionString) ConnectionStringUtil.checkConnectionString(com.couchbase.client.core.util.ConnectionStringUtil.checkConnectionString) ConnectionString(com.couchbase.client.core.util.ConnectionString) RetryStrategy(com.couchbase.client.core.retry.RetryStrategy) RequestSpan(com.couchbase.client.core.cnc.RequestSpan)

Example 30 with RetryStrategy

use of com.couchbase.client.core.retry.RetryStrategy in project couchbase-jvm-clients by couchbase.

the class AsyncCluster method searchRequest.

SearchRequest searchRequest(final String indexName, final SearchQuery query, final SearchOptions.Built opts) {
    notNullOrEmpty(indexName, "IndexName", () -> new ReducedSearchErrorContext(indexName, query.export().toMap()));
    Duration timeout = opts.timeout().orElse(environment.get().timeoutConfig().searchTimeout());
    JsonObject params = query.export();
    opts.injectParams(indexName, params, timeout);
    byte[] bytes = params.toString().getBytes(StandardCharsets.UTF_8);
    RetryStrategy retryStrategy = opts.retryStrategy().orElse(environment.get().retryStrategy());
    final RequestSpan span = environment().requestTracer().requestSpan(TracingIdentifiers.SPAN_REQUEST_SEARCH, opts.parentSpan().orElse(null));
    SearchRequest request = new SearchRequest(timeout, core.context(), retryStrategy, authenticator, indexName, bytes, span);
    request.context().clientContext(opts.clientContext());
    return request;
}
Also used : ReducedSearchErrorContext(com.couchbase.client.core.error.context.ReducedSearchErrorContext) SearchRequest(com.couchbase.client.core.msg.search.SearchRequest) JsonObject(com.couchbase.client.java.json.JsonObject) Duration(java.time.Duration) RetryStrategy(com.couchbase.client.core.retry.RetryStrategy) RequestSpan(com.couchbase.client.core.cnc.RequestSpan)

Aggregations

RetryStrategy (com.couchbase.client.core.retry.RetryStrategy)31 Duration (java.time.Duration)31 RequestSpan (com.couchbase.client.core.cnc.RequestSpan)28 ArrayList (java.util.ArrayList)8 TracingIdentifiers (com.couchbase.client.core.cnc.TracingIdentifiers)7 BucketConfig (com.couchbase.client.core.config.BucketConfig)7 GetRequest (com.couchbase.client.core.msg.kv.GetRequest)7 List (java.util.List)7 Core (com.couchbase.client.core.Core)6 CoreContext (com.couchbase.client.core.CoreContext)6 Stability (com.couchbase.client.core.annotation.Stability)6 ReducedKeyValueErrorContext (com.couchbase.client.core.error.context.ReducedKeyValueErrorContext)6 CollectionIdentifier (com.couchbase.client.core.io.CollectionIdentifier)6 Validators.notNullOrEmpty (com.couchbase.client.core.util.Validators.notNullOrEmpty)6 JsonObject (com.couchbase.client.java.json.JsonObject)6 CompletableFuture (java.util.concurrent.CompletableFuture)6 Reactor (com.couchbase.client.core.Reactor)5 CouchbaseBucketConfig (com.couchbase.client.core.config.CouchbaseBucketConfig)5 Map (java.util.Map)5 Flux (reactor.core.publisher.Flux)5