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 ;
19
20
import java .util .concurrent .Callable ;
20
21
21
22
import org .apache .commons .logging .Log ;
22
23
import org .apache .commons .logging .LogFactory ;
24
+
23
25
import org .springframework .util .Assert ;
24
26
import org .springframework .web .context .request .NativeWebRequest ;
25
27
@@ -63,9 +65,9 @@ public class DeferredResult<T> {
63
65
64
66
private DeferredResultHandler resultHandler ;
65
67
66
- private Object result = RESULT_NONE ;
68
+ private volatile Object result = RESULT_NONE ;
67
69
68
- private boolean expired ;
70
+ private volatile boolean expired ;
69
71
70
72
71
73
/**
@@ -94,17 +96,17 @@ public DeferredResult(Long timeout, Object timeoutResult) {
94
96
this .timeout = timeout ;
95
97
}
96
98
99
+
97
100
/**
98
101
* Return {@code true} if this DeferredResult is no longer usable either
99
102
* because it was previously set or because the underlying request expired.
100
- * <p>
101
- * 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)},
102
104
* or {@link #setErrorResult(Object)}, or as a result of a timeout, if a
103
105
* timeout result was provided to the constructor. The request may also
104
106
* expire due to a timeout or network error.
105
107
*/
106
108
public final boolean isSetOrExpired () {
107
- return (( this .result != RESULT_NONE ) || this .expired );
109
+ return (this .result != RESULT_NONE || this .expired );
108
110
}
109
111
110
112
/**
@@ -145,12 +147,12 @@ public final void setResultHandler(DeferredResultHandler resultHandler) {
145
147
Assert .notNull (resultHandler , "DeferredResultHandler is required" );
146
148
synchronized (this ) {
147
149
this .resultHandler = resultHandler ;
148
- if (( this .result != RESULT_NONE ) && ( !this .expired ) ) {
150
+ if (this .result != RESULT_NONE && !this .expired ) {
149
151
try {
150
152
this .resultHandler .handleResult (this .result );
151
153
}
152
- catch (Throwable t ) {
153
- logger .trace ("DeferredResult not handled" , t );
154
+ catch (Throwable ex ) {
155
+ logger .trace ("DeferredResult not handled" , ex );
154
156
}
155
157
}
156
158
}
@@ -194,9 +196,9 @@ public boolean setErrorResult(Object result) {
194
196
return setResultInternal (result );
195
197
}
196
198
199
+
197
200
final DeferredResultProcessingInterceptor getInterceptor () {
198
201
return new DeferredResultProcessingInterceptorAdapter () {
199
-
200
202
@ Override
201
203
public <S > boolean handleTimeout (NativeWebRequest request , DeferredResult <S > deferredResult ) {
202
204
if (timeoutCallback != null ) {
@@ -207,7 +209,6 @@ public <S> boolean handleTimeout(NativeWebRequest request, DeferredResult<S> def
207
209
}
208
210
return true ;
209
211
}
210
-
211
212
@ Override
212
213
public <S > void afterCompletion (NativeWebRequest request , DeferredResult <S > deferredResult ) {
213
214
synchronized (DeferredResult .this ) {
0 commit comments