Provide method to set async TimeoutHandler

Issue: SPR-9914
This commit is contained in:
Rossen Stoyanchev
2012-10-25 12:35:23 -04:00
parent b093b30315
commit cb86712187
2 changed files with 40 additions and 10 deletions

View File

@@ -66,6 +66,8 @@ public final class WebAsyncManager {
private AsyncTaskExecutor taskExecutor = new SimpleAsyncTaskExecutor(this.getClass().getSimpleName());
private Runnable timeoutHandler;
private Object concurrentResult = RESULT_NONE;
private Object[] concurrentResultContext;
@@ -117,6 +119,15 @@ public final class WebAsyncManager {
this.taskExecutor = taskExecutor;
}
/**
* Set the handler to use when concurrent handling times out. If not set, by
* default a timeout is handled by returning SERVICE_UNAVAILABLE (503).
* @param timeoutHandler the handler
*/
public void setTimeoutHandler(Runnable timeoutHandler) {
this.timeoutHandler = timeoutHandler;
}
/**
* Whether the selected handler for the current request chose to handle the
* request asynchronously. A return value of "true" indicates concurrent
@@ -348,6 +359,10 @@ public final class WebAsyncManager {
Assert.state(this.asyncWebRequest != null, "AsyncWebRequest must not be null");
this.asyncWebRequest.startAsync();
if (this.timeoutHandler != null) {
this.asyncWebRequest.setTimeoutHandler(this.timeoutHandler);
}
if (logger.isDebugEnabled()) {
HttpServletRequest request = asyncWebRequest.getNativeRequest(HttpServletRequest.class);
String requestUri = urlPathHelper.getRequestUri(request);