Skip to content

Commit 25a7136

Browse files
committed
Merge pull request #199 from rwinch/SPR-10059
* SPR-10059: Make DeferredResult extensible
2 parents 455701d + be7b07f commit 25a7136

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

spring-web/src/main/java/org/springframework/web/context/request/async/DeferredResult.java

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package org.springframework.web.context.request.async;
1717

18+
import java.util.PriorityQueue;
1819
import java.util.concurrent.Callable;
1920

2021
import org.apache.commons.logging.Log;
@@ -28,10 +29,24 @@
2829
* concurrently on behalf of the application, with a {@code DeferredResult} the
2930
* application can produce the result from a thread of its choice.
3031
*
32+
* <p>Subclasses can extend this class to easily associate additional data or
33+
* behavior with the {@link DeferredResult}. For example, one might want to
34+
* associate the user used to create the {@link DeferredResult} by extending the
35+
* class and adding an addition property for the user. In this way, the user
36+
* could easily be accessed later without the need to use a data structure to do
37+
* the mapping.
38+
*
39+
* <p>An example of associating additional behavior to this class might be
40+
* realized by extending the class to implement an additional interface. For
41+
* example, one might want to implement a {@link Comparable} so that when the
42+
* {@link DeferredResult} is added to a {@link PriorityQueue} it is handled in
43+
* the correct order.
44+
*
3145
* @author Rossen Stoyanchev
46+
* @author Rob Winch
3247
* @since 3.2
3348
*/
34-
public final class DeferredResult<T> {
49+
public class DeferredResult<T> {
3550

3651
private static final Log logger = LogFactory.getLog(DeferredResult.class);
3752

@@ -88,14 +103,14 @@ public DeferredResult(Long timeout, Object timeoutResult) {
88103
* timeout result was provided to the constructor. The request may also
89104
* expire due to a timeout or network error.
90105
*/
91-
public boolean isSetOrExpired() {
106+
public final boolean isSetOrExpired() {
92107
return ((this.result != RESULT_NONE) || this.expired);
93108
}
94109

95110
/**
96111
* Return the configured timeout value in milliseconds.
97112
*/
98-
Long getTimeoutValue() {
113+
final Long getTimeoutValue() {
99114
return this.timeout;
100115
}
101116

@@ -126,7 +141,7 @@ public void onCompletion(Runnable callback) {
126141
* @param resultHandler the handler
127142
* @see {@link DeferredResultProcessingInterceptor}
128143
*/
129-
public void setResultHandler(DeferredResultHandler resultHandler) {
144+
public final void setResultHandler(DeferredResultHandler resultHandler) {
130145
Assert.notNull(resultHandler, "DeferredResultHandler is required");
131146
synchronized (this) {
132147
this.resultHandler = resultHandler;
@@ -179,7 +194,7 @@ public boolean setErrorResult(Object result) {
179194
return setResultInternal(result);
180195
}
181196

182-
DeferredResultProcessingInterceptor getInterceptor() {
197+
final DeferredResultProcessingInterceptor getInterceptor() {
183198
return new DeferredResultProcessingInterceptorAdapter() {
184199

185200
@Override

0 commit comments

Comments
 (0)