@UnstableApi public final class DefaultClientRequestContext extends NonWrappingRequestContext implements ClientRequestContext
ClientRequestContext implementation.| Constructor and Description |
|---|
DefaultClientRequestContext(MeterRegistry meterRegistry,
SessionProtocol sessionProtocol,
RequestId id,
HttpMethod method,
String path,
String query,
String fragment,
ClientOptions options,
HttpRequest req,
RpcRequest rpcReq,
long requestStartTimeNanos,
long requestStartTimeMicros)
Creates a new instance.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addAdditionalRequestHeader(CharSequence name,
Object value)
Adds a header with the specified
name and value. |
void |
addAdditionalRequestHeaders(Iterable<? extends Map.Entry<? extends CharSequence,?>> headers)
|
HttpHeaders |
additionalRequestHeaders()
|
io.netty.buffer.ByteBufAllocator |
alloc()
Returns the
ByteBufAllocator for this RequestContext. |
protected io.netty.channel.Channel |
channel()
Returns the
Channel that is handling this request, or null if the connection is not
established yet. |
void |
clearResponseTimeout()
Clears the previously scheduled response timeout, if any.
|
Endpoint |
endpoint()
|
EndpointGroup |
endpointGroup()
Returns the
EndpointGroup used for the current Request. |
io.netty.channel.EventLoop |
eventLoop()
Returns the
EventLoop that is handling the current Request. |
void |
extendResponseTimeout(Duration adjustment)
Extends the previously scheduled response timeout by the specified amount of
adjustment. |
void |
extendResponseTimeoutMillis(long adjustmentMillis)
Extends the previously scheduled response timeout by
the specified amount of
adjustmentMillis. |
String |
fragment()
Returns the fragment part of the URI of the current
Request, as defined in
the section 3.5 of RFC3986. |
boolean |
init(EndpointGroup endpointGroup)
Initializes this context with the specified
EndpointGroup. |
RequestLogAccess |
log()
Returns the
RequestLogAccess that provides the access to the RequestLog, which
contains the information collected while processing the current Request. |
RequestLogBuilder |
logBuilder()
Returns the
RequestLogBuilder that collects the information about the current Request. |
long |
maxResponseLength()
Returns the maximum length of the received
Response. |
ClientRequestContext |
newDerivedContext(RequestId id,
HttpRequest req,
RpcRequest rpcReq,
Endpoint endpoint)
Creates a new
ClientRequestContext whose properties and Attributes are copied from this
ClientRequestContext, except having different Request, Endpoint and its own
RequestLog. |
ClientOptions |
options()
Returns the
ClientOptions of the current Request. |
boolean |
removeAdditionalRequestHeader(CharSequence name)
Removes all headers with the specified
name. |
Runnable |
responseTimeoutHandler()
Returns
Response timeout handler which is executed when
the Response is not completely received within the allowed ClientRequestContext.responseTimeoutMillis()
or the default ClientOption.RESPONSE_TIMEOUT_MILLIS. |
long |
responseTimeoutMillis()
|
ServiceRequestContext |
root()
Returns the
ServiceRequestContext whose Service invokes the Client
Request which created this ClientRequestContext, or null if this client request
was not made in the context of a server request. |
void |
setAdditionalRequestHeader(CharSequence name,
Object value)
Sets a header with the specified
name and value. |
void |
setAdditionalRequestHeaders(Iterable<? extends Map.Entry<? extends CharSequence,?>> headers)
Clears the current header and sets the specified
HttpHeaders which is included when a
Client sends an HttpRequest. |
void |
setMaxResponseLength(long maxResponseLength)
Sets the maximum length of the received
Response. |
void |
setResponseTimeout(Duration responseTimeout)
|
void |
setResponseTimeoutAfter(Duration responseTimeout)
Schedules the response timeout that is triggered when the
Response is not
fully received within the specified amount of time from now. |
void |
setResponseTimeoutAfterMillis(long responseTimeoutMillis)
Schedules the response timeout that is triggered when the
Response is not
fully received within the specified amount of time from now. |
void |
setResponseTimeoutAt(Instant responseTimeoutAt)
Schedules the response timeout that is triggered at the specified time represented
as the number of milliseconds since the epoch (
1970-01-01T00:00:00Z). |
void |
setResponseTimeoutAtMillis(long responseTimeoutAtMillis)
Schedules the response timeout that is triggered at the specified time represented
as the number since the epoch (
1970-01-01T00:00:00Z). |
void |
setResponseTimeoutHandler(Runnable responseTimeoutHandler)
Sets a handler to run when the response times out.
|
void |
setResponseTimeoutMillis(long responseTimeoutMillis)
|
void |
setWriteTimeout(Duration writeTimeout)
Returns the amount of time allowed until the initial write attempt of the current
Request
succeeds. |
void |
setWriteTimeoutMillis(long writeTimeoutMillis)
Returns the amount of time allowed until the initial write attempt of the current
Request
succeeds. |
SSLSession |
sslSession()
The
SSLSession for this request if the connection is made over TLS, or null if
the connection is not established yet or the connection is not a TLS connection. |
String |
toString() |
protected void |
validateHeaders(RequestHeaders headers)
Validates the specified
RequestHeaders. |
long |
writeTimeoutMillis()
Returns the amount of time allowed until the initial write attempt of the current
Request
succeeds. |
attr, attrs, computeAttrIfAbsent, decodedPath, id, localAddress, meterRegistry, method, ownAttr, ownAttrs, path, query, remoteAddress, request, rpcRequest, sessionProtocol, setAttr, setAttrIfAbsent, unsafeUpdateRequest, updateRequest, updateRpcRequestclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitattr, attrs, builder, builder, builder, current, currentOrNull, mapCurrent, newDerivedContext, of, of, of, ownAttr, ownAttrs, push, request, rpcRequestcomputeAttrIfAbsent, contextAwareEventLoop, contextAwareExecutor, decodedPath, executor, id, localAddress, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, mapCurrent, meterRegistry, method, path, push, push, push, pushIfAbsent, query, rejectPromise, remoteAddress, replace, resolvePromise, sessionProtocol, setAttr, setAttrIfAbsent, updateRequest, updateRpcRequestpublic DefaultClientRequestContext(MeterRegistry meterRegistry, SessionProtocol sessionProtocol, RequestId id, HttpMethod method, String path, String query, String fragment, ClientOptions options, HttpRequest req, RpcRequest rpcReq, long requestStartTimeNanos, long requestStartTimeMicros)
init(EndpointGroup) method must be invoked to finish
the construction of this context.sessionProtocol - the SessionProtocol of the invocationid - the RequestId that contains the identifier of the current Request
and Response pair.req - the HttpRequest associated with this contextrpcReq - the RpcRequest associated with this contextrequestStartTimeNanos - System.nanoTime() value when the request started.requestStartTimeMicros - the number of microseconds since the epoch,
e.g. System.currentTimeMillis() * 1000.public boolean init(EndpointGroup endpointGroup)
EndpointGroup.
This method must be invoked to finish the construction of this context.true if the initialization has succeeded.
false if the initialization has failed and this context's RequestLog has been
completed with the cause of the failure.public ServiceRequestContext root()
ClientRequestContextServiceRequestContext whose Service invokes the Client
Request which created this ClientRequestContext, or null if this client request
was not made in the context of a server request.root in interface ClientRequestContextpublic ClientRequestContext newDerivedContext(RequestId id, HttpRequest req, RpcRequest rpcReq, Endpoint endpoint)
ClientRequestContextClientRequestContext whose properties and Attributes are copied from this
ClientRequestContext, except having different Request, Endpoint and its own
RequestLog.newDerivedContext in interface ClientRequestContextprotected void validateHeaders(RequestHeaders headers)
NonWrappingRequestContextRequestHeaders. By default, this method will raise
an IllegalArgumentException if it does not have ":scheme" or ":authority"
header.validateHeaders in class NonWrappingRequestContextprotected io.netty.channel.Channel channel()
NonWrappingRequestContextChannel that is handling this request, or null if the connection is not
established yet.channel in class NonWrappingRequestContextpublic io.netty.channel.EventLoop eventLoop()
RequestContextEventLoop that is handling the current Request.eventLoop in interface RequestContextpublic SSLSession sslSession()
RequestContextSSLSession for this request if the connection is made over TLS, or null if
the connection is not established yet or the connection is not a TLS connection.sslSession in interface RequestContextpublic ClientOptions options()
ClientRequestContextClientOptions of the current Request.options in interface ClientRequestContextpublic EndpointGroup endpointGroup()
ClientRequestContextEndpointGroup used for the current Request.endpointGroup in interface ClientRequestContextEndpointGroup if a user specified an EndpointGroup when initiating
a Request. null if a user specified an Endpoint.public Endpoint endpoint()
ClientRequestContextendpoint in interface ClientRequestContextEndpoint, or null if the Request has failed
because its remote Endpoint couldn't be determined.public String fragment()
ClientRequestContextRequest, as defined in
the section 3.5 of RFC3986.fragment in interface ClientRequestContextnull if no fragment was specifiedpublic long writeTimeoutMillis()
ClientRequestContextRequest
succeeds. This value is initially set from ClientOption.WRITE_TIMEOUT_MILLIS.writeTimeoutMillis in interface ClientRequestContextpublic void setWriteTimeoutMillis(long writeTimeoutMillis)
ClientRequestContextRequest
succeeds. This value is initially set from ClientOption.WRITE_TIMEOUT_MILLIS.setWriteTimeoutMillis in interface ClientRequestContextpublic void setWriteTimeout(Duration writeTimeout)
ClientRequestContextRequest
succeeds. This value is initially set from ClientOption.WRITE_TIMEOUT_MILLIS.setWriteTimeout in interface ClientRequestContextpublic long responseTimeoutMillis()
ClientRequestContextResponse completely
since the transfer of the Response started. This value is initially set from
ClientOption.RESPONSE_TIMEOUT_MILLIS.responseTimeoutMillis in interface ClientRequestContextpublic void clearResponseTimeout()
ClientRequestContextclearResponseTimeout in interface ClientRequestContextpublic void setResponseTimeoutMillis(long responseTimeoutMillis)
ClientRequestContextResponse is not
fully received within the specified amount of time since the Response started
or Request was fully sent.
This value is initially set from ClientOption.RESPONSE_TIMEOUT_MILLIS.
For example:
ClientRequestContext ctx = ...;
ctx.setResponseTimeoutMillis(1000);
assert ctx.responseTimeoutMillis() == 1000;
ctx.setResponseTimeoutMillis(2000);
assert ctx.responseTimeoutMillis() == 2000;
setResponseTimeoutMillis in interface ClientRequestContextresponseTimeoutMillis - the amount of time allowed in milliseconds from
the beginning of the responsepublic void setResponseTimeout(Duration responseTimeout)
ClientRequestContextResponse is not
fully received within the specified amount of time since the Response started
or Request was fully sent.
This value is initially set from ClientOption.RESPONSE_TIMEOUT_MILLIS.
For example:
ClientRequestContext ctx = ...;
ctx.setResponseTimeout(Duration.ofSeconds(1));
assert ctx.responseTimeoutMillis() == 1000;
ctx.setResponseTimeout(Duration.ofSeconds(2));
assert ctx.responseTimeoutMillis() == 2000;
setResponseTimeout in interface ClientRequestContextresponseTimeout - the amount of time allowed from the beginning of the responsepublic void extendResponseTimeoutMillis(long adjustmentMillis)
ClientRequestContextadjustmentMillis.
This method does nothing if no response timeout was scheduled previously.
Note that a negative adjustmentMillis reduces the current timeout.
The initial timeout is set from ClientOption.RESPONSE_TIMEOUT_MILLIS.
For example:
ClientRequestContext ctx = ...;
long oldResponseTimeoutMillis = ctx.responseTimeoutMillis();
ctx.extendResponseTimeoutMillis(1000);
assert ctx.responseTimeoutMillis() == oldResponseTimeoutMillis + 1000;
ctx.extendResponseTimeoutMillis(-500);
assert ctx.responseTimeoutMillis() == oldResponseTimeoutMillis + 500;
extendResponseTimeoutMillis in interface ClientRequestContextadjustmentMillis - the amount of time in milliseconds to extend the current timeout bypublic void extendResponseTimeout(Duration adjustment)
ClientRequestContextadjustment.
This method does nothing if no response timeout was scheduled previously.
Note that a negative adjustment reduces the current timeout.
The initial timeout is set from ClientOption.RESPONSE_TIMEOUT_MILLIS.
For example:
ClientRequestContext ctx = ...;
long oldResponseTimeoutMillis = ctx.responseTimeoutMillis();
ctx.extendResponseTimeout(Duration.ofSeconds(1));
assert ctx.responseTimeoutMillis() == oldResponseTimeoutMillis + 1000;
ctx.extendResponseTimeout(Duration.ofMillis(-500));
assert ctx.responseTimeoutMillis() == oldResponseTimeoutMillis + 500;
extendResponseTimeout in interface ClientRequestContextadjustment - the amount of time to extend the current timeout bypublic void setResponseTimeoutAfterMillis(long responseTimeoutMillis)
ClientRequestContextResponse is not
fully received within the specified amount of time from now.
Note that the specified responseTimeoutMillis must be positive.
The initial timeout is set from ClientOption.RESPONSE_TIMEOUT_MILLIS.
For example:
ClientRequestContext ctx = ...;
// Schedules timeout after 1 seconds from now.
ctx.setResponseTimeoutAfterMillis(1000);
setResponseTimeoutAfterMillis in interface ClientRequestContextresponseTimeoutMillis - the amount of time allowed in milliseconds from nowpublic void setResponseTimeoutAfter(Duration responseTimeout)
ClientRequestContextResponse is not
fully received within the specified amount of time from now.
Note that the specified responseTimeout must be positive.
The initial timeout is set from ClientOption.RESPONSE_TIMEOUT_MILLIS.
For example:
ClientRequestContext ctx = ...;
// Schedules timeout after 1 seconds from now.
ctx.setResponseTimeoutAfter(Duration.ofSeconds(1));
setResponseTimeoutAfter in interface ClientRequestContextresponseTimeout - the amount of time allowed from nowpublic void setResponseTimeoutAtMillis(long responseTimeoutAtMillis)
ClientRequestContext1970-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 from ClientOption.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);
setResponseTimeoutAtMillis in interface ClientRequestContextresponseTimeoutAtMillis - the response timeout represented as the number of milliseconds
since the epoch (1970-01-01T00:00:00Z)public void setResponseTimeoutAt(Instant responseTimeoutAt)
ClientRequestContext1970-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 from ClientOption.RESPONSE_TIMEOUT_MILLIS.
For example:
ClientRequestContext ctx = ...;
// Schedules timeout after 1 seconds from now.
ctx.setResponseTimeoutAt(Instant.now().plus(1, ChronoUnit.SECONDS));
setResponseTimeoutAt in interface ClientRequestContextresponseTimeoutAt - the response timeout represented as the number of milliseconds
since the epoch (1970-01-01T00:00:00Z)public Runnable responseTimeoutHandler()
ClientRequestContextResponse timeout handler which is executed when
the Response is not completely received within the allowed ClientRequestContext.responseTimeoutMillis()
or the default ClientOption.RESPONSE_TIMEOUT_MILLIS.responseTimeoutHandler in interface ClientRequestContextpublic void setResponseTimeoutHandler(Runnable responseTimeoutHandler)
ClientRequestContextresponseTimeoutHandler must abort
the response, e.g., by calling StreamMessage.abort(Throwable).
If not set, the response will be closed with ResponseTimeoutException.
For example,
HttpResponseWriter res = HttpResponse.streaming();
ctx.setResponseTimeoutHandler(() -> {
res.abort(new IllegalStateException("Server is in a bad state."));
});
...
setResponseTimeoutHandler in interface ClientRequestContextpublic long maxResponseLength()
ClientRequestContextResponse.
This value is initially set from ClientOption.MAX_RESPONSE_LENGTH.maxResponseLength in interface ClientRequestContext0 if unlimited.ContentTooLargeExceptionpublic void setMaxResponseLength(long maxResponseLength)
ClientRequestContextResponse.
This value is initially set from ClientOption.MAX_RESPONSE_LENGTH.
Specify 0 to disable the limit of the length of a response.setMaxResponseLength in interface ClientRequestContextContentTooLargeExceptionpublic HttpHeaders additionalRequestHeaders()
ClientRequestContextadditionalRequestHeaders in interface ClientRequestContextpublic void setAdditionalRequestHeader(CharSequence name, Object value)
ClientRequestContextname and value. This will remove all previous values
associated with the specified name.
The header will be included when a Client sends an HttpRequest.setAdditionalRequestHeader in interface ClientRequestContextpublic void setAdditionalRequestHeaders(Iterable<? extends Map.Entry<? extends CharSequence,?>> headers)
ClientRequestContextHttpHeaders which is included when a
Client sends an HttpRequest.setAdditionalRequestHeaders in interface ClientRequestContextpublic void addAdditionalRequestHeader(CharSequence name, Object value)
ClientRequestContextname and value. The header will be included when
a Client sends an HttpRequest.addAdditionalRequestHeader in interface ClientRequestContextpublic void addAdditionalRequestHeaders(Iterable<? extends Map.Entry<? extends CharSequence,?>> headers)
ClientRequestContextaddAdditionalRequestHeaders in interface ClientRequestContextpublic boolean removeAdditionalRequestHeader(CharSequence name)
ClientRequestContextname.removeAdditionalRequestHeader in interface ClientRequestContexttrue if at least one entry has been removedpublic RequestLogAccess log()
RequestContextRequestLogAccess that provides the access to the RequestLog, which
contains the information collected while processing the current Request.log in interface RequestContextpublic RequestLogBuilder logBuilder()
RequestContextRequestLogBuilder that collects the information about the current Request.logBuilder in interface RequestContextpublic io.netty.buffer.ByteBufAllocator alloc()
RequestContextByteBufAllocator for this RequestContext. Any buffers created by this
ByteBufAllocator must be
reference-counted. If you don't know
what this means, you should probably use byte[] or ByteBuffer directly instead
of calling this method.alloc in interface RequestContextCopyright © 2020 LeanCloud. All rights reserved.