Package com.couchbase.client.core.msg
Class BaseRequest<R extends Response>
- java.lang.Object
-
- com.couchbase.client.core.msg.BaseRequest<R>
-
- All Implemented Interfaces:
Request<R>
- Direct Known Subclasses:
AnalyticsRequest
,BaseKeyValueRequest
,BaseManagerRequest
,CoreHttpRequest
,CoreTransactionRequest
,QueryRequest
,SearchRequest
,ViewRequest
public abstract class BaseRequest<R extends Response> extends Object implements Request<R>
Base class for allRequests
.- Since:
- 2.0.0
-
-
Constructor Summary
Constructors Constructor Description BaseRequest(Duration timeout, CoreContext ctx, RetryStrategy retryStrategy)
BaseRequest(Duration timeout, CoreContext ctx, RetryStrategy retryStrategy, RequestSpan requestSpan)
Creates a basic request that has all the required properties to be executed in general.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description long
absoluteTimeout()
The absolute timestamp when the request should time out.void
cancel(CancellationReason reason, Function<Throwable,Throwable> exceptionTranslator)
Cancels this request, allowing the caller to customize the exception.CancellationReason
cancellationReason()
If the request isRequest.cancelled()
, this returns the reason why.boolean
cancelled()
Allows to check if this request has been cancelled before it got a chance to be either failed or succeeded.boolean
completed()
Allows to check if this request is completed already.RequestContext
context()
If attached, returns the context for this request.long
createdAt()
Holds the nanoTime when the request got created.void
fail(Throwable error)
Fails this request and completes it.boolean
failed()
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.RequestSpan
requestSpan()
Holds the internal span for this request.CompletableFuture<R>
response()
Holds the response which eventually completes.RetryStrategy
retryStrategy()
The retry strategy for this particular request.Map<String,Object>
serviceContext()
Returns contextual information for each individual service.void
succeed(R result)
Completes this request successfully.boolean
succeeded()
Allows to check if this request has been successfully completed.Duration
timeout()
Returns the timeout for this request.boolean
timeoutElapsed()
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.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.couchbase.client.core.msg.Request
bucket, cancel, idempotent, name, operationId, serviceType, target
-
-
-
-
Constructor Detail
-
BaseRequest
public BaseRequest(Duration timeout, CoreContext ctx, RetryStrategy retryStrategy)
-
BaseRequest
public BaseRequest(Duration timeout, CoreContext ctx, RetryStrategy retryStrategy, RequestSpan requestSpan)
Creates a basic request that has all the required properties to be executed in general.- Parameters:
timeout
- the timeout of the request.ctx
- the context if provided.
-
-
Method Detail
-
response
public CompletableFuture<R> response()
Description copied from interface:Request
Holds the response which eventually completes.
-
succeed
public void succeed(R result)
Description copied from interface:Request
Completes this request successfully.
-
fail
public void fail(Throwable error)
Description copied from interface:Request
Fails this request and completes it.
-
cancel
public void cancel(CancellationReason reason, Function<Throwable,Throwable> exceptionTranslator)
Description copied from interface:Request
Cancels this request, allowing the caller to customize the exception.
-
timeoutRegistration
public void timeoutRegistration(com.couchbase.client.core.deps.io.netty.util.Timeout registration)
Description copied from interface:Request
Sets the timeout registration used to cancel when complete.- Specified by:
timeoutRegistration
in interfaceRequest<R extends Response>
- Parameters:
registration
- the registration for the timeout timer.
-
completed
public boolean completed()
Description copied from interface:Request
Allows to check if this request is completed already.
-
succeeded
public boolean succeeded()
Description copied from interface:Request
Allows to check if this request has been successfully completed.
-
failed
public boolean failed()
Description copied from interface:Request
Allows to check if this request has been completed but with an exception.
-
cancelled
public boolean cancelled()
Description copied from interface:Request
Allows to check if this request has been cancelled before it got a chance to be either failed or succeeded.
-
cancellationReason
public CancellationReason cancellationReason()
Description copied from interface:Request
If the request isRequest.cancelled()
, this returns the reason why.- Specified by:
cancellationReason
in interfaceRequest<R extends Response>
- Returns:
- the cancellation reason if cancelled, null otherwise.
-
context
public RequestContext context()
Description copied from interface:Request
If attached, returns the context for this request.
-
timeout
public Duration timeout()
Description copied from interface:Request
Returns the timeout for this request.
-
timeoutElapsed
public boolean timeoutElapsed()
Description copied from interface:Request
Returns true if the timeout elapsed.- Specified by:
timeoutElapsed
in interfaceRequest<R extends Response>
-
absoluteTimeout
public long absoluteTimeout()
Description copied from interface:Request
The absolute timestamp when the request should time out.- Specified by:
absoluteTimeout
in interfaceRequest<R extends Response>
- Returns:
- the absolute timeout in nanoseconds.
-
id
public long id()
Description copied from interface:Request
Holds a unique ID for each request that is assigned automatically.
-
retryStrategy
public RetryStrategy retryStrategy()
Description copied from interface:Request
The retry strategy for this particular request.- Specified by:
retryStrategy
in interfaceRequest<R extends Response>
- Returns:
- the retry strategy for this request.
-
serviceContext
public Map<String,Object> serviceContext()
Description copied from interface:Request
Returns contextual information for each individual service.- Specified by:
serviceContext
in interfaceRequest<R extends Response>
- Returns:
- the service context.
-
createdAt
public long createdAt()
Description copied from interface:Request
Holds the nanoTime when the request got created.
-
requestSpan
public RequestSpan requestSpan()
Description copied from interface:Request
Holds the internal span for this request.- Specified by:
requestSpan
in interfaceRequest<R extends Response>
- Returns:
- the internal span used for the request.
-
-