001/* 002 * Copyright 2002-2017 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 java.util.function.Consumer; 020 021import org.springframework.lang.Nullable; 022import org.springframework.web.context.request.NativeWebRequest; 023 024/** 025 * Extends {@link NativeWebRequest} with methods for asynchronous request processing. 026 * 027 * @author Rossen Stoyanchev 028 * @since 3.2 029 */ 030public interface AsyncWebRequest extends NativeWebRequest { 031 032 /** 033 * Set the time required for concurrent handling to complete. 034 * This property should not be set when concurrent handling is in progress, 035 * i.e. when {@link #isAsyncStarted()} is {@code true}. 036 * @param timeout amount of time in milliseconds; {@code null} means no 037 * timeout, i.e. rely on the default timeout of the container. 038 */ 039 void setTimeout(@Nullable Long timeout); 040 041 /** 042 * Add a handler to invoke when concurrent handling has timed out. 043 */ 044 void addTimeoutHandler(Runnable runnable); 045 046 /** 047 * Add a handler to invoke when an error occurred while concurrent 048 * handling of a request. 049 * @since 5.0 050 */ 051 void addErrorHandler(Consumer<Throwable> exceptionHandler); 052 053 /** 054 * Add a handler to invoke when request processing completes. 055 */ 056 void addCompletionHandler(Runnable runnable); 057 058 /** 059 * Mark the start of asynchronous request processing so that when the main 060 * processing thread exits, the response remains open for further processing 061 * in another thread. 062 * @throws IllegalStateException if async processing has completed or is not supported 063 */ 064 void startAsync(); 065 066 /** 067 * Whether the request is in async mode following a call to {@link #startAsync()}. 068 * Returns "false" if asynchronous processing never started, has completed, 069 * or the request was dispatched for further processing. 070 */ 071 boolean isAsyncStarted(); 072 073 /** 074 * Dispatch the request to the container in order to resume processing after 075 * concurrent execution in an application thread. 076 */ 077 void dispatch(); 078 079 /** 080 * Whether asynchronous processing has completed. 081 */ 082 boolean isAsyncComplete(); 083 084}