Package com.linecorp.armeria.common
Class AbstractRequestContextBuilder
java.lang.Object
com.linecorp.armeria.common.AbstractRequestContextBuilder
- Direct Known Subclasses:
ClientRequestContextBuilder
,ServiceRequestContextBuilder
Provides the information required for building a
RequestContext
.- See Also:
-
Constructor Summary
ModifierConstructorDescriptionprotected
AbstractRequestContextBuilder
(boolean server, HttpRequest req) Creates a new builder with the specifiedHttpRequest
.protected
AbstractRequestContextBuilder
(boolean server, RpcRequest rpcReq, URI uri) Creates a new builder with the specifiedRpcRequest
andURI
. -
Method Summary
Modifier and TypeMethodDescriptionprotected final ByteBufAllocator
alloc()
Returns theByteBufAllocator
.alloc
(ByteBufAllocator alloc) Sets theByteBufAllocator
.protected final String
Returns the authority of the request.Returns theEventLoop
that handles the request.Sets theEventLoop
that handles the request.protected final Channel
fakeChannel
(EventLoop eventLoop) Returns a fakeChannel
which is required internally when creating a context.protected final RequestId
id()
Returns theRequestId
.Sets theRequestId
.protected final boolean
Returns whether the request start time has been specified.protected final InetSocketAddress
Returns the local socket address of the connection.localAddress
(InetSocketAddress localAddress) Sets the local socket address of the connection.protected final MeterRegistry
Returns theMeterRegistry
.meterRegistry
(MeterRegistry meterRegistry) Sets theMeterRegistry
.protected final HttpMethod
method()
Returns theHttpMethod
of the request.protected AbstractRequestContextBuilder
method
(HttpMethod method) Sets theHttpMethod
of the request.protected final InetSocketAddress
Returns the remote socket address of the connection.remoteAddress
(InetSocketAddress remoteAddress) Sets the remote socket address of the connection.protected final @Nullable HttpRequest
request()
Returns theHttpRequest
of the context.requestStartTime
(long requestStartTimeNanos, long requestStartTimeMicros) Sets the request start time of the request.protected final long
Returns the number of microseconds since the epoch when the request started.protected final long
Returns theSystem.nanoTime()
value when the request started.protected final RequestTarget
Returns theRequestTarget
.protected final @Nullable RpcRequest
Returns theRpcRequest
of the context.protected final SessionProtocol
Returns theSessionProtocol
of the request.sessionProtocol
(SessionProtocol sessionProtocol) Sets theSessionProtocol
of the request.protected final @Nullable SSLSession
Returns theSSLSession
of the connection.sslSession
(SSLSession sslSession) Sets theSSLSession
of the connection.protected final boolean
timedOut()
Returns whether a timeout is set.timedOut
(boolean timedOut) Sets the specifiedtimedOut
.
-
Constructor Details
-
AbstractRequestContextBuilder
Creates a new builder with the specifiedHttpRequest
.- Parameters:
server
- whether this builder will build a server-side context.req
- theHttpRequest
.
-
AbstractRequestContextBuilder
Creates a new builder with the specifiedRpcRequest
andURI
.- Parameters:
server
- whether this builder will build a server-side context.rpcReq
- theRpcRequest
.uri
- theURI
of the request endpoint.
-
-
Method Details
-
meterRegistry
Returns theMeterRegistry
. -
meterRegistry
Sets theMeterRegistry
. If not set,NoopMeterRegistry
is used. -
eventLoop
Returns theEventLoop
that handles the request. -
eventLoop
Sets theEventLoop
that handles the request. If not set, one of theCommonPools.workerGroup()
is used. -
alloc
Returns theByteBufAllocator
. -
alloc
Sets theByteBufAllocator
. If not set,ByteBufAllocator.DEFAULT
is used. -
request
Returns theHttpRequest
of the context. -
rpcRequest
Returns theRpcRequest
of the context. -
sessionProtocol
Returns theSessionProtocol
of the request. -
sessionProtocol
Sets theSessionProtocol
of the request.- Throws:
IllegalArgumentException
- if the specifiedSessionProtocol
is not compatible with the scheme of theURI
you specified when creating this builder. For example, you cannot specifySessionProtocol.H2C
if you created this builder withh1c://example.com/
.
-
remoteAddress
Returns the remote socket address of the connection. -
remoteAddress
Sets the remote socket address of the connection. If not set, it is auto-generated with the localhost IP address (e.g."127.0.0.1"
or"::1"
). -
localAddress
Returns the local socket address of the connection. -
localAddress
Sets the local socket address of the connection. If not set, it is auto-generated with the localhost IP address (e.g."127.0.0.1"
or"::1"
). -
sslSession
Returns theSSLSession
of the connection.- Returns:
- the
SSLSession
, ornull
if theSessionProtocol
is not TLS.
-
sslSession
Sets theSSLSession
of the connection. If the currentSessionProtocol
is not TLS, the TLS version of the currentSessionProtocol
will be set automatically. For example,SessionProtocol.H2C
will be automatically upgraded toSessionProtocol.H2
. Note that upgrading the currentSessionProtocol
may trigger anIllegalArgumentException
, as described insessionProtocol(SessionProtocol)
. -
isRequestStartTimeSet
protected final boolean isRequestStartTimeSet()Returns whether the request start time has been specified. If not specified, the builder will use the current time returned byrequestStartTimeNanos()
andrequestStartTimeMicros()
as the request start time. -
requestStartTimeNanos
protected final long requestStartTimeNanos()Returns theSystem.nanoTime()
value when the request started.- Throws:
IllegalStateException
- if the request start time is unspecified.
-
requestStartTimeMicros
protected final long requestStartTimeMicros()Returns the number of microseconds since the epoch when the request started.- Throws:
IllegalStateException
- if the request start time is unspecified.
-
requestStartTime
public AbstractRequestContextBuilder requestStartTime(long requestStartTimeNanos, long requestStartTimeMicros) Sets the request start time of the request.- Parameters:
requestStartTimeNanos
- theSystem.nanoTime()
value when the request started.requestStartTimeMicros
- the number of microseconds since the epoch when the request started.
-
method
Returns theHttpMethod
of the request. -
method
Sets theHttpMethod
of the request.- Throws:
IllegalArgumentException
- if the specifiedHttpMethod
is not same with theHttpMethod
of theHttpRequest
you specified when creating this builder. This exception is not thrown if you created a builder with anRpcRequest
.
-
authority
Returns the authority of the request. -
requestTarget
Returns theRequestTarget
. -
id
-
id
Returns theRequestId
. -
fakeChannel
Returns a fakeChannel
which is required internally when creating a context. -
timedOut
protected final boolean timedOut()Returns whether a timeout is set. -
timedOut
Sets the specifiedtimedOut
. If the specifiedtimedOut
istrue
,RequestContext.isTimedOut()
will always returntrue
. This is useful for checking the behavior of aService
andClient
when a request exceeds a deadline.
-