Package com.linecorp.armeria.client
Class ClientRequestContextWrapper
java.lang.Object
com.linecorp.armeria.common.RequestContextWrapper<ClientRequestContext>
com.linecorp.armeria.client.ClientRequestContextWrapper
- All Implemented Interfaces:
ClientRequestContext
,RequestContext
public class ClientRequestContextWrapper extends RequestContextWrapper<ClientRequestContext> implements ClientRequestContext
Wraps an existing
ClientRequestContext
.-
Constructor Summary
Constructors Modifier Constructor Description protected
ClientRequestContextWrapper(ClientRequestContext delegate)
Creates a new instance. -
Method Summary
Modifier and Type Method Description void
addAdditionalRequestHeader(CharSequence name, Object value)
Adds a header with the specifiedname
andvalue
.HttpHeaders
additionalRequestHeaders()
void
clearResponseTimeout()
Clears the previously scheduled response timeout, if any.Endpoint
endpoint()
EndpointGroup
endpointGroup()
Returns theEndpointGroup
used for the currentRequest
.String
fragment()
Returns the fragment part of the URI of the currentRequest
, as defined in the section 3.5 of RFC3986.boolean
isTimedOut()
Returns whether thisRequestContext
has been timed-out (e.g., when the corresponding request passes a deadline).long
maxResponseLength()
Returns the maximum length of the receivedResponse
.void
mutateAdditionalRequestHeaders(Consumer<HttpHeadersBuilder> mutator)
ClientRequestContext
newDerivedContext(RequestId id, HttpRequest req, RpcRequest rpcReq, Endpoint endpoint)
Creates a newClientRequestContext
whose properties andAttribute
s are copied from thisClientRequestContext
, except having differentRequest
,Endpoint
and its ownRequestLog
.ClientOptions
options()
Returns theClientOptions
of the currentRequest
.Runnable
responseTimeoutHandler()
ReturnsResponse
timeout handler which is executed when theResponse
is not completely received within the allowedClientRequestContext.responseTimeoutMillis()
or the defaultClientOption.RESPONSE_TIMEOUT_MILLIS
.long
responseTimeoutMillis()
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
setResponseTimeoutAtMillis(long responseTimeoutAtMillis)
Deprecated.void
setResponseTimeoutHandler(Runnable responseTimeoutHandler)
Sets a handler to run when the response times out.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)
Returns the amount of time allowed until the initial write attempt of the currentRequest
succeeds.void
setWriteTimeoutMillis(long writeTimeoutMillis)
Returns the amount of time allowed until the initial write attempt of the currentRequest
succeeds.void
timeoutNow()
Triggers the current timeout immediately if a timeout was scheduled before.long
writeTimeoutMillis()
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, computeAttrIfAbsent, decodedPath, delegate, eventLoop, id, localAddress, log, logBuilder, meterRegistry, method, ownAttr, ownAttrs, path, query, remoteAddress, request, root, rpcRequest, sessionProtocol, setAttr, setAttrIfAbsent, sslSession, toString, updateRequest, updateRpcRequest
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
extendResponseTimeout, extendResponseTimeoutMillis, newDerivedContext, push, request, rpcRequest, setResponseTimeout, setResponseTimeout, setResponseTimeoutAfter, setResponseTimeoutAfterMillis, setResponseTimeoutAt, setResponseTimeoutMillis
Methods inherited from interface com.linecorp.armeria.common.RequestContext
alloc, attr, attrs, computeAttrIfAbsent, contextAwareEventLoop, contextAwareExecutor, decodedPath, eventLoop, executor, id, localAddress, log, logBuilder, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, meterRegistry, method, ownAttr, ownAttrs, path, query, remoteAddress, replace, root, sessionProtocol, setAttr, setAttrIfAbsent, sslSession, updateRequest, updateRpcRequest
-
Constructor Details
-
ClientRequestContextWrapper
Creates a new instance.
-
-
Method Details
-
newDerivedContext
public ClientRequestContext newDerivedContext(RequestId id, @Nullable HttpRequest req, @Nullable RpcRequest rpcReq, @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
-
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 fromClientOption.WRITE_TIMEOUT_MILLIS
.- Specified by:
writeTimeoutMillis
in interfaceClientRequestContext
-
setWriteTimeoutMillis
public void setWriteTimeoutMillis(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 fromClientOption.WRITE_TIMEOUT_MILLIS
.- Specified by:
setWriteTimeoutMillis
in interfaceClientRequestContext
-
setWriteTimeout
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 fromClientOption.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. This value is initially set fromClientOption.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 fromClientOption.RESPONSE_TIMEOUT_MILLIS
.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
-
setResponseTimeoutAtMillis
Deprecated.Description copied from interface:ClientRequestContext
Schedules the response timeout that is triggered at the specified time represented as the number since the epoch (1970-01-01T00:00:00Z
). Note that the response will be timed out immediately if the specified time is before now. The initial timeout is set fromClientOption.RESPONSE_TIMEOUT_MILLIS
.For example:
ClientRequestContext ctx = ...; // Schedules timeout after 1 seconds from now. long responseTimeoutAt = Instant.now().plus(1, ChronoUnit.SECONDS).toEpochMilli(); ctx.setResponseTimeoutAtMillis(responseTimeoutAt);
- Specified by:
setResponseTimeoutAtMillis
in interfaceClientRequestContext
- Parameters:
responseTimeoutAtMillis
- the response timeout represented as the number of milliseconds since the epoch (1970-01-01T00:00:00Z
)
-
responseTimeoutHandler
Description copied from interface:ClientRequestContext
ReturnsResponse
timeout handler which is executed when theResponse
is not completely received within the allowedClientRequestContext.responseTimeoutMillis()
or the defaultClientOption.RESPONSE_TIMEOUT_MILLIS
.- Specified by:
responseTimeoutHandler
in interfaceClientRequestContext
-
setResponseTimeoutHandler
Description copied from interface:ClientRequestContext
Sets a handler to run when the response times out.responseTimeoutHandler
must abort the response, e.g., by callingStreamMessage.abort(Throwable)
. If not set, the response will be closed withResponseTimeoutException
.For example,
HttpResponseWriter res = HttpResponse.streaming(); ctx.setResponseTimeoutHandler(() -> { res.abort(new IllegalStateException("Server is in a bad state.")); }); ...
- Specified by:
setResponseTimeoutHandler
in interfaceClientRequestContext
-
maxResponseLength
public long maxResponseLength()Description copied from interface:ClientRequestContext
Returns the maximum length of the receivedResponse
. This value is initially set fromClientOption.MAX_RESPONSE_LENGTH
.- Specified by:
maxResponseLength
in interfaceClientRequestContext
- Returns:
- the maximum length of the response.
0
if unlimited. - See Also:
ContentTooLargeException
-
setMaxResponseLength
public void setMaxResponseLength(long maxResponseLength)Description copied from interface:ClientRequestContext
Sets the maximum length of the receivedResponse
. This value is initially set fromClientOption.MAX_RESPONSE_LENGTH
. Specify0
to disable the limit of the length of a response.- Specified by:
setMaxResponseLength
in interfaceClientRequestContext
- See Also:
ContentTooLargeException
-
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
-
timeoutNow
public void timeoutNow()Description copied from interface:RequestContext
Triggers the current timeout immediately if a timeout was scheduled before. Otherwise, the currentRequest
will be timed-out immediately after a timeout scheduler is initialized.- Specified by:
timeoutNow
in interfaceRequestContext
-
isTimedOut
public boolean isTimedOut()Description copied from interface:RequestContext
Returns whether thisRequestContext
has been timed-out (e.g., when the corresponding request passes a deadline).- Specified by:
isTimedOut
in interfaceRequestContext
-