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
/**
@@ -98,33 +99,34 @@ public DeferredResult(Long timeout, Object timeoutResult) {
98
99
this .timeout = timeout ;
99
100
}
100
101
102
+
101
103
/**
102
104
* Return {@code true} if this DeferredResult is no longer usable either
103
105
* because it was previously set or because the underlying request expired.
104
- * <p>
105
- * The result may have been set with a call to {@link #setResult(Object)},
106
+ * <p>The result may have been set with a call to {@link #setResult(Object)},
106
107
* or {@link #setErrorResult(Object)}, or as a result of a timeout, if a
107
108
* timeout result was provided to the constructor. The request may also
108
109
* expire due to a timeout or network error.
109
110
*/
110
111
public final boolean isSetOrExpired () {
111
- return (( this .result != RESULT_NONE ) || this .expired );
112
+ return (this .result != RESULT_NONE || this .expired );
112
113
}
113
114
114
115
/**
115
- * @return {@code true} if the DeferredResult has been set.
116
+ * Return {@code true} if the DeferredResult has been set.
116
117
*/
117
118
public boolean hasResult () {
118
- return this .result != RESULT_NONE ;
119
+ return ( this .result != RESULT_NONE ) ;
119
120
}
120
121
121
122
/**
122
- * @return the result or {@code null} if the result wasn't set; since the result can
123
- * also be {@code null}, it is recommended to use {@link #hasResult()} first
124
- * to check if there is a result prior to calling this method.
123
+ * Return the result, or {@code null} if the result wasn't set. Since the result
124
+ * can also be {@code null}, it is recommended to use {@link #hasResult()} first
125
+ * to check if there is a result prior to calling this method.
125
126
*/
126
127
public Object getResult () {
127
- return hasResult () ? this .result : null ;
128
+ Object resultToCheck = this .result ;
129
+ return (resultToCheck != RESULT_NONE ? resultToCheck : null );
128
130
}
129
131
130
132
/**
@@ -165,12 +167,12 @@ public final void setResultHandler(DeferredResultHandler resultHandler) {
165
167
Assert .notNull (resultHandler , "DeferredResultHandler is required" );
166
168
synchronized (this ) {
167
169
this .resultHandler = resultHandler ;
168
- if (( this .result != RESULT_NONE ) && ( !this .expired ) ) {
170
+ if (this .result != RESULT_NONE && !this .expired ) {
169
171
try {
170
172
this .resultHandler .handleResult (this .result );
171
173
}
172
- catch (Throwable t ) {
173
- logger .trace ("DeferredResult not handled" , t );
174
+ catch (Throwable ex ) {
175
+ logger .trace ("DeferredResult not handled" , ex );
174
176
}
175
177
}
176
178
}
@@ -214,9 +216,9 @@ public boolean setErrorResult(Object result) {
214
216
return setResultInternal (result );
215
217
}
216
218
219
+
217
220
final DeferredResultProcessingInterceptor getInterceptor () {
218
221
return new DeferredResultProcessingInterceptorAdapter () {
219
-
220
222
@ Override
221
223
public <S > boolean handleTimeout (NativeWebRequest request , DeferredResult <S > deferredResult ) {
222
224
if (timeoutCallback != null ) {
@@ -227,7 +229,6 @@ public <S> boolean handleTimeout(NativeWebRequest request, DeferredResult<S> def
227
229
}
228
230
return true ;
229
231
}
230
-
231
232
@ Override
232
233
public <S > void afterCompletion (NativeWebRequest request , DeferredResult <S > deferredResult ) {
233
234
synchronized (DeferredResult .this ) {
0 commit comments