Package org.apache.catalina.core
Class AsyncContextImpl
- java.lang.Object
-
- org.apache.catalina.core.AsyncContextImpl
-
- All Implemented Interfaces:
AsyncContext,AsyncContextCallback
public class AsyncContextImpl extends Object implements AsyncContext, AsyncContextCallback
-
-
Field Summary
Fields Modifier and Type Field Description protected static StringManagersm-
Fields inherited from interface javax.servlet.AsyncContext
ASYNC_CONTEXT_PATH, ASYNC_PATH_INFO, ASYNC_QUERY_STRING, ASYNC_REQUEST_URI, ASYNC_SERVLET_PATH
-
-
Constructor Summary
Constructors Constructor Description AsyncContextImpl(Request request)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddListener(AsyncListener listener)Adds an event listener that will be called for different AsyncEvents firevoidaddListener(AsyncListener listener, ServletRequest servletRequest, ServletResponse servletResponse)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 objectvoiddecrementInProgressAsyncCount()Used to notify the Context that async processing has ended.voiddispatch()voiddispatch(String path)voiddispatch(ServletContext servletContext, String path)protected voiddoInternalDispatch()voidfireOnComplete()ServletRequestgetRequest()ServletResponsegetResponse()longgetTimeout()Get the current timeout.booleanhasOriginalRequestAndResponse()voidincrementInProgressAsyncCount()Used to notify the Context that async processing has started.booleanisAvailable()Reports if the web application associated with this async request is available.booleanisStarted()voidrecycle()voidsetErrorState(Throwable t, boolean fireOnError)voidsetStarted(Context context, ServletRequest request, ServletResponse response, boolean originalRequestResponse)voidsetTimeout(long timeout)Set the timeout.voidstart(Runnable run)Starts a new thread to process the asynchronous requestbooleantimeout()
-
-
-
Field Detail
-
sm
protected static final StringManager sm
-
-
Constructor Detail
-
AsyncContextImpl
public AsyncContextImpl(Request request)
-
-
Method Detail
-
complete
public void complete()
Description copied from interface:javax.servlet.AsyncContextCompletes the async request processing and closes the response stream- Specified by:
completein interfaceAsyncContext
-
fireOnComplete
public void fireOnComplete()
- Specified by:
fireOnCompletein interfaceAsyncContextCallback
-
timeout
public boolean timeout()
-
dispatch
public void dispatch()
- Specified by:
dispatchin interfaceAsyncContext
-
dispatch
public void dispatch(String path)
- Specified by:
dispatchin interfaceAsyncContext- Parameters:
path- The path to which the request/response should be dispatched relative to theServletContextfrom which this async request was started.
-
dispatch
public void dispatch(ServletContext servletContext, String path)
- Specified by:
dispatchin interfaceAsyncContext- Parameters:
servletContext- TheServletContextto which the request/response should be dispatched.path- The path to which the request/response should be dispatched relative to the specifiedServletContext.
-
getRequest
public ServletRequest getRequest()
- Specified by:
getRequestin interfaceAsyncContext- Returns:
- a reference to the ServletRequest object
-
getResponse
public ServletResponse getResponse()
- Specified by:
getResponsein interfaceAsyncContext- Returns:
- a reference to the ServletResponse object
-
start
public void start(Runnable run)
Description copied from interface:javax.servlet.AsyncContextStarts a new thread to process the asynchronous request- Specified by:
startin interfaceAsyncContext- Parameters:
run- a Runnable that the new thread will run
-
addListener
public void addListener(AsyncListener listener)
Description copied from interface:javax.servlet.AsyncContextAdds an event listener that will be called for different AsyncEvents fire- Specified by:
addListenerin interfaceAsyncContext- Parameters:
listener- an AsyncListener that will be called with AsyncEvent objects
-
addListener
public void addListener(AsyncListener listener, ServletRequest servletRequest, ServletResponse servletResponse)
Description copied from interface:javax.servlet.AsyncContextAdds an event listener that will be called when different AsyncEvents fire- Specified by:
addListenerin interfaceAsyncContext- Parameters:
listener- an AsyncListener that will be called with AsyncEvent objectsservletRequest- the ServletRequest that will be passed with the AsyncEventservletResponse- the ServletResponse that will be passed with the AsyncEvent
-
createListener
public <T extends AsyncListener> T createListener(Class<T> clazz) throws ServletException
Description copied from interface:javax.servlet.AsyncContextCreates and returns an AsyncListener object- Specified by:
createListenerin interfaceAsyncContext- 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
-
recycle
public void recycle()
-
isStarted
public boolean isStarted()
-
setStarted
public void setStarted(Context context, ServletRequest request, ServletResponse response, boolean originalRequestResponse)
-
hasOriginalRequestAndResponse
public boolean hasOriginalRequestAndResponse()
- Specified by:
hasOriginalRequestAndResponsein interfaceAsyncContext- Returns:
- true if the Request and Response are the original ones
-
doInternalDispatch
protected void doInternalDispatch() throws ServletException, IOException- Throws:
ServletExceptionIOException
-
getTimeout
public long getTimeout()
Description copied from interface:javax.servlet.AsyncContextGet the current timeout.- Specified by:
getTimeoutin interfaceAsyncContext- Returns:
- The timeout in milliseconds. 0 or less indicates no timeout.
-
setTimeout
public void setTimeout(long timeout)
Description copied from interface:javax.servlet.AsyncContextSet the timeout.- Specified by:
setTimeoutin interfaceAsyncContext- Parameters:
timeout- The timeout in milliseconds. 0 or less indicates no timeout.
-
isAvailable
public boolean isAvailable()
Description copied from interface:AsyncContextCallbackReports if the web application associated with this async request is available.- Specified by:
isAvailablein interfaceAsyncContextCallback- Returns:
trueif the associated web application is available, otherwisefalse
-
setErrorState
public void setErrorState(Throwable t, boolean fireOnError)
-
incrementInProgressAsyncCount
public void incrementInProgressAsyncCount()
Description copied from interface:AsyncContextCallbackUsed to notify the Context that async processing has started. Specifically, for the counting of in-progress async requests to work correctly, this must be called exactly once every time theAsyncStateMachinetransitions from DISPATCHED to any other state.- Specified by:
incrementInProgressAsyncCountin interfaceAsyncContextCallback
-
decrementInProgressAsyncCount
public void decrementInProgressAsyncCount()
Description copied from interface:AsyncContextCallbackUsed to notify the Context that async processing has ended. Specifically, for the counting of in-progress async requests to work correctly, this must be called exactly once every time theAsyncStateMachinetransitions to DISPATCHED from any other state.- Specified by:
decrementInProgressAsyncCountin interfaceAsyncContextCallback
-
-