public class DefaultServiceRequestContext extends NonWrappingRequestContext implements ServiceRequestContext
ServiceRequestContext
implementation.Constructor and Description |
---|
DefaultServiceRequestContext(ServiceConfig cfg,
Channel ch,
io.micrometer.core.instrument.MeterRegistry meterRegistry,
SessionProtocol sessionProtocol,
PathMappingContext pathMappingContext,
PathMappingResult pathMappingResult,
Request request,
SSLSession sslSession)
Creates a new instance.
|
Modifier and Type | Method and Description |
---|---|
ByteBufAllocator |
alloc()
Returns the
ByteBufAllocator for this RequestContext . |
ExecutorService |
blockingTaskExecutor()
Returns the
ExecutorService that could be used for executing a potentially long-running task. |
protected Channel |
channel()
Returns the
Channel that is handling this request, or null if the connection is not
established yet. |
EventLoop |
eventLoop()
|
RequestLog |
log()
Returns the
RequestLog that contains the information about the current Request . |
RequestLogBuilder |
logBuilder()
Returns the
RequestLogBuilder that collects the information about the current Request . |
Logger |
logger()
|
String |
mappedPath()
Returns the path with its context path removed.
|
long |
maxRequestLength()
Returns the maximum length of the current
Request . |
MediaType |
negotiatedProduceType()
Returns the negotiated producible media type.
|
ServiceRequestContext |
newDerivedContext()
Creates a new derived
RequestContext which only the RequestLog
is different from the deriving context. |
ServiceRequestContext |
newDerivedContext(Request request)
Creates a new derived
RequestContext with the specified Request which the
RequestLog is different from the deriving context. |
PathMapping |
pathMapping()
|
PathMappingContext |
pathMappingContext()
Returns the
PathMappingContext used to find the Service . |
Map<String,String> |
pathParams()
Returns the path parameters mapped by the
PathMapping associated with the Service
that is handling the current Request . |
Runnable |
requestTimeoutHandler() |
long |
requestTimeoutMillis()
Returns the amount of time allowed until receiving the current
Request completely. |
Server |
server()
|
<T extends Service<HttpRequest,HttpResponse>> |
service()
|
void |
setMaxRequestLength(long maxRequestLength)
Sets the maximum length of the current
Request . |
void |
setRequestTimeout(Duration requestTimeout)
Sets the amount of time allowed until receiving the current
Request completely. |
void |
setRequestTimeoutChangeListener(RequestTimeoutChangeListener listener)
Sets the listener that is notified when the requestTimeoutMillis() request timeout} of
the request is changed.
|
void |
setRequestTimeoutHandler(Runnable requestTimeoutHandler)
Sets a handler to run when the request times out.
|
void |
setRequestTimeoutMillis(long requestTimeoutMillis)
Sets the amount of time allowed until receiving the current
Request completely. |
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() |
VirtualHost |
virtualHost()
Returns the
VirtualHost that is handling the current Request . |
attr, attrs, hasAttr, invokeOnChildCallbacks, invokeOnEnterCallbacks, invokeOnExitCallbacks, localAddress, meterRegistry, method, onChild, onEnter, onExit, path, query, remoteAddress, request, sessionProtocol
contextAwareEventLoop, equals, hashCode, isTimedOut, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, onEnter, onExit, rejectPromise, resolvePromise, setTimedOut
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
localAddress, pathParam, remoteAddress
attrs, contextAwareEventLoop, current, invokeOnChildCallbacks, invokeOnEnterCallbacks, invokeOnExitCallbacks, isTimedOut, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, mapCurrent, meterRegistry, method, onChild, onEnter, onEnter, onExit, onExit, path, push, push, query, rejectPromise, request, resolvePromise, sessionProtocol
attr, hasAttr
public DefaultServiceRequestContext(ServiceConfig cfg, Channel ch, io.micrometer.core.instrument.MeterRegistry meterRegistry, SessionProtocol sessionProtocol, PathMappingContext pathMappingContext, PathMappingResult pathMappingResult, Request request, @Nullable SSLSession sslSession)
ch
- the Channel
that handles the invocationmeterRegistry
- the MeterRegistry
that collects various statssessionProtocol
- the SessionProtocol
of the invocationrequest
- the request associated with this contextsslSession
- the SSLSession
for this invocation if it is over TLSpublic ServiceRequestContext newDerivedContext()
RequestContext
RequestContext
which only the RequestLog
is different from the deriving context. Note that the references of Attribute
s
in the RequestContext.attrs()
are copied as well.newDerivedContext
in interface RequestContext
newDerivedContext
in interface ServiceRequestContext
public ServiceRequestContext newDerivedContext(Request request)
RequestContext
RequestContext
with the specified Request
which the
RequestLog
is different from the deriving context.
Note that the references of Attribute
s in the RequestContext.attrs()
are copied as well.newDerivedContext
in interface RequestContext
newDerivedContext
in interface ServiceRequestContext
protected Channel channel()
NonWrappingRequestContext
Channel
that is handling this request, or null
if the connection is not
established yet.channel
in class NonWrappingRequestContext
public Server server()
ServiceRequestContext
server
in interface ServiceRequestContext
public VirtualHost virtualHost()
ServiceRequestContext
VirtualHost
that is handling the current Request
.virtualHost
in interface ServiceRequestContext
public PathMapping pathMapping()
ServiceRequestContext
pathMapping
in interface ServiceRequestContext
public PathMappingContext pathMappingContext()
ServiceRequestContext
PathMappingContext
used to find the Service
.pathMappingContext
in interface ServiceRequestContext
public Map<String,String> pathParams()
ServiceRequestContext
PathMapping
associated with the Service
that is handling the current Request
.pathParams
in interface ServiceRequestContext
public <T extends Service<HttpRequest,HttpResponse>> T service()
ServiceRequestContext
service
in interface ServiceRequestContext
public ExecutorService blockingTaskExecutor()
ServiceRequestContext
ExecutorService
that could be used for executing a potentially long-running task.
The ExecutorService
will propagate the ServiceRequestContext
automatically when running
a task.
Note that performing a long-running task in Service.serve(ServiceRequestContext, Request)
may block the Server
's I/O event loop and thus should be executed in other threads.
blockingTaskExecutor
in interface ServiceRequestContext
public String mappedPath()
ServiceRequestContext
mappedPath
in interface ServiceRequestContext
@Nullable public MediaType negotiatedProduceType()
ServiceRequestContext
Service
, null
would be returned.negotiatedProduceType
in interface ServiceRequestContext
public EventLoop eventLoop()
RequestContext
eventLoop
in interface RequestContext
public Logger logger()
ServiceRequestContext
logger
in interface ServiceRequestContext
@Nullable public SSLSession sslSession()
RequestContext
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.sslSession
in interface RequestContext
sslSession
in class NonWrappingRequestContext
public long requestTimeoutMillis()
ServiceRequestContext
Request
completely.
This value is initially set from ServerConfig.defaultRequestTimeoutMillis()
.requestTimeoutMillis
in interface ServiceRequestContext
public void setRequestTimeoutMillis(long requestTimeoutMillis)
ServiceRequestContext
Request
completely.
This value is initially set from ServerConfig.defaultRequestTimeoutMillis()
.setRequestTimeoutMillis
in interface ServiceRequestContext
public void setRequestTimeout(Duration requestTimeout)
ServiceRequestContext
Request
completely.
This value is initially set from ServerConfig.defaultRequestTimeoutMillis()
.setRequestTimeout
in interface ServiceRequestContext
public void setRequestTimeoutHandler(Runnable requestTimeoutHandler)
ServiceRequestContext
requestTimeoutHandler
must close the response,
e.g., by calling StreamWriter.close()
. If not set, the response will be closed with
HttpStatus.SERVICE_UNAVAILABLE
.
For example,
HttpResponseWriter res = HttpResponse.streaming();
ctx.setRequestTimeoutHandler(() -> {
res.write(HttpHeaders.of(HttpStatus.OK, MediaType.PLAIN_TEXT_UTF_8, "Request timed out."));
res.close();
});
...
setRequestTimeoutHandler
in interface ServiceRequestContext
public long maxRequestLength()
ServiceRequestContext
Request
.
This value is initially set from ServerConfig.defaultMaxRequestLength()
.
If 0, there is no limit on the request size.maxRequestLength
in interface ServiceRequestContext
ContentTooLargeException
public void setMaxRequestLength(long maxRequestLength)
ServiceRequestContext
Request
.
This value is initially set from ServerConfig.defaultMaxRequestLength()
.
If 0, there is no limit on the request size.setMaxRequestLength
in interface ServiceRequestContext
ContentTooLargeException
public RequestLog log()
RequestContext
RequestLog
that contains the information about the current Request
.log
in interface RequestContext
public RequestLogBuilder logBuilder()
RequestContext
RequestLogBuilder
that collects the information about the current Request
.logBuilder
in interface RequestContext
public ByteBufAllocator alloc()
RequestContext
ByteBufAllocator
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 RequestContext
public void setRequestTimeoutChangeListener(RequestTimeoutChangeListener listener)
Note: This method is meant for internal use by server-side protocol implementation to reschedule a timeout task when a user updates the request timeout configuration.
© Copyright 2015–2018 LINE Corporation. All rights reserved.