Package jakarta.servlet
Interface AsyncContext
public interface AsyncContext
Provides the context for asynchronous request handling
- Since:
- Servlet 3.0
- 
Field SummaryFieldsModifier and TypeFieldDescriptionstatic final StringThe attribute name for the Context Path of the async requeststatic final StringThe attribute name for the Mapping of the async requeststatic final StringThe attribute name for the Path Info of the async requeststatic final StringThe attribute name for the Query String of the async requeststatic final StringThe attribute name for the URI of the async requeststatic final StringThe attribute name for the Servlet Path of the async request
- 
Method SummaryModifier and TypeMethodDescriptionvoidaddListener(AsyncListener listener) Adds an event listener that will be called for different AsyncEvents firevoidaddListener(AsyncListener listener, ServletRequest request, ServletResponse response) Adds an event listener that will be called when different AsyncEvents firevoidcomplete()Completes the async request processing and closes the response stream<T extends AsyncListener>
 TcreateListener(Class<T> clazz) Creates and returns an AsyncListener objectvoiddispatch()voiddispatch(ServletContext context, String path) voidlongGet the current timeout.booleanvoidsetTimeout(long timeout) Set the timeout.voidStarts a new thread to process the asynchronous request
- 
Field Details- 
ASYNC_REQUEST_URIThe attribute name for the URI of the async request- See Also:
 
- 
ASYNC_CONTEXT_PATHThe attribute name for the Context Path of the async request- See Also:
 
- 
ASYNC_MAPPINGThe attribute name for the Mapping of the async request- See Also:
 
- 
ASYNC_PATH_INFOThe attribute name for the Path Info of the async request- See Also:
 
- 
ASYNC_SERVLET_PATHThe attribute name for the Servlet Path of the async request- See Also:
 
- 
ASYNC_QUERY_STRINGThe attribute name for the Query String of the async request- See Also:
 
 
- 
- 
Method Details- 
getRequestServletRequest getRequest()- Returns:
- a reference to the ServletRequest object
 
- 
getResponseServletResponse getResponse()- Returns:
- a reference to the ServletResponse object
 
- 
hasOriginalRequestAndResponseboolean hasOriginalRequestAndResponse()- Returns:
- true if the Request and Response are the original ones
 
- 
dispatchvoid dispatch()- Throws:
- IllegalStateException- if this method is called when the request is not in asynchronous mode. The request is in asynchronous mode after- ServletRequest.startAsync()or- ServletRequest.startAsync(ServletRequest, ServletResponse)has been called and before- complete()or any other dispatch() method has been called.
 
- 
dispatch- Parameters:
- path- The path to which the request/response should be dispatched relative to the- ServletContextfrom which this async request was started.
- Throws:
- IllegalStateException- if this method is called when the request is not in asynchronous mode. The request is in asynchronous mode after- ServletRequest.startAsync()or- ServletRequest.startAsync(ServletRequest, ServletResponse)has been called and before- complete()or any other dispatch() method has been called.
 
- 
dispatch- Parameters:
- path- The path to which the request/response should be dispatched relative to the specified- ServletContext.
- context- The- ServletContextto which the request/response should be dispatched.
- Throws:
- IllegalStateException- if this method is called when the request is not in asynchronous mode. The request is in asynchronous mode after- ServletRequest.startAsync()or- ServletRequest.startAsync(ServletRequest, ServletResponse)has been called and before- complete()or any other dispatch() method has been called.
 
- 
completevoid complete()Completes the async request processing and closes the response stream
- 
startStarts a new thread to process the asynchronous request- Parameters:
- run- a Runnable that the new thread will run
 
- 
addListenerAdds an event listener that will be called for different AsyncEvents fire- Parameters:
- listener- an AsyncListener that will be called with AsyncEvent objects
 
- 
addListenerAdds an event listener that will be called when different AsyncEvents fire- Parameters:
- listener- an AsyncListener that will be called with AsyncEvent objects
- request- the ServletRequest that will be passed with the AsyncEvent
- response- the ServletResponse that will be passed with the AsyncEvent
 
- 
createListenerCreates and returns an AsyncListener object- Type Parameters:
- T- The type to create that extends AsyncListener
- Parameters:
- clazz- The class to instantiate to create the listener
- Returns:
- the newly created AsyncListener object
- Throws:
- ServletException- if the listener cannot be created
 
- 
setTimeoutvoid setTimeout(long timeout) Set the timeout.- Parameters:
- timeout- The timeout in milliseconds. 0 or less indicates no timeout.
 
- 
getTimeoutlong getTimeout()Get the current timeout.- Returns:
- The timeout in milliseconds. 0 or less indicates no timeout.
 
 
-