1
1
/*
2
- * Copyright 2002-2013 the original author or authors.
2
+ * Copyright 2002-2015 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
13
13
* See the License for the specific language governing permissions and
14
14
* limitations under the License.
15
15
*/
16
+
16
17
package org .springframework .web .context .request .async ;
17
18
18
19
import java .util .PriorityQueue ;
@@ -64,9 +65,9 @@ public class DeferredResult<T> {
64
65
65
66
private DeferredResultHandler resultHandler ;
66
67
67
- private Object result = RESULT_NONE ;
68
+ private volatile Object result = RESULT_NONE ;
68
69
69
- private boolean expired ;
70
+ private volatile boolean expired ;
70
71
71
72
72
73
/**
@@ -95,33 +96,34 @@ public DeferredResult(Long timeout, Object timeoutResult) {
95
96
this .timeout = timeout ;
96
97
}
97
98
99
+
98
100
/**
99
101
* Return {@code true} if this DeferredResult is no longer usable either
100
102
* because it was previously set or because the underlying request expired.
101
- * <p>
102
- * The result may have been set with a call to {@link #setResult(Object)},
103
+ * <p>The result may have been set with a call to {@link #setResult(Object)},
103
104
* or {@link #setErrorResult(Object)}, or as a result of a timeout, if a
104
105
* timeout result was provided to the constructor. The request may also
105
106
* expire due to a timeout or network error.
106
107
*/
107
108
public final boolean isSetOrExpired () {
108
- return (( this .result != RESULT_NONE ) || this .expired );
109
+ return (this .result != RESULT_NONE || this .expired );
109
110
}
110
111
111
112
/**
112
- * @return {@code true} if the DeferredResult has been set.
113
+ * Return {@code true} if the DeferredResult has been set.
113
114
*/
114
115
public boolean hasResult () {
115
- return this .result != RESULT_NONE ;
116
+ return ( this .result != RESULT_NONE ) ;
116
117
}
117
118
118
119
/**
119
- * @return the result or {@code null} if the result wasn't set; since the result can
120
- * also be {@code null}, it is recommended to use {@link #hasResult()} first
121
- * to check if there is a result prior to calling this method.
120
+ * Return the result, or {@code null} if the result wasn't set. Since the result
121
+ * can also be {@code null}, it is recommended to use {@link #hasResult()} first
122
+ * to check if there is a result prior to calling this method.
122
123
*/
123
124
public Object getResult () {
124
- return hasResult () ? this .result : null ;
125
+ Object resultToCheck = this .result ;
126
+ return (resultToCheck != RESULT_NONE ? resultToCheck : null );
125
127
}
126
128
127
129
/**
@@ -162,12 +164,12 @@ public final void setResultHandler(DeferredResultHandler resultHandler) {
162
164
Assert .notNull (resultHandler , "DeferredResultHandler is required" );
163
165
synchronized (this ) {
164
166
this .resultHandler = resultHandler ;
165
- if (( this .result != RESULT_NONE ) && ( !this .expired ) ) {
167
+ if (this .result != RESULT_NONE && !this .expired ) {
166
168
try {
167
169
this .resultHandler .handleResult (this .result );
168
170
}
169
- catch (Throwable t ) {
170
- logger .trace ("DeferredResult not handled" , t );
171
+ catch (Throwable ex ) {
172
+ logger .trace ("DeferredResult not handled" , ex );
171
173
}
172
174
}
173
175
}
@@ -211,9 +213,9 @@ public boolean setErrorResult(Object result) {
211
213
return setResultInternal (result );
212
214
}
213
215
216
+
214
217
final DeferredResultProcessingInterceptor getInterceptor () {
215
218
return new DeferredResultProcessingInterceptorAdapter () {
216
-
217
219
@ Override
218
220
public <S > boolean handleTimeout (NativeWebRequest request , DeferredResult <S > deferredResult ) {
219
221
if (timeoutCallback != null ) {
@@ -224,7 +226,6 @@ public <S> boolean handleTimeout(NativeWebRequest request, DeferredResult<S> def
224
226
}
225
227
return true ;
226
228
}
227
-
228
229
@ Override
229
230
public <S > void afterCompletion (NativeWebRequest request , DeferredResult <S > deferredResult ) {
230
231
synchronized (DeferredResult .this ) {
0 commit comments