public class ClientRequestContextWrapper extends RequestContextWrapper<ClientRequestContext> implements ClientRequestContext
ClientRequestContext.| Modifier | Constructor and Description |
|---|---|
protected |
ClientRequestContextWrapper(ClientRequestContext delegate)
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()
|
void |
clearResponseTimeout()
Clears the previously scheduled response timeout, if any.
|
Endpoint |
endpoint()
|
EndpointGroup |
endpointGroup()
Returns the
EndpointGroup used for 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. |
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. |
<V> V |
ownAttr(io.netty.util.AttributeKey<V> key)
Returns the value mapped to the given
AttributeKey or null if there's no value set by
RequestContext.setAttr(AttributeKey, Object) or RequestContext.setAttrIfAbsent(AttributeKey, Object). |
Iterator<Map.Entry<io.netty.util.AttributeKey<?>,Object>> |
ownAttrs()
|
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)
Deprecated.
|
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)
Deprecated.
|
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. |
long |
writeTimeoutMillis()
Returns the amount of time allowed until the initial write attempt of the current
Request
succeeds. |
alloc, attr, attrs, computeAttrIfAbsent, decodedPath, delegate, eventLoop, id, localAddress, log, logBuilder, meterRegistry, method, path, query, remoteAddress, request, rpcRequest, sessionProtocol, setAttr, setAttrIfAbsent, sslSession, updateRequest, updateRpcRequestclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitattr, attrs, builder, builder, builder, current, currentOrNull, mapCurrent, newDerivedContext, of, of, of, push, request, rpcRequestalloc, computeAttrIfAbsent, contextAwareEventLoop, contextAwareExecutor, decodedPath, eventLoop, executor, id, localAddress, log, logBuilder, 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, sslSession, updateRequest, updateRpcRequestprotected ClientRequestContextWrapper(ClientRequestContext delegate)
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 <V> V ownAttr(io.netty.util.AttributeKey<V> key)
ClientRequestContextAttributeKey or null if there's no value set by
RequestContext.setAttr(AttributeKey, Object) or RequestContext.setAttrIfAbsent(AttributeKey, Object).
Unlike ClientRequestContext.attr(AttributeKey), this does not search in ClientRequestContext.root().ownAttr in interface ClientRequestContextClientRequestContext.attr(AttributeKey)public Iterator<Map.Entry<io.netty.util.AttributeKey<?>,Object>> ownAttrs()
ClientRequestContextIterator of all Map.Entrys this context contains.
Unlike ClientRequestContext.attrs(), this does not iterate ClientRequestContext.root().ownAttrs in interface ClientRequestContextClientRequestContext.attrs()public 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 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 ClientOptions options()
ClientRequestContextClientOptions of the current Request.options in interface ClientRequestContextpublic 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 ClientRequestContext@Deprecated public 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 response@Deprecated public 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 removedCopyright © 2020 LeanCloud. All rights reserved.