Package com.linecorp.armeria.common
Class AbstractRequestContextBuilder
- java.lang.Object
-
- com.linecorp.armeria.common.AbstractRequestContextBuilder
-
- Direct Known Subclasses:
ClientRequestContextBuilder
,ServiceRequestContextBuilder
public abstract class AbstractRequestContextBuilder extends Object
Provides the information required for building aRequestContext
.
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
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 Type Method Description protected ByteBufAllocator
alloc()
Returns theByteBufAllocator
.AbstractRequestContextBuilder
alloc(ByteBufAllocator alloc)
Sets theByteBufAllocator
.protected String
authority()
Returns the authority of the request.protected EventLoop
eventLoop()
Returns theEventLoop
that handles the request.AbstractRequestContextBuilder
eventLoop(EventLoop eventLoop)
Sets theEventLoop
that handles the request.protected Channel
fakeChannel()
Returns a fakeChannel
which is required internally when creating a context.protected RequestId
id()
Returns theRequestId
.AbstractRequestContextBuilder
id(RequestId id)
Sets theRequestId
.protected boolean
isRequestStartTimeSet()
Returns whether the request start time has been specified.protected InetSocketAddress
localAddress()
Returns the local socket address of the connection.AbstractRequestContextBuilder
localAddress(InetSocketAddress localAddress)
Sets the local socket address of the connection.protected MeterRegistry
meterRegistry()
Returns theMeterRegistry
.AbstractRequestContextBuilder
meterRegistry(MeterRegistry meterRegistry)
Sets theMeterRegistry
.protected HttpMethod
method()
Returns theHttpMethod
of the request.protected AbstractRequestContextBuilder
method(HttpMethod method)
Sets theHttpMethod
of the request.protected String
path()
Returns the path of the request, excluding the query part.protected String
query()
Returns the query part of the request, excluding the leading question mark ('?'
).protected InetSocketAddress
remoteAddress()
Returns the remote socket address of the connection.AbstractRequestContextBuilder
remoteAddress(InetSocketAddress remoteAddress)
Sets the remote socket address of the connection.protected HttpRequest
request()
Returns theHttpRequest
of the context.AbstractRequestContextBuilder
requestStartTime(long requestStartTimeNanos, long requestStartTimeMicros)
Sets the request start time of the request.protected long
requestStartTimeMicros()
Returns the number of microseconds since the epoch when the request started.protected long
requestStartTimeNanos()
Returns theSystem.nanoTime()
value when the request started.protected RpcRequest
rpcRequest()
Returns theRpcRequest
of the context.protected SessionProtocol
sessionProtocol()
Returns theSessionProtocol
of the request.AbstractRequestContextBuilder
sessionProtocol(SessionProtocol sessionProtocol)
Sets theSessionProtocol
of the request.protected SSLSession
sslSession()
Returns theSSLSession
of the connection.AbstractRequestContextBuilder
sslSession(SSLSession sslSession)
Sets theSSLSession
of the connection.
-
-
-
Constructor Detail
-
AbstractRequestContextBuilder
protected AbstractRequestContextBuilder(boolean server, HttpRequest req)
Creates a new builder with the specifiedHttpRequest
.- Parameters:
server
- whether this builder will build a server-side context.req
- theHttpRequest
.
-
AbstractRequestContextBuilder
protected AbstractRequestContextBuilder(boolean server, RpcRequest rpcReq, URI uri)
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 Detail
-
meterRegistry
protected final MeterRegistry meterRegistry()
Returns theMeterRegistry
.
-
meterRegistry
public AbstractRequestContextBuilder meterRegistry(MeterRegistry meterRegistry)
Sets theMeterRegistry
. If not set,NoopMeterRegistry
is used.
-
eventLoop
public AbstractRequestContextBuilder eventLoop(EventLoop eventLoop)
Sets theEventLoop
that handles the request. If not set, one of theCommonPools.workerGroup()
is used.
-
alloc
protected final ByteBufAllocator alloc()
Returns theByteBufAllocator
.
-
alloc
public AbstractRequestContextBuilder alloc(ByteBufAllocator alloc)
Sets theByteBufAllocator
. If not set,ByteBufAllocator.DEFAULT
is used.
-
request
@Nullable protected final HttpRequest request()
Returns theHttpRequest
of the context.
-
rpcRequest
@Nullable protected final RpcRequest rpcRequest()
Returns theRpcRequest
of the context.
-
sessionProtocol
protected final SessionProtocol sessionProtocol()
Returns theSessionProtocol
of the request.
-
sessionProtocol
public AbstractRequestContextBuilder sessionProtocol(SessionProtocol 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
protected final InetSocketAddress remoteAddress()
Returns the remote socket address of the connection.
-
remoteAddress
public AbstractRequestContextBuilder remoteAddress(InetSocketAddress 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
protected final InetSocketAddress localAddress()
Returns the local socket address of the connection.
-
localAddress
public AbstractRequestContextBuilder localAddress(InetSocketAddress 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
@Nullable protected final SSLSession sslSession()
Returns theSSLSession
of the connection.- Returns:
- the
SSLSession
, ornull
if theSessionProtocol
is not TLS.
-
sslSession
public AbstractRequestContextBuilder sslSession(SSLSession 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
protected final HttpMethod method()
Returns theHttpMethod
of the request.
-
method
protected AbstractRequestContextBuilder method(HttpMethod 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
protected final String authority()
Returns the authority of the request.
-
path
protected final String path()
Returns the path of the request, excluding the query part.
-
id
public AbstractRequestContextBuilder id(RequestId id)
-
query
@Nullable protected final String query()
Returns the query part of the request, excluding the leading question mark ('?'
).- Returns:
- the query string, or
null
if there is no query.
-
-