Package com.linecorp.armeria.client
Class ClientRequestContextWrapper
java.lang.Object
com.linecorp.armeria.common.util.AbstractUnwrappable<ClientRequestContext>
com.linecorp.armeria.common.RequestContextWrapper<ClientRequestContext>
com.linecorp.armeria.client.ClientRequestContextWrapper
- All Implemented Interfaces:
ClientRequestContext
,RequestContext
,Unwrappable
public class ClientRequestContextWrapper
extends RequestContextWrapper<ClientRequestContext>
implements ClientRequestContext
Wraps an existing
ClientRequestContext
.-
Constructor Summary
ModifierConstructorDescriptionprotected
Creates a new instance. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addAdditionalRequestHeader
(CharSequence name, Object value) Adds a header with the specifiedname
andvalue
.Returns the authority which will eventually be sent when aClient
sends anHttpRequest
.void
Clears the previously scheduled response timeout, if any.endpoint()
Returns theEndpointGroup
used for the currentRequest
.fragment()
Returns the fragment part of the URI of the currentRequest
, as defined in the section 3.5 of RFC3986.hook()
Returns the hook which is invoked whenever thisRequestContext
is pushed to theRequestContextStorage
.void
hook
(Supplier<? extends AutoCloseable> contextHook) Adds a hook which is invoked whenever thisRequestContext
is pushed to theRequestContextStorage
.host()
Returns the host part ofClientRequestContext.authority()
, without a port number.boolean
Returns whether thisRequestContext
has been cancelled.boolean
Returns whether thisRequestContext
has been timed-out, that is the cancellation cause is an instance ofTimeoutException
.long
Returns the maximum length of the receivedResponse
.void
newDerivedContext
(RequestId id, @Nullable HttpRequest req, @Nullable RpcRequest rpcReq, @Nullable Endpoint endpoint) Creates a newClientRequestContext
whose properties andAttribute
s are copied from thisClientRequestContext
, except having differentRequest
,Endpoint
and its ownRequestLog
.options()
Returns theClientOptions
of the currentRequest
.long
void
setAdditionalRequestHeader
(CharSequence name, Object value) Sets a header with the specifiedname
andvalue
.void
setMaxResponseLength
(long maxResponseLength) Sets the maximum length of the receivedResponse
.void
setResponseTimeout
(TimeoutMode mode, Duration responseTimeout) Schedules the response timeout that is triggered when theResponse
is not fully received within the specifiedTimeoutMode
and the specifiedresponseTimeoutMillis
since theResponse
started orRequest
was fully sent.void
setResponseTimeoutMillis
(TimeoutMode mode, long responseTimeoutMillis) Schedules the response timeout that is triggered when theResponse
is not fully received within the specifiedTimeoutMode
and the specifiedresponseTimeoutMillis
since theResponse
started orRequest
was fully sent.void
setWriteTimeout
(Duration writeTimeout) Sets the amount of time allowed until the initial write attempt of the currentRequest
succeeds.void
setWriteTimeoutMillis
(long writeTimeoutMillis) Sets the amount of time allowed until the initial write attempt of the currentRequest
succeeds.Unwraps this object and returns the innermost object being decorated.uri()
Returns aCompletableFuture
which is completed with aThrowable
cancellation cause after theClientRequestContext
has been cancelled.Returns aCompletableFuture
which is completed with aThrowable
cancellation cause when theClientRequestContext
is about to get cancelled.Deprecated.Deprecated.long
Returns the amount of time allowed until the initial write attempt of the currentRequest
succeeds.Methods inherited from class com.linecorp.armeria.common.RequestContextWrapper
alloc, attr, attrs, cancel, cancel, cancellationCause, decodedPath, delegate, eventLoop, hasAttr, hasOwnAttr, id, initiateConnectionShutdown, localAddress, log, logBuilder, meterRegistry, method, ownAttr, ownAttrs, path, query, remoteAddress, request, requestAutoAbortDelayMillis, root, rpcRequest, sessionProtocol, setAttr, setRequestAutoAbortDelay, setRequestAutoAbortDelayMillis, sslSession, timeoutNow, toString, updateRequest, updateRpcRequest
Methods inherited from class com.linecorp.armeria.common.util.AbstractUnwrappable
as, unwrap
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface com.linecorp.armeria.client.ClientRequestContext
cancel, initiateConnectionShutdown, push, request, rpcRequest, setResponseTimeout, setResponseTimeoutMillis, timeoutNow, unwrap
Methods inherited from interface com.linecorp.armeria.common.RequestContext
alloc, attr, attrs, cancel, cancellationCause, decodedPath, eventLoop, hasAttr, hasOwnAttr, id, localAddress, log, logBuilder, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, meterRegistry, method, ownAttr, ownAttrs, path, query, remoteAddress, replace, requestAutoAbortDelayMillis, root, run, run, sessionProtocol, setAttr, setRequestAutoAbortDelay, setRequestAutoAbortDelayMillis, sslSession, updateRequest, updateRpcRequest
Methods inherited from interface com.linecorp.armeria.common.util.Unwrappable
as, equalsIgnoreWrapper
-
Constructor Details
-
ClientRequestContextWrapper
Creates a new instance.
-
-
Method Details
-
newDerivedContext
public ClientRequestContext newDerivedContext(RequestId id, @Nullable @Nullable HttpRequest req, @Nullable @Nullable RpcRequest rpcReq, @Nullable @Nullable Endpoint endpoint) Description copied from interface:ClientRequestContext
Creates a newClientRequestContext
whose properties andAttribute
s are copied from thisClientRequestContext
, except having differentRequest
,Endpoint
and its ownRequestLog
.Note that this method does not copy the
RequestLog
properties to the derived context.- Specified by:
newDerivedContext
in interfaceClientRequestContext
-
endpointGroup
Description copied from interface:ClientRequestContext
Returns theEndpointGroup
used for the currentRequest
.- Specified by:
endpointGroup
in interfaceClientRequestContext
- Returns:
- the
EndpointGroup
if a user specified anEndpointGroup
when initiating aRequest
.null
if a user specified anEndpoint
.
-
endpoint
Description copied from interface:ClientRequestContext
- Specified by:
endpoint
in interfaceClientRequestContext
- Returns:
- the remote
Endpoint
, ornull
if theRequest
has failed because its remoteEndpoint
couldn't be determined.
-
fragment
Description copied from interface:ClientRequestContext
Returns the fragment part of the URI of the currentRequest
, as defined in the section 3.5 of RFC3986.- Specified by:
fragment
in interfaceClientRequestContext
- Returns:
- the fragment part of the request URI, or
null
if no fragment was specified
-
authority
Description copied from interface:ClientRequestContext
Returns the authority which will eventually be sent when aClient
sends anHttpRequest
. This method checks the following locations and returns the first non-null value.- Specified by:
authority
in interfaceClientRequestContext
-
host
Description copied from interface:ClientRequestContext
Returns the host part ofClientRequestContext.authority()
, without a port number.- Specified by:
host
in interfaceClientRequestContext
-
uri
Description copied from interface:RequestContext
- Specified by:
uri
in interfaceClientRequestContext
- Specified by:
uri
in interfaceRequestContext
- Overrides:
uri
in classRequestContextWrapper<ClientRequestContext>
- See Also:
-
options
Description copied from interface:ClientRequestContext
Returns theClientOptions
of the currentRequest
.- Specified by:
options
in interfaceClientRequestContext
-
writeTimeoutMillis
public long writeTimeoutMillis()Description copied from interface:ClientRequestContext
Returns the amount of time allowed until the initial write attempt of the currentRequest
succeeds. This value is initially set fromClientOptions.WRITE_TIMEOUT_MILLIS
.- Specified by:
writeTimeoutMillis
in interfaceClientRequestContext
-
setWriteTimeoutMillis
public void setWriteTimeoutMillis(long writeTimeoutMillis) Description copied from interface:ClientRequestContext
Sets the amount of time allowed until the initial write attempt of the currentRequest
succeeds. This value is initially set fromClientOptions.WRITE_TIMEOUT_MILLIS
.- Specified by:
setWriteTimeoutMillis
in interfaceClientRequestContext
-
setWriteTimeout
Description copied from interface:ClientRequestContext
Sets the amount of time allowed until the initial write attempt of the currentRequest
succeeds. This value is initially set fromClientOptions.WRITE_TIMEOUT_MILLIS
.- Specified by:
setWriteTimeout
in interfaceClientRequestContext
-
responseTimeoutMillis
public long responseTimeoutMillis()Description copied from interface:ClientRequestContext
Returns the amount of time allowed until receiving theResponse
completely since the transfer of theResponse
started or theRequest
was fully sent. This value is initially set fromClientOptions.RESPONSE_TIMEOUT_MILLIS
.- Specified by:
responseTimeoutMillis
in interfaceClientRequestContext
-
clearResponseTimeout
public void clearResponseTimeout()Description copied from interface:ClientRequestContext
Clears the previously scheduled response timeout, if any. Note that calling this will prevent the response from ever being timed out.- Specified by:
clearResponseTimeout
in interfaceClientRequestContext
-
setResponseTimeoutMillis
Description copied from interface:ClientRequestContext
Schedules the response timeout that is triggered when theResponse
is not fully received within the specifiedTimeoutMode
and the specifiedresponseTimeoutMillis
since theResponse
started orRequest
was fully sent. This value is initially set fromClientOptions.RESPONSE_TIMEOUT_MILLIS
.timeout mode description Timeout mode description TimeoutMode.SET_FROM_NOW
Sets a given amount of timeout from the current time. TimeoutMode.SET_FROM_START
Sets a given amount of timeout since the current Response
began processing.TimeoutMode.EXTEND
Extends the previously scheduled timeout by the given amount of timeout. For example:
ClientRequestContext ctx = ...; // Schedules a timeout from the start time of the response ctx.setResponseTimeoutMillis(TimeoutMode.SET_FROM_START, 2000); assert ctx.responseTimeoutMillis() == 2000; ctx.setResponseTimeoutMillis(TimeoutMode.SET_FROM_START, 1000); assert ctx.responseTimeoutMillis() == 1000; // Schedules timeout after 3 seconds from now. ctx.setResponseTimeoutMillis(TimeoutMode.SET_FROM_NOW, 3000); // Extends the previously scheduled timeout. long oldResponseTimeoutMillis = ctx.responseTimeoutMillis(); ctx.setResponseTimeoutMillis(TimeoutMode.EXTEND, 1000); assert ctx.responseTimeoutMillis() == oldResponseTimeoutMillis + 1000; ctx.extendResponseTimeoutMillis(TimeoutMode.EXTEND, -500); assert ctx.responseTimeoutMillis() == oldResponseTimeoutMillis + 500;
- Specified by:
setResponseTimeoutMillis
in interfaceClientRequestContext
-
setResponseTimeout
Description copied from interface:ClientRequestContext
Schedules the response timeout that is triggered when theResponse
is not fully received within the specifiedTimeoutMode
and the specifiedresponseTimeoutMillis
since theResponse
started orRequest
was fully sent. This value is initially set fromClientOptions.RESPONSE_TIMEOUT_MILLIS
.timeout mode description Timeout mode description TimeoutMode.SET_FROM_NOW
Sets a given amount of timeout from the current time. TimeoutMode.SET_FROM_START
Sets a given amount of timeout since the current Response
began processing.TimeoutMode.EXTEND
Extends the previously scheduled timeout by the given amount of timeout. For example:
ClientRequestContext ctx = ...; // Schedules a timeout from the start time of the response ctx.setResponseTimeoutMillis(TimeoutMode.SET_FROM_START, Duration.ofSeconds(2)); assert ctx.responseTimeoutMillis() == 2000; ctx.setResponseTimeoutMillis(TimeoutMode.SET_FROM_START, Duration.ofSeconds(1)); assert ctx.responseTimeoutMillis() == 1000; // Schedules timeout after 3 seconds from now. ctx.setResponseTimeoutMillis(TimeoutMode.SET_FROM_NOW, Duration.ofSeconds(3)); // Extends the previously scheduled timeout. long oldResponseTimeoutMillis = ctx.responseTimeoutMillis(); ctx.setResponseTimeoutMillis(TimeoutMode.EXTEND, Duration.ofSeconds(1)); assert ctx.responseTimeoutMillis() == oldResponseTimeoutMillis + 1000; ctx.setResponseTimeoutMillis(TimeoutMode.EXTEND, Duration.ofMillis(-500)); assert ctx.responseTimeoutMillis() == oldResponseTimeoutMillis + 500;
- Specified by:
setResponseTimeout
in interfaceClientRequestContext
-
maxResponseLength
public long maxResponseLength()Description copied from interface:ClientRequestContext
Returns the maximum length of the receivedResponse
. This value is initially set fromClientOptions.MAX_RESPONSE_LENGTH
.- Specified by:
maxResponseLength
in interfaceClientRequestContext
- Returns:
- the maximum length of the response.
0
if unlimited. - See Also:
-
setMaxResponseLength
public void setMaxResponseLength(long maxResponseLength) Description copied from interface:ClientRequestContext
Sets the maximum length of the receivedResponse
. This value is initially set fromClientOptions.MAX_RESPONSE_LENGTH
. Specify0
to disable the limit of the length of a response.- Specified by:
setMaxResponseLength
in interfaceClientRequestContext
- See Also:
-
defaultRequestHeaders
Description copied from interface:ClientRequestContext
Returns the defaultHttpHeaders
which will be included when aClient
sends anHttpRequest
.Note that the values of the default
HttpHeaders
could be overridden if the sameHttpHeaderNames
are defined inHttpRequest.headers()
orClientRequestContext.additionalRequestHeaders()
.- Specified by:
defaultRequestHeaders
in interfaceClientRequestContext
- See Also:
-
additionalRequestHeaders
Description copied from interface:ClientRequestContext
- Specified by:
additionalRequestHeaders
in interfaceClientRequestContext
-
setAdditionalRequestHeader
Description copied from interface:ClientRequestContext
Sets a header with the specifiedname
andvalue
. This will remove all previous values associated with the specifiedname
. The header will be included when aClient
sends anHttpRequest
.- Specified by:
setAdditionalRequestHeader
in interfaceClientRequestContext
-
addAdditionalRequestHeader
Description copied from interface:ClientRequestContext
Adds a header with the specifiedname
andvalue
. The header will be included when aClient
sends anHttpRequest
.- Specified by:
addAdditionalRequestHeader
in interfaceClientRequestContext
-
mutateAdditionalRequestHeaders
Description copied from interface:ClientRequestContext
- Specified by:
mutateAdditionalRequestHeaders
in interfaceClientRequestContext
- Parameters:
mutator
- theConsumer
that mutates the additional request headers
-
exchangeType
Description copied from interface:RequestContext
- Specified by:
exchangeType
in interfaceClientRequestContext
- Specified by:
exchangeType
in interfaceRequestContext
- Overrides:
exchangeType
in classRequestContextWrapper<ClientRequestContext>
-
hook
Description copied from interface:RequestContext
Adds a hook which is invoked whenever thisRequestContext
is pushed to theRequestContextStorage
. TheAutoCloseable
returned bycontextHook
will be called whenever thisRequestContext
is popped from theRequestContextStorage
. This method is useful when you need to propagate a custom context in thisRequestContext
's scope.Note:
- The
contextHook
is not invoked when thisRequestContext.hook(Supplier)
method is called thus you need to call it yourself if you want to apply the hook in the current thread. - This operation is highly performance-sensitive operation, and thus it's not a good idea to run a time-consuming task.
- Specified by:
hook
in interfaceRequestContext
- The
-
hook
Description copied from interface:RequestContext
Returns the hook which is invoked whenever thisRequestContext
is pushed to theRequestContextStorage
. TheSafeCloseable
returned by theSupplier
will be called whenever thisRequestContext
is popped from theRequestContextStorage
.- Specified by:
hook
in interfaceRequestContext
-
isCancelled
public boolean isCancelled()Description copied from interface:RequestContext
Returns whether thisRequestContext
has been cancelled.- Specified by:
isCancelled
in interfaceRequestContext
-
isTimedOut
public boolean isTimedOut()Description copied from interface:RequestContext
Returns whether thisRequestContext
has been timed-out, that is the cancellation cause is an instance ofTimeoutException
.- Specified by:
isTimedOut
in interfaceRequestContext
-
whenResponseCancelling
Description copied from interface:ClientRequestContext
Returns aCompletableFuture
which is completed with aThrowable
cancellation cause when theClientRequestContext
is about to get cancelled. If the response is handled successfully without cancellation, theCompletableFuture
won't complete.- Specified by:
whenResponseCancelling
in interfaceClientRequestContext
-
whenResponseCancelled
Description copied from interface:ClientRequestContext
Returns aCompletableFuture
which is completed with aThrowable
cancellation cause after theClientRequestContext
has been cancelled.RequestContext.isCancelled()
will always returntrue
when the returnedCompletableFuture
is completed. If the response is handled successfully without cancellation, theCompletableFuture
won't complete.- Specified by:
whenResponseCancelled
in interfaceClientRequestContext
-
whenResponseTimingOut
Deprecated.Description copied from interface:ClientRequestContext
Returns aCompletableFuture
which is completed when theClientRequestContext
is about to get timed out. If the response is handled successfully or not cancelled by timeout, theCompletableFuture
won't complete.- Specified by:
whenResponseTimingOut
in interfaceClientRequestContext
-
whenResponseTimedOut
Deprecated.Description copied from interface:ClientRequestContext
Returns aCompletableFuture
which is completed after theClientRequestContext
has been timed out.RequestContext.isTimedOut()
will always returntrue
when the returnedCompletableFuture
is completed. If the response is handled successfully or not cancelled by timeout, theCompletableFuture
won't complete.- Specified by:
whenResponseTimedOut
in interfaceClientRequestContext
-
unwrapAll
Description copied from interface:Unwrappable
Unwraps this object and returns the innermost object being decorated. If thisUnwrappable
is the innermost object, this method returns itself. For example:class Foo implements Unwrappable {} class Bar<T extends Unwrappable> extends AbstractUnwrappable<T> { Bar(T delegate) { super(delegate); } } class Qux<T extends Unwrappable> extends AbstractUnwrappable<T> { Qux(T delegate) { super(delegate); } } Foo foo = new Foo(); assert foo.unwrapAll() == foo; Bar<Foo> bar = new Bar<>(foo); assert bar.unwrapAll() == foo; Qux<Bar<Foo>> qux = new Qux<>(bar); assert qux.unwrap() == bar; assert qux.unwrapAll() == foo;
- Specified by:
unwrapAll
in interfaceClientRequestContext
- Specified by:
unwrapAll
in interfaceRequestContext
- Specified by:
unwrapAll
in interfaceUnwrappable
- Overrides:
unwrapAll
in classRequestContextWrapper<ClientRequestContext>
-