接口 DeferredResultProcessingInterceptor
public interface DeferredResultProcessingInterceptor
Intercepts concurrent request handling, where the concurrent result is obtained by waiting for aDeferredResult
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 theDeferredResult
is set as well as on timeout, 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
HandlerExceptionResolver
mechanism.The
afterTimeout
method can set theDeferredResult
in order to resume processing.- 从以下版本开始:
- 3.2
- 作者:
- Rossen Stoyanchev, Rob Winch
方法概要
所有方法 实例方法 抽象方法 修饰符和类型 方法 说明 <T> void
afterCompletion(NativeWebRequest request, DeferredResult<T> deferredResult)
Invoked from a container thread when an async request completed for any reason including timeout and network error.<T> void
beforeConcurrentHandling(NativeWebRequest request, DeferredResult<T> deferredResult)
Invoked immediately before the start of concurrent handling, in the same thread that started it.<T> boolean
handleTimeout(NativeWebRequest request, DeferredResult<T> deferredResult)
Invoked from a container thread when an async request times out before theDeferredResult
has been set.<T> void
postProcess(NativeWebRequest request, DeferredResult<T> deferredResult, Object concurrentResult)
Invoked after aDeferredResult
has been set, viaDeferredResult.setResult(Object)
orDeferredResult.setErrorResult(Object)
, and is also ready to handle the concurrent result.<T> void
preProcess(NativeWebRequest request, DeferredResult<T> deferredResult)
Invoked immediately after the start of concurrent handling, in the same thread that started it.
方法详细资料
beforeConcurrentHandling
<T> void beforeConcurrentHandling(NativeWebRequest 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
<T> void preProcess(NativeWebRequest 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
DeferredResult
may 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
<T> void postProcess(NativeWebRequest request, DeferredResult<T> deferredResult, Object concurrentResult) throws Exception
Invoked after aDeferredResult
has 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
DeferredResult
was 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
<T> boolean handleTimeout(NativeWebRequest request, DeferredResult<T> deferredResult) throws Exception
Invoked from a container thread when an async request times out before theDeferredResult
has been set. Implementations may invokesetResult
orsetErrorResult
to resume processing.- 参数:
request
- the current requestdeferredResult
- the DeferredResult for the current request; if theDeferredResult
is set, then concurrent processing is resumed and subsequent interceptors are not invoked- 返回:
true
if processing should continue, orfalse
if other interceptors should not be invoked- 抛出:
Exception
- in case of errors
afterCompletion
<T> void afterCompletion(NativeWebRequest 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 aDeferredResult
instance is no longer usable.- 参数:
request
- the current requestdeferredResult
- the DeferredResult for the current request- 抛出:
Exception
- in case of errors