Add onTimeout/onCompletion callbacks to DeferredResult

Issue: SPR-9914
This commit is contained in:
Rossen Stoyanchev
2012-10-30 21:55:38 -04:00
parent 3a09644843
commit d701464517
21 changed files with 309 additions and 158 deletions

View File

@@ -905,7 +905,7 @@ public abstract class FrameworkServlet extends HttpServletBean {
initContextHolders(request, localeContext, requestAttributes);
WebAsyncManager asyncManager = WebAsyncUtils.getAsyncManager(request);
asyncManager.registerCallableInterceptor(this.getClass().getName(), createRequestBindingInterceptor(request));
asyncManager.registerCallableInterceptor(FrameworkServlet.class.getName(), getRequestBindingInterceptor(request));
try {
doService(request, response);
@@ -988,7 +988,7 @@ public abstract class FrameworkServlet extends HttpServletBean {
}
}
private CallableProcessingInterceptor createRequestBindingInterceptor(final HttpServletRequest request) {
private CallableProcessingInterceptor getRequestBindingInterceptor(final HttpServletRequest request) {
return new CallableProcessingInterceptorAdapter() {
@Override
public <T> void preProcess(NativeWebRequest webRequest, Callable<T> task) {

View File

@@ -23,7 +23,7 @@ import java.util.concurrent.Callable;
import org.springframework.core.task.AsyncTaskExecutor;
import org.springframework.core.task.SimpleAsyncTaskExecutor;
import org.springframework.util.Assert;
import org.springframework.web.context.request.async.AsyncTask;
import org.springframework.web.context.request.async.MvcAsyncTask;
import org.springframework.web.context.request.async.CallableProcessingInterceptor;
import org.springframework.web.context.request.async.DeferredResult;
import org.springframework.web.context.request.async.DeferredResultProcessingInterceptor;
@@ -50,7 +50,7 @@ public class AsyncSupportConfigurer {
/**
* Set the default {@link AsyncTaskExecutor} to use when a controller method
* returns a {@link Callable}. Controller methods can override this default on
* a per-request basis by returning an {@link AsyncTask}.
* a per-request basis by returning an {@link MvcAsyncTask}.
*
* <p>By default a {@link SimpleAsyncTaskExecutor} instance is used and it's
* highly recommended to change that default in production since the simple

View File

@@ -19,13 +19,13 @@ package org.springframework.web.servlet.mvc.method.annotation;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.core.MethodParameter;
import org.springframework.web.context.request.NativeWebRequest;
import org.springframework.web.context.request.async.AsyncTask;
import org.springframework.web.context.request.async.MvcAsyncTask;
import org.springframework.web.context.request.async.WebAsyncUtils;
import org.springframework.web.method.support.HandlerMethodReturnValueHandler;
import org.springframework.web.method.support.ModelAndViewContainer;
/**
* Handles return values of type {@link AsyncTask}.
* Handles return values of type {@link MvcAsyncTask}.
*
* @author Rossen Stoyanchev
* @since 3.2
@@ -41,7 +41,7 @@ public class AsyncTaskMethodReturnValueHandler implements HandlerMethodReturnVal
public boolean supportsReturnType(MethodParameter returnType) {
Class<?> paramType = returnType.getParameterType();
return AsyncTask.class.isAssignableFrom(paramType);
return MvcAsyncTask.class.isAssignableFrom(paramType);
}
public void handleReturnValue(Object returnValue,
@@ -52,9 +52,9 @@ public class AsyncTaskMethodReturnValueHandler implements HandlerMethodReturnVal
return;
}
AsyncTask<?> asyncTask = (AsyncTask<?>) returnValue;
asyncTask.setBeanFactory(this.beanFactory);
WebAsyncUtils.getAsyncManager(webRequest).startCallableProcessing(asyncTask, mavContainer);
MvcAsyncTask<?> mvcAsyncTask = (MvcAsyncTask<?>) returnValue;
mvcAsyncTask.setBeanFactory(this.beanFactory);
WebAsyncUtils.getAsyncManager(webRequest).startCallableProcessing(mvcAsyncTask, mavContainer);
}
}

View File

@@ -63,7 +63,7 @@ import org.springframework.web.bind.support.WebDataBinderFactory;
import org.springframework.web.context.request.NativeWebRequest;
import org.springframework.web.context.request.ServletWebRequest;
import org.springframework.web.context.request.WebRequest;
import org.springframework.web.context.request.async.AsyncTask;
import org.springframework.web.context.request.async.MvcAsyncTask;
import org.springframework.web.context.request.async.AsyncWebRequest;
import org.springframework.web.context.request.async.CallableProcessingInterceptor;
import org.springframework.web.context.request.async.DeferredResultProcessingInterceptor;
@@ -350,7 +350,7 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter i
/**
* Set the default {@link AsyncTaskExecutor} to use when a controller method
* return a {@link Callable}. Controller methods can override this default on
* a per-request basis by returning an {@link AsyncTask}.
* a per-request basis by returning an {@link MvcAsyncTask}.
* <p>By default a {@link SimpleAsyncTaskExecutor} instance is used.
* It's recommended to change that default in production as the simple executor
* does not re-use threads.