public final class DeferredResult<T>
extends java.lang.Object
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.| Modifier and Type | Class and Description |
|---|---|
static interface |
DeferredResult.DeferredResultHandler
Handles a DeferredResult value when set.
|
| Constructor and Description |
|---|
DeferredResult()
Create a DeferredResult.
|
DeferredResult(long timeout)
Create a DeferredResult with a timeout.
|
DeferredResult(java.lang.Long timeout,
java.lang.Object timeoutResult)
Create a DeferredResult with a timeout and a default result to use on timeout.
|
| Modifier and Type | Method and Description |
|---|---|
java.lang.Long |
getTimeoutMilliseconds()
Return the configured timeout value in milliseconds.
|
boolean |
isSetOrExpired()
Whether the DeferredResult can no longer be set either because the async
request expired or because it was already set.
|
boolean |
setErrorResult(java.lang.Object result)
Set an error result value and pass it on for handling.
|
boolean |
setResult(T result)
Set the result value and pass it on for handling.
|
void |
setResultHandler(DeferredResult.DeferredResultHandler resultHandler)
Set a handler to handle the result when set.
|
public DeferredResult()
public DeferredResult(long timeout)
timeout - timeout value in millisecondspublic DeferredResult(java.lang.Long timeout,
java.lang.Object timeoutResult)
timeout - timeout value in milliseconds; ignored if nulltimeoutResult - the result to use, possibly nullpublic java.lang.Long getTimeoutMilliseconds()
public void setResultHandler(DeferredResult.DeferredResultHandler resultHandler)
public boolean setResult(T result)
result - the result valueisSetOrExpired()public boolean setErrorResult(java.lang.Object result)
Exception or Throwable, it will be processed as though the
controller raised the exception. Otherwise it will be processed as if the
controller returned the given result.result - the error result valueisSetOrExpired()public boolean isSetOrExpired()