提交 be7b07f8 编写于 作者: R Rob Winch 提交者: Phillip Webb

Make DeferredResult extensible

Previously it was cumbersome to associate data or behavior to a
DeferredResult because it was marked as final and had no extension
points.

Now DeferredResult is non-final which allows subclasses to associate
additional data and behavior to it.

Issue: SPR-10059
上级 455701d2
......@@ -15,6 +15,7 @@
*/
package org.springframework.web.context.request.async;
import java.util.PriorityQueue;
import java.util.concurrent.Callable;
import org.apache.commons.logging.Log;
......@@ -28,10 +29,24 @@ import org.springframework.web.context.request.NativeWebRequest;
* concurrently on behalf of the application, with a {@code DeferredResult} the
* application can produce the result from a thread of its choice.
*
* <p>Subclasses can extend this class to easily associate additional data or
* behavior with the {@link DeferredResult}. For example, one might want to
* associate the user used to create the {@link DeferredResult} by extending the
* class and adding an addition 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.
*
* <p>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 a {@link Comparable} so that when the
* {@link DeferredResult} is added to a {@link PriorityQueue} it is handled in
* the correct order.
*
* @author Rossen Stoyanchev
* @author Rob Winch
* @since 3.2
*/
public final class DeferredResult<T> {
public class DeferredResult<T> {
private static final Log logger = LogFactory.getLog(DeferredResult.class);
......@@ -88,14 +103,14 @@ public final class DeferredResult<T> {
* timeout result was provided to the constructor. The request may also
* expire due to a timeout or network error.
*/
public boolean isSetOrExpired() {
public final boolean isSetOrExpired() {
return ((this.result != RESULT_NONE) || this.expired);
}
/**
* Return the configured timeout value in milliseconds.
*/
Long getTimeoutValue() {
final Long getTimeoutValue() {
return this.timeout;
}
......@@ -126,7 +141,7 @@ public final class DeferredResult<T> {
* @param resultHandler the handler
* @see {@link DeferredResultProcessingInterceptor}
*/
public void setResultHandler(DeferredResultHandler resultHandler) {
public final void setResultHandler(DeferredResultHandler resultHandler) {
Assert.notNull(resultHandler, "DeferredResultHandler is required");
synchronized (this) {
this.resultHandler = resultHandler;
......@@ -179,7 +194,7 @@ public final class DeferredResult<T> {
return setResultInternal(result);
}
DeferredResultProcessingInterceptor getInterceptor() {
final DeferredResultProcessingInterceptor getInterceptor() {
return new DeferredResultProcessingInterceptorAdapter() {
@Override
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册