类 DeferredResult<T>
- 类型参数:
T- the result type
DeferredResult provides an alternative to using a Callable for
asynchronous request processing. While a Callable is executed concurrently
on behalf of the application, with a DeferredResult the application can
produce the result from a thread of its choice.
Subclasses can extend this class to easily associate additional data or behavior
with the DeferredResult. For example, one might want to associate the user
used to create the DeferredResult by extending the class and adding an
additional property for the user. In this way, the user could easily be accessed
later without the need to use a data structure to do the mapping.
An example of associating additional behavior to this class might be realized
by extending the class to implement an additional interface. For example, one
might want to implement Comparable so that when the DeferredResult
is added to a PriorityQueue it is handled in the correct order.
- 从以下版本开始:
- 4.0
- 作者:
- Rossen Stoyanchev, Juergen Hoeller, Rob Winch, Harry Yang
-
嵌套类概要
嵌套类修饰符和类型类说明static interfaceHandles a DeferredResult value when set. -
字段概要
字段 -
构造器概要
构造器构造器说明Create a DeferredResult.DeferredResult(Long timeoutValue) Create a DeferredResult with a custom timeout value.DeferredResult(Long timeoutValue, Object timeoutResult) Create a DeferredResult with a timeout value and a default result to use in case of timeout.DeferredResult(Long timeoutValue, Supplier<?> timeoutResult) Variant ofDeferredResult(Long, Object)that accepts a dynamic fallback value based on aSupplier. -
方法概要
修饰符和类型方法说明(专用程序包) final DeferredResultProcessingInterceptorReturn the result, ornullif the result wasn't set.(专用程序包) final LongReturn the configured timeout value in milliseconds.booleanReturntrueif the DeferredResult has been set.final booleanReturntrueif this DeferredResult is no longer usable either because it was previously set or because the underlying request expired.voidonCompletion(Runnable callback) Register code to invoke when the async request completes.voidRegister code to invoke when an error occurred during the async request.voidRegister code to invoke when the async request times out.booleansetErrorResult(Object result) Set an error value for theDeferredResultand handle it.booleanSet the value for the DeferredResult and handle it.final voidsetResultHandler(DeferredResult.DeferredResultHandler resultHandler) Provide a handler to use to handle the result value.private booleansetResultInternal(Object result)
-
字段详细资料
-
RESULT_NONE
-
logger
private static final cn.taketoday.logging.Logger logger -
timeoutValue
-
timeoutResult
-
timeoutCallback
-
errorCallback
-
completionCallback
-
resultHandler
-
result
-
expired
private volatile boolean expired
-
-
构造器详细资料
-
DeferredResult
public DeferredResult()Create a DeferredResult. -
DeferredResult
Create a DeferredResult with a custom timeout value.By default not set in which case the default configured in the MVC Java Config or the MVC namespace is used, or if that's not set, then the timeout depends on the default of the underlying server.
- 参数:
timeoutValue- timeout value in milliseconds
-
DeferredResult
Create a DeferredResult with a timeout value and a default result to use in case of timeout.- 参数:
timeoutValue- timeout value in milliseconds (ignored ifnull)timeoutResult- the result to use
-
DeferredResult
Variant ofDeferredResult(Long, Object)that accepts a dynamic fallback value based on aSupplier.- 参数:
timeoutValue- timeout value in milliseconds (ignored ifnull)timeoutResult- the result supplier to use
-
-
方法详细资料
-
isSetOrExpired
public final boolean isSetOrExpired()Returntrueif this DeferredResult is no longer usable either because it was previously set or because the underlying request expired.The result may have been set with a call to
setResult(Object), orsetErrorResult(Object), or as a result of a timeout, if a timeout result was provided to the constructor. The request may also expire due to a timeout or network error. -
hasResult
public boolean hasResult()Returntrueif the DeferredResult has been set. -
getResult
Return the result, ornullif the result wasn't set. Since the result can also benull, it is recommended to usehasResult()first to check if there is a result prior to calling this method. -
getTimeoutValue
Return the configured timeout value in milliseconds. -
onTimeout
Register code to invoke when the async request times out.This method is called from a container thread when an async request times out before the
DeferredResulthas been populated. It may invokesetResultorsetErrorResultto resume processing. -
onError
Register code to invoke when an error occurred during the async request.This method is called from a container thread when an error occurs while processing an async request before the
DeferredResulthas been populated. It may invokesetResultorsetErrorResultto resume processing. -
onCompletion
Register code to invoke when the async request completes.This method is called from a container thread when an async request completed for any reason including timeout and network error. This is useful for detecting that a
DeferredResultinstance is no longer usable. -
setResultHandler
Provide a handler to use to handle the result value.- 参数:
resultHandler- the handler- 另请参阅:
-
setResult
Set the value for the DeferredResult and handle it.- 参数:
result- the value to set- 返回:
trueif the result was set and passed on for handling;falseif the result was already set or the async request expired- 另请参阅:
-
setResultInternal
-
setErrorResult
Set an error value for theDeferredResultand handle it. The value may be anExceptionorThrowablein which case it will be processed as if a handler raised the exception.- 参数:
result- the error result value- 返回:
trueif the result was set to the error value and passed on for handling;falseif the result was already set or the async request expired- 另请参阅:
-
getInterceptor
-