001/* 002 * Copyright 2002-2012 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.web.context.request.async; 018 019import org.springframework.web.context.request.NativeWebRequest; 020 021/** 022 * Extends {@link NativeWebRequest} with methods for asynchronous request processing. 023 * 024 * @author Rossen Stoyanchev 025 * @since 3.2 026 */ 027public interface AsyncWebRequest extends NativeWebRequest { 028 029 /** 030 * Set the time required for concurrent handling to complete. 031 * This property should not be set when concurrent handling is in progress, 032 * i.e. when {@link #isAsyncStarted()} is {@code true}. 033 * @param timeout amount of time in milliseconds; {@code null} means no 034 * timeout, i.e. rely on the default timeout of the container. 035 */ 036 void setTimeout(Long timeout); 037 038 /** 039 * Add a handler to invoke when concurrent handling has timed out. 040 */ 041 void addTimeoutHandler(Runnable runnable); 042 043 /** 044 * Add a handle to invoke when request processing completes. 045 */ 046 void addCompletionHandler(Runnable runnable); 047 048 /** 049 * Mark the start of asynchronous request processing so that when the main 050 * processing thread exits, the response remains open for further processing 051 * in another thread. 052 * @throws IllegalStateException if async processing has completed or is not supported 053 */ 054 void startAsync(); 055 056 /** 057 * Whether the request is in async mode following a call to {@link #startAsync()}. 058 * Returns "false" if asynchronous processing never started, has completed, 059 * or the request was dispatched for further processing. 060 */ 061 boolean isAsyncStarted(); 062 063 /** 064 * Dispatch the request to the container in order to resume processing after 065 * concurrent execution in an application thread. 066 */ 067 void dispatch(); 068 069 /** 070 * Whether asynchronous processing has completed. 071 */ 072 boolean isAsyncComplete(); 073 074}