类 WebAsyncManager
java.lang.Object
cn.taketoday.web.context.async.WebAsyncManager
The central class for managing asynchronous request processing, mainly intended
as an SPI and not typically used directly by application classes.
An async scenario starts with request processing as usual in a thread (T1).
Concurrent request handling can be initiated by calling
startCallableProcessing or
startDeferredResultProcessing,
both of which produce a result in a separate thread (T2). The result is saved
and the request dispatched to the container, to resume processing with the saved
result in a third thread (T3). Within the dispatched thread (T3), the saved
result can be accessed via getConcurrentResult() or its presence
detected via hasConcurrentResult().
- 从以下版本开始:
- 4.0
- 作者:
- Rossen Stoyanchev, Juergen Hoeller, Harry Yang
- 另请参阅:
-
字段概要
字段修饰符和类型字段说明private AsyncWebRequestprivate final Map<Object,CallableProcessingInterceptor> private Objectprivate Object[]private static final cn.taketoday.core.task.AsyncTaskExecutorprivate final Map<Object,DeferredResultProcessingInterceptor> private booleanprivate static final cn.taketoday.logging.Loggerprivate final RequestContextprivate static final Objectprivate cn.taketoday.core.task.AsyncTaskExecutorprivate static final TimeoutAsyncProcessingInterceptorstatic final StringThe name attribute of theRequestContext.static final StringThe name attribute containing the result. -
构造器概要
构造器 -
方法概要
修饰符和类型方法说明voidClear concurrentResult and concurrentResultContext.static ObjectfindHttpRequestHandler(RequestContext request) private StringGet theCallableProcessingInterceptorregistered under the given key.Provides access to the result from concurrent handling.Object[]Provides access to additional processing context saved at the start of concurrent handling.Get theDeferredResultProcessingInterceptorregistered under the given key.booleanWhether a result value exists as a result of concurrent handling.voidregisterCallableInterceptor(Object key, CallableProcessingInterceptor interceptor) Register aCallableProcessingInterceptorunder the given key.voidregisterCallableInterceptors(CallableProcessingInterceptor... interceptors) Register aCallableProcessingInterceptorwithout a key.voidregisterDeferredResultInterceptor(Object key, DeferredResultProcessingInterceptor interceptor) Register aDeferredResultProcessingInterceptorunder the given key.voidregisterDeferredResultInterceptors(DeferredResultProcessingInterceptor... interceptors) Register one or moreDeferredResultProcessingInterceptorswithout a specified key.voidsetAsyncRequest(AsyncWebRequest asyncRequest) Configure theAsyncWebRequestto use.private voidsetConcurrentResultAndDispatch(Object result) voidsetTaskExecutor(cn.taketoday.core.task.AsyncTaskExecutor taskExecutor) Configure an AsyncTaskExecutor for use with concurrent processing viastartCallableProcessing(Callable, Object...).private voidstartAsyncProcessing(Object[] processingContext) voidstartCallableProcessing(WebAsyncTask<?> webAsyncTask, Object... processingContext) Use the givenWebAsyncTaskto configure the task executor as well as the timeout value of theAsyncWebRequestbefore delegating tostartCallableProcessing(Callable, Object...).voidstartCallableProcessing(Callable<?> callable, Object... processingContext) Start concurrent request processing and execute the given task with anAsyncTaskExecutor.voidstartDeferredResultProcessing(DeferredResult<?> deferredResult, Object... processingContext) Start concurrent request processing and initialize the givenDeferredResultwith aDeferredResult.DeferredResultHandlerthat saves the result and dispatches the request to resume processing of that result.
-
字段详细资料
-
WEB_ASYNC_REQUEST_ATTRIBUTE
The name attribute of theRequestContext. -
WEB_ASYNC_RESULT_ATTRIBUTE
The name attribute containing the result. -
RESULT_NONE
-
DEFAULT_TASK_EXECUTOR
private static final cn.taketoday.core.task.AsyncTaskExecutor DEFAULT_TASK_EXECUTOR -
logger
private static final cn.taketoday.logging.Logger logger -
timeoutInterceptor
-
asyncRequest
-
taskExecutor
private cn.taketoday.core.task.AsyncTaskExecutor taskExecutor -
concurrentResult
-
concurrentResultContext
-
errorHandlingInProgress
private volatile boolean errorHandlingInProgress -
callableInterceptors
-
deferredResultInterceptors
-
requestContext
-
-
构造器详细资料
-
WebAsyncManager
-
-
方法详细资料
-
setAsyncRequest
Configure theAsyncWebRequestto use. This property may be set more than once during a single request to accurately reflect the current state of the request (e.g. following a forward, request/response wrapping, etc). However, it should not be set while concurrent handling is in progress, i.e. whileRequestContext.isConcurrentHandlingStarted()istrue.- 参数:
asyncRequest- the web request to use
-
setTaskExecutor
public void setTaskExecutor(cn.taketoday.core.task.AsyncTaskExecutor taskExecutor) Configure an AsyncTaskExecutor for use with concurrent processing viastartCallableProcessing(Callable, Object...).By default a
SimpleAsyncTaskExecutorinstance is used. -
hasConcurrentResult
public boolean hasConcurrentResult()Whether a result value exists as a result of concurrent handling. -
getConcurrentResult
Provides access to the result from concurrent handling.- 返回:
- an Object, possibly an
ExceptionorThrowableif concurrent handling raised one. - 另请参阅:
-
getConcurrentResultContext
Provides access to additional processing context saved at the start of concurrent handling.- 另请参阅:
-
getCallableInterceptor
Get theCallableProcessingInterceptorregistered under the given key.- 参数:
key- the key- 返回:
- the interceptor registered under that key, or
nullif none
-
getDeferredResultInterceptor
Get theDeferredResultProcessingInterceptorregistered under the given key.- 参数:
key- the key- 返回:
- the interceptor registered under that key, or
nullif none
-
registerCallableInterceptor
Register aCallableProcessingInterceptorunder the given key.- 参数:
key- the keyinterceptor- the interceptor to register
-
registerCallableInterceptors
Register aCallableProcessingInterceptorwithout a key. The key is derived from the class name and hashcode.- 参数:
interceptors- one or more interceptors to register
-
registerDeferredResultInterceptor
public void registerDeferredResultInterceptor(Object key, DeferredResultProcessingInterceptor interceptor) Register aDeferredResultProcessingInterceptorunder the given key.- 参数:
key- the keyinterceptor- the interceptor to register
-
registerDeferredResultInterceptors
Register one or moreDeferredResultProcessingInterceptorswithout a specified key. The default key is derived from the interceptor class name and hash code.- 参数:
interceptors- one or more interceptors to register
-
clearConcurrentResult
public void clearConcurrentResult()Clear concurrentResult and concurrentResultContext. -
startCallableProcessing
public void startCallableProcessing(Callable<?> callable, Object... processingContext) throws Exception Start concurrent request processing and execute the given task with anAsyncTaskExecutor. The result from the task execution is saved and the request dispatched in order to resume processing of that result. If the task raises an Exception then the saved result will be the raised Exception.- 参数:
callable- a unit of work to be executed asynchronouslyprocessingContext- additional context to save that can be accessed viagetConcurrentResultContext()- 抛出:
Exception- if concurrent processing failed to start- 另请参阅:
-
startCallableProcessing
public void startCallableProcessing(WebAsyncTask<?> webAsyncTask, Object... processingContext) throws Exception Use the givenWebAsyncTaskto configure the task executor as well as the timeout value of theAsyncWebRequestbefore delegating tostartCallableProcessing(Callable, Object...).- 参数:
webAsyncTask- a WebAsyncTask containing the targetCallableprocessingContext- additional context to save that can be accessed viagetConcurrentResultContext()- 抛出:
Exception- if concurrent processing failed to start
-
formatRequestUri
-
setConcurrentResultAndDispatch
-
startDeferredResultProcessing
public void startDeferredResultProcessing(DeferredResult<?> deferredResult, Object... processingContext) throws Exception Start concurrent request processing and initialize the givenDeferredResultwith aDeferredResult.DeferredResultHandlerthat saves the result and dispatches the request to resume processing of that result. TheAsyncWebRequestis also updated with a completion handler that expires theDeferredResultand a timeout handler assuming theDeferredResulthas a default timeout result.- 参数:
deferredResult- the DeferredResult instance to initializeprocessingContext- additional context to save that can be accessed viagetConcurrentResultContext()- 抛出:
Exception- if concurrent processing failed to start- 另请参阅:
-
startAsyncProcessing
-
findHttpRequestHandler
-