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.
| Modifier and Type | Class and Description |
|---|---|
| public static interface | DeferredResult.
Handles a DeferredResult value when set. |
| Modifier and Type | Field and Description |
|---|---|
| private Runnable | |
| private Consumer | |
| private volatile boolean | |
| private static final Log | |
| private volatile Object | |
| private static final Object | |
| private DeferredResult. | |
| private Runnable | |
| private final Supplier | |
| private final Long |
| Access | Constructor and Description |
|---|---|
| public | |
| public | DeferredResult(Long
timeout value in milliseconds timeoutValue)Create a DeferredResult with a custom timeout value. |
| public | DeferredResult(Long
timeout value in milliseconds (ignored if timeoutValue, Object null)the result to use timeoutResult)Create a DeferredResult with a timeout value and a default result to use in case of timeout. |
| public | DeferredResult(Long
timeout value in milliseconds (ignored if timeoutValue, Supplier<?> null)the result supplier to use timeoutResult)Variant of |
| Modifier and Type | Method and Description |
|---|---|
| pack-priv final DeferredResultProcessingInterceptor | |
| public Object | |
| pack-priv final Long | |
| public boolean | |
| public final boolean | isSetOrExpired()
Return |
| public void | |
| public void | |
| public void | |
| public boolean | Returns: true if the result was set to the error value and passed on
for handling; false if the result was already set or the async
request expiredthe error result value result)Set an error value for the |
| public boolean | Returns: true if the result was set and passed on for handling;
false if the result was already set or the async request expiredthe value to set result)Set the value for the DeferredResult and handle it. |
| public final void | setResultHandler(DeferredResult.
the handler resultHandlerProvide a handler to use to handle the result value. |
| private boolean |
| completionCallback | back to summary |
|---|---|
| private Runnable completionCallback
| |
| errorCallback | back to summary |
|---|---|
| private Consumer<Throwable> errorCallback
| |
| expired | back to summary |
|---|---|
| private volatile boolean expired | |
| logger | back to summary |
|---|---|
| private static final Log logger | |
| result | back to summary |
|---|---|
| private volatile Object result
| |
| RESULT_NONE | back to summary |
|---|---|
| private static final Object RESULT_NONE | |
| resultHandler | back to summary |
|---|---|
| private DeferredResult. | |
| timeoutCallback | back to summary |
|---|---|
| private Runnable timeoutCallback
| |
| timeoutResult | back to summary |
|---|---|
| private final Supplier<?> timeoutResult | |
| timeoutValue | back to summary |
|---|---|
| private final Long timeoutValue
| |
| DeferredResult | back to summary |
|---|---|
| public DeferredResult() Create a DeferredResult. | |
| DeferredResult | back to summary |
|---|---|
| public DeferredResult(Long timeoutValue) 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.
| |
| DeferredResult | back to summary |
|---|---|
| public DeferredResult(Long timeoutValue, Object timeoutResult) Create a DeferredResult with a timeout value and a default result to use in case of timeout. | |
| DeferredResult | back to summary |
|---|---|
| public DeferredResult(Long timeoutValue, Supplier<?> timeoutResult) Variant of | |
| getInterceptor | back to summary |
|---|---|
| pack-priv final DeferredResultProcessingInterceptor getInterceptor() | |
| getResult | back to summary |
|---|---|
| public Object getResult() Return the result, or
| |
| getTimeoutValue | back to summary |
|---|---|
| pack-priv final Long getTimeoutValue() Return the configured timeout value in milliseconds.
| |
| hasResult | back to summary |
|---|---|
| public boolean hasResult() Return
| |
| isSetOrExpired | back to summary |
|---|---|
| public final boolean isSetOrExpired() Return The result may have been set with a call to | |
| onCompletion | back to summary |
|---|---|
| public void onCompletion(Runnable callback) 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 | |
| onError | back to summary |
|---|---|
| public void onError(Consumer<Throwable> callback) 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
| |
| onTimeout | back to summary |
|---|---|
| public void onTimeout(Runnable callback) 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 | |
| setErrorResult | back to summary |
|---|---|
| public boolean setErrorResult(Object result) Set an error value for the
| |
| setResult | back to summary |
|---|---|
| public boolean setResult(T result) Set the value for the DeferredResult and handle it.
| |
| setResultHandler | back to summary |
|---|---|
| public final void setResultHandler(DeferredResult. Provide a handler to use to handle the result value.
| |
| setResultInternal | back to summary |
|---|---|
| private boolean setResultInternal(Object result) | |
| Modifier and Type | Method and Description |
|---|---|
| public void |
| handleResult | back to summary |
|---|---|
| public void handleResult(Object result) | |