接口 DeferredResultProcessingInterceptor
- 所有已知实现类:
TimeoutAsyncProcessingInterceptor
DeferredResult to be set from a thread
chosen by the application (e.g. in response to some external event).
A DeferredResultProcessingInterceptor is invoked before the start
of async processing, after the DeferredResult is set as well as on
timeout/error, or after completing for any reason including a timeout or network
error.
As a general rule exceptions raised by interceptor methods will cause
async processing to resume by dispatching back to the container and using
the Exception instance as the concurrent result. Such exceptions will then
be processed through the HandlerExceptionHandler mechanism.
The handleTimeout
method can set the DeferredResult in order to resume processing.
- 从以下版本开始:
- 4.0
- 作者:
- Rossen Stoyanchev, Rob Winch
-
方法概要
修饰符和类型方法说明default <T> voidafterCompletion(RequestContext request, DeferredResult<T> deferredResult) Invoked from a container thread when an async request completed for any reason including timeout and network error.default <T> voidbeforeConcurrentHandling(RequestContext request, DeferredResult<T> deferredResult) Invoked immediately before the start of concurrent handling, in the same thread that started it.default <T> booleanhandleError(RequestContext request, DeferredResult<T> deferredResult, Throwable t) Invoked from a container thread when an error occurred while processing an async request before theDeferredResulthas been set.default <T> booleanhandleTimeout(RequestContext request, DeferredResult<T> deferredResult) Invoked from a container thread when an async request times out before theDeferredResulthas been set.default <T> voidpostProcess(RequestContext request, DeferredResult<T> deferredResult, Object concurrentResult) Invoked after aDeferredResulthas been set, viaDeferredResult.setResult(Object)orDeferredResult.setErrorResult(Object), and is also ready to handle the concurrent result.default <T> voidpreProcess(RequestContext request, DeferredResult<T> deferredResult) Invoked immediately after the start of concurrent handling, in the same thread that started it.
-
方法详细资料
-
beforeConcurrentHandling
default <T> void beforeConcurrentHandling(RequestContext request, DeferredResult<T> deferredResult) throws Exception Invoked immediately before the start of concurrent handling, in the same thread that started it. This method may be used to capture state just prior to the start of concurrent processing with the givenDeferredResult.- 参数:
request- the current requestdeferredResult- the DeferredResult for the current request- 抛出:
Exception- in case of errors
-
preProcess
default <T> void preProcess(RequestContext request, DeferredResult<T> deferredResult) throws Exception Invoked immediately after the start of concurrent handling, in the same thread that started it. This method may be used to detect the start of concurrent processing with the givenDeferredResult.The
DeferredResultmay have already been set, for example at the time of its creation or by another thread.- 参数:
request- the current requestdeferredResult- the DeferredResult for the current request- 抛出:
Exception- in case of errors
-
postProcess
default <T> void postProcess(RequestContext request, DeferredResult<T> deferredResult, Object concurrentResult) throws Exception Invoked after aDeferredResulthas been set, viaDeferredResult.setResult(Object)orDeferredResult.setErrorResult(Object), and is also ready to handle the concurrent result.This method may also be invoked after a timeout when the
DeferredResultwas created with a constructor accepting a default timeout result.- 参数:
request- the current requestdeferredResult- the DeferredResult for the current requestconcurrentResult- the result to which theDeferredResult- 抛出:
Exception- in case of errors
-
handleTimeout
default <T> boolean handleTimeout(RequestContext request, DeferredResult<T> deferredResult) throws Exception Invoked from a container thread when an async request times out before theDeferredResulthas been set. Implementations may invokesetResultorsetErrorResultto resume processing.- 参数:
request- the current requestdeferredResult- the DeferredResult for the current request; if theDeferredResultis set, then concurrent processing is resumed and subsequent interceptors are not invoked- 返回:
trueif processing should continue, orfalseif other interceptors should not be invoked- 抛出:
Exception- in case of errors
-
handleError
default <T> boolean handleError(RequestContext request, DeferredResult<T> deferredResult, Throwable t) throws Exception Invoked from a container thread when an error occurred while processing an async request before theDeferredResulthas been set. Implementations may invokesetResultorsetErrorResultto resume processing.- 参数:
request- the current requestdeferredResult- the DeferredResult for the current request; if theDeferredResultis set, then concurrent processing is resumed and subsequent interceptors are not invokedt- the error that occurred while request processing- 返回:
trueif error handling should continue, orfalseif other interceptors should by bypassed and not be invoked- 抛出:
Exception- in case of errors
-
afterCompletion
default <T> void afterCompletion(RequestContext request, DeferredResult<T> deferredResult) throws Exception Invoked from a container thread when an async request completed for any reason including timeout and network error. This method is useful for detecting that aDeferredResultinstance is no longer usable.- 参数:
request- the current requestdeferredResult- the DeferredResult for the current request- 抛出:
Exception- in case of errors
-