Interface Request<R extends Response>

All Known Subinterfaces:
HttpRequest<H,ROW,T,R>, KeyValueRequest<R>, ManagerRequest<R>, NonChunkedHttpRequest<R>
All Known Implementing Classes:
AnalyticsRequest, AppendRequest, BaseKeyValueRequest, BaseManagerRequest, BaseRequest, BucketConfigRequest, BucketConfigStreamingRequest, CarrierBucketConfigRequest, CarrierGlobalConfigRequest, CoreHttpRequest, CoreTransactionRequest, DecrementRequest, GenericManagerRequest, GetAndLockRequest, GetAndTouchRequest, GetCollectionIdRequest, GetCollectionManifestRequest, GetMetaRequest, GetRequest, IncrementRequest, InsertRequest, KvPingRequest, MultiObserveViaCasRequest, NoopRequest, ObserveViaCasRequest, ObserveViaSeqnoRequest, PredeterminedPartitionRequest, PrependRequest, ProtostellarBaseRequest, QueryRequest, RangeScanCancelRequest, RangeScanContinueRequest, RangeScanCreateRequest, RemoveRequest, ReplaceRequest, ReplicaGetRequest, ReplicaSubdocGetRequest, ServerSearchRequest, SubdocGetRequest, SubdocMutateRequest, TouchRequest, UnlockRequest, UpsertRequest, ViewRequest

public interface Request<R extends Response>
Represents a Request flowing through the client.
Since:
2.0.0
  • Method Summary

    Modifier and Type
    Method
    Description
    long
    The absolute timestamp when the request should time out.
    default String
    Returns the name of the bucket this request is scoped to, or null if not scoped to a bucket.
    default void
    Cancels this request.
    void
    cancel(CancellationReason reason, Function<Throwable,Throwable> exceptionTranslator)
    Cancels this request, allowing the caller to customize the exception.
    If the request is cancelled(), this returns the reason why.
    boolean
    Allows to check if this request has been cancelled before it got a chance to be either failed or succeeded.
    boolean
    Allows to check if this request is completed already.
    If attached, returns the context for this request.
    long
    Holds the nanoTime when the request got created.
    void
    fail(Throwable error)
    Fails this request and completes it.
    boolean
    Allows to check if this request has been completed but with an exception.
    long
    id()
    Holds a unique ID for each request that is assigned automatically.
    default boolean
    Returns if the given request is idempotent or not.
    default String
    The unique name of the request, usually related to the type but not necessarily.
    default String
    Returns a potentially non-unique identifier that is useful for tracing output.
    Holds the internal span for this request.
    Holds the response which eventually completes.
    The retry strategy for this particular request.
    Returns contextual information for each individual service.
    The service type of this request.
    void
    succeed(R result)
    Completes this request successfully.
    boolean
    Allows to check if this request has been successfully completed.
    Returns the node that should service this request, or null to let the service locator decide.
    Returns the timeout for this request.
    boolean
    Returns true if the timeout elapsed.
    void
    timeoutRegistration(com.couchbase.client.core.deps.io.netty.util.Timeout registration)
    Sets the timeout registration used to cancel when complete.
  • Method Details

    • id

      long id()
      Holds a unique ID for each request that is assigned automatically.
      Returns:
      the unique request ID.
    • response

      CompletableFuture<R> response()
      Holds the response which eventually completes.
      Returns:
      the future containing the response, eventually.
    • succeed

      void succeed(R result)
      Completes this request successfully.
      Parameters:
      result - the result to complete with.
    • fail

      void fail(Throwable error)
      Fails this request and completes it.
      Parameters:
      error - the error to fail this request with.
    • cancel

      default void cancel(CancellationReason reason)
      Cancels this request.
    • cancel

      void cancel(CancellationReason reason, Function<Throwable,Throwable> exceptionTranslator)
      Cancels this request, allowing the caller to customize the exception.
      Parameters:
      exceptionTranslator - A typical function might create a new custom exception using the argument as the cause.
    • timeoutRegistration

      void timeoutRegistration(com.couchbase.client.core.deps.io.netty.util.Timeout registration)
      Sets the timeout registration used to cancel when complete.
      Parameters:
      registration - the registration for the timeout timer.
    • context

      RequestContext context()
      If attached, returns the context for this request.
      Returns:
      the request context if attached.
    • timeout

      Duration timeout()
      Returns the timeout for this request.
      Returns:
      the timeout for this request.
    • timeoutElapsed

      boolean timeoutElapsed()
      Returns true if the timeout elapsed.
    • completed

      boolean completed()
      Allows to check if this request is completed already.
      Returns:
      true if completed, failed or cancelled.
    • succeeded

      boolean succeeded()
      Allows to check if this request has been successfully completed.
      Returns:
      true if succeeded, false otherwise.
    • failed

      boolean failed()
      Allows to check if this request has been completed but with an exception.
      Returns:
      true if failed, false otherwise.
    • cancelled

      boolean cancelled()
      Allows to check if this request has been cancelled before it got a chance to be either failed or succeeded.
      Returns:
      true if cancelled, false otherwise.
    • cancellationReason

      CancellationReason cancellationReason()
      If the request is cancelled(), this returns the reason why.
      Returns:
      the cancellation reason if cancelled, null otherwise.
    • serviceType

      @Nullable ServiceType serviceType()
      The service type of this request.

      Can be null if this is a 'virtual service' (e.g. transactions), which don't map 1:1 to a particular cluster service, but need to integrate into various codepaths that are built around ServiceType such as ThresholdLoggingTracer. Virtual requests must not be sent into core at present, as there is limited support for them.

      Returns:
      the service type for this request.
    • bucket

      default String bucket()
      Returns the name of the bucket this request is scoped to, or null if not scoped to a bucket.
      Returns:
      (nullable)
    • target

      default NodeIdentifier target()
      Returns the node that should service this request, or null to let the service locator decide.
      Returns:
      (nullable)
    • serviceContext

      Map<String,Object> serviceContext()
      Returns contextual information for each individual service.
      Returns:
      the service context.
    • retryStrategy

      RetryStrategy retryStrategy()
      The retry strategy for this particular request.
      Returns:
      the retry strategy for this request.
    • requestSpan

      RequestSpan requestSpan()
      Holds the internal span for this request.
      Returns:
      the internal span used for the request.
    • createdAt

      long createdAt()
      Holds the nanoTime when the request got created.
      Returns:
      the time when the request got created.
    • absoluteTimeout

      long absoluteTimeout()
      The absolute timestamp when the request should time out.
      Returns:
      the absolute timeout in nanoseconds.
    • idempotent

      default boolean idempotent()
      Returns if the given request is idempotent or not.

      By default, this method always returns false for data consistency reasons. Only specific idempotent operations should override this default since it impacts retry handling quite a bit. DO NOT SET THIS TO TRUE ON MUTATING OPERATIONS!

      Returns:
      true if idempotent.
    • operationId

      default String operationId()
      Returns a potentially non-unique identifier that is useful for tracing output.

      Note: might be null! It depends on the type of operation. It is also different from the unqiue operation ID that increments to provide additional context (i.e in query the context uuid, in kv the opaque value).

      Returns:
      if present, the operation id. Null otherwise.
    • name

      default String name()
      The unique name of the request, usually related to the type but not necessarily.

      The default implementation is derived from the class name (i.e. FooRequest returns foo), but if that does not match up it should be overridden in the actual class.

      Returns:
      the name of the request type.