|
|
|
|
@ -18,6 +18,7 @@ package org.springframework.web.context.request.async;
@@ -18,6 +18,7 @@ package org.springframework.web.context.request.async;
|
|
|
|
|
|
|
|
|
|
import java.util.List; |
|
|
|
|
import java.util.concurrent.Callable; |
|
|
|
|
import java.util.concurrent.Future; |
|
|
|
|
|
|
|
|
|
import org.apache.commons.logging.Log; |
|
|
|
|
import org.apache.commons.logging.LogFactory; |
|
|
|
|
@ -39,11 +40,19 @@ class CallableInterceptorChain {
@@ -39,11 +40,19 @@ class CallableInterceptorChain {
|
|
|
|
|
|
|
|
|
|
private int preProcessIndex = -1; |
|
|
|
|
|
|
|
|
|
private volatile Future<?> taskFuture; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public CallableInterceptorChain(List<CallableProcessingInterceptor> interceptors) { |
|
|
|
|
this.interceptors = interceptors; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void setTaskFuture(Future<?> taskFuture) { |
|
|
|
|
this.taskFuture = taskFuture; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void applyBeforeConcurrentHandling(NativeWebRequest request, Callable<?> task) throws Exception { |
|
|
|
|
for (CallableProcessingInterceptor interceptor : this.interceptors) { |
|
|
|
|
interceptor.beforeConcurrentHandling(request, task); |
|
|
|
|
@ -77,6 +86,7 @@ class CallableInterceptorChain {
@@ -77,6 +86,7 @@ class CallableInterceptorChain {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public Object triggerAfterTimeout(NativeWebRequest request, Callable<?> task) { |
|
|
|
|
cancelTask(); |
|
|
|
|
for (CallableProcessingInterceptor interceptor : this.interceptors) { |
|
|
|
|
try { |
|
|
|
|
Object result = interceptor.handleTimeout(request, task); |
|
|
|
|
@ -94,7 +104,20 @@ class CallableInterceptorChain {
@@ -94,7 +104,20 @@ class CallableInterceptorChain {
|
|
|
|
|
return CallableProcessingInterceptor.RESULT_NONE; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void cancelTask() { |
|
|
|
|
Future<?> future = this.taskFuture; |
|
|
|
|
if (future != null) { |
|
|
|
|
try { |
|
|
|
|
future.cancel(true); |
|
|
|
|
} |
|
|
|
|
catch (Throwable ex) { |
|
|
|
|
// Ignore
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public Object triggerAfterError(NativeWebRequest request, Callable<?> task, Throwable throwable) { |
|
|
|
|
cancelTask(); |
|
|
|
|
for (CallableProcessingInterceptor interceptor : this.interceptors) { |
|
|
|
|
try { |
|
|
|
|
Object result = interceptor.handleError(request, task, throwable); |
|
|
|
|
|