public class AsyncContinuation extends Object implements javax.servlet.AsyncContext, Continuation
| Modifier and Type | Class and Description |
|---|---|
class |
AsyncContinuation.AsyncEventState |
class |
AsyncContinuation.AsyncTimeout |
| Modifier and Type | Field and Description |
|---|---|
protected AbstractHttpConnection |
_connection |
ASYNC_CONTEXT_PATH, ASYNC_PATH_INFO, ASYNC_QUERY_STRING, ASYNC_REQUEST_URI, ASYNC_SERVLET_PATHATTRIBUTE| Modifier | Constructor and Description |
|---|---|
protected |
AsyncContinuation() |
| Modifier and Type | Method and Description |
|---|---|
void |
addContinuationListener(ContinuationListener listener)
Add a ContinuationListener.
|
void |
addListener(javax.servlet.AsyncListener listener) |
void |
addListener(javax.servlet.AsyncListener listener,
javax.servlet.ServletRequest request,
javax.servlet.ServletResponse response) |
void |
cancel() |
protected void |
cancelTimeout() |
void |
complete()
Complete a suspended request.
|
<T extends javax.servlet.AsyncListener> |
createListener(Class<T> clazz) |
void |
dispatch() |
void |
dispatch(javax.servlet.ServletContext context,
String path) |
void |
dispatch(String path) |
protected void |
doComplete(Throwable ex) |
protected void |
expired() |
AsyncContinuation.AsyncEventState |
getAsyncEventState() |
Object |
getAttribute(String name)
Get a request attribute.
|
Request |
getBaseRequest() |
ContextHandler |
getContextHandler() |
javax.servlet.ServletRequest |
getRequest() |
javax.servlet.ServletResponse |
getResponse() |
javax.servlet.ServletResponse |
getServletResponse()
Get the suspended response.
|
String |
getStatusString() |
long |
getTimeout() |
protected boolean |
handling() |
boolean |
hasOriginalRequestAndResponse() |
boolean |
isAsync() |
boolean |
isAsyncStarted() |
boolean |
isComplete() |
boolean |
isCompleting() |
boolean |
isDispatchable() |
boolean |
isExpired() |
boolean |
isInitial() |
boolean |
isResponseWrapped()
Is the suspended response wrapped.
|
boolean |
isResumed() |
boolean |
isSuspended() |
boolean |
isSuspending() |
protected void |
recycle() |
void |
removeAttribute(String name)
Remove a request attribute.
|
void |
resume()
Resume a suspended request.
|
protected void |
scheduleDispatch() |
protected void |
scheduleTimeout() |
void |
setAttribute(String name,
Object attribute)
Set a request attribute.
|
protected void |
setConnection(AbstractHttpConnection connection) |
void |
setTimeout(long ms)
Set the continuation timeout.
|
void |
start(Runnable run) |
void |
suspend()
Suspend the processing of the request and associated
ServletResponse. |
protected void |
suspend(javax.servlet.ServletContext context,
javax.servlet.ServletRequest request,
javax.servlet.ServletResponse response) |
void |
suspend(javax.servlet.ServletResponse response)
Suspend the processing of the request and associated
ServletResponse. |
String |
toString() |
void |
undispatch()
Undispatch the request.
|
protected boolean |
unhandle()
Signal that the HttpConnection has finished handling the request.
|
protected AbstractHttpConnection _connection
protected void setConnection(AbstractHttpConnection connection)
public void addListener(javax.servlet.AsyncListener listener)
addListener in interface javax.servlet.AsyncContextpublic void addListener(javax.servlet.AsyncListener listener,
javax.servlet.ServletRequest request,
javax.servlet.ServletResponse response)
addListener in interface javax.servlet.AsyncContextpublic void addContinuationListener(ContinuationListener listener)
ContinuationaddContinuationListener in interface Continuationpublic void setTimeout(long ms)
ContinuationsetTimeout in interface javax.servlet.AsyncContextsetTimeout in interface Continuationms - The time in milliseconds to wait before expiring this
continuation after a call to Continuation.suspend() or Continuation.suspend(ServletResponse).
A timeout of <=0 means the continuation will never expire.public long getTimeout()
getTimeout in interface javax.servlet.AsyncContextpublic AsyncContinuation.AsyncEventState getAsyncEventState()
public boolean isResponseWrapped()
Continuation
Filters that wrap the response object should check this method to
determine if they should destroy/finish the wrapped response. If
the request was suspended with a call to Continuation.suspend(ServletResponse)
that passed the wrapped response, then the filter should register
a ContinuationListener to destroy/finish the wrapped response
during a call to ContinuationListener.onComplete(Continuation).
isResponseWrapped in interface ContinuationContinuation.suspend(ServletResponse) has been passed a
ServletResponseWrapper instance.Continuation.isResponseWrapped()public boolean isInitial()
isInitial in interface Continuationpublic boolean isSuspended()
isSuspended in interface ContinuationContinuation.suspend() has been called and before the
request has been redispatched due to being resumed, completed or
timed out.public boolean isSuspending()
public boolean isDispatchable()
public String getStatusString()
protected boolean handling()
protected boolean unhandle()
public void dispatch()
dispatch in interface javax.servlet.AsyncContextprotected void expired()
public void complete()
ContinuationThis method can be called by any thread that has been passed a reference to a suspended request. When a request is completed, the associated response object committed and flushed. The request is not redispatched.
If complete is called before a suspended request is returned to the
container (ie the thread that called Continuation.suspend() is still
within the filter chain and/or servlet service method), then the complete
does not take effect until the call to the filter chain and/or servlet
returns to the container. In this case both Continuation.isSuspended() and
Continuation.isResumed() return true.
Typically resume() is used after a call to Continuation.suspend(ServletResponse) with
a possibly wrapped response. The async handler should use the response
provided by Continuation.getServletResponse() to write the response before
calling Continuation.complete(). If the request was suspended with a
call to Continuation.suspend() then no response object will be available via
Continuation.getServletResponse().
Once complete has been called and any thread calling the filter chain and/or servlet chain has returned to the container, the request lifecycle is complete. The container is able to recycle request objects, so it is not valid hold a request or continuation reference after the end of the life cycle.
complete in interface javax.servlet.AsyncContextcomplete in interface ContinuationContinuation.suspend()public <T extends javax.servlet.AsyncListener> T createListener(Class<T> clazz) throws javax.servlet.ServletException
createListener in interface javax.servlet.AsyncContextjavax.servlet.ServletExceptionprotected void doComplete(Throwable ex)
protected void recycle()
public void cancel()
protected void scheduleDispatch()
protected void scheduleTimeout()
protected void cancelTimeout()
public boolean isCompleting()
public boolean isComplete()
public boolean isAsyncStarted()
public boolean isAsync()
public void dispatch(javax.servlet.ServletContext context,
String path)
dispatch in interface javax.servlet.AsyncContextpublic void dispatch(String path)
dispatch in interface javax.servlet.AsyncContextpublic Request getBaseRequest()
public javax.servlet.ServletRequest getRequest()
getRequest in interface javax.servlet.AsyncContextpublic javax.servlet.ServletResponse getResponse()
getResponse in interface javax.servlet.AsyncContextpublic void start(Runnable run)
start in interface javax.servlet.AsyncContextpublic boolean hasOriginalRequestAndResponse()
hasOriginalRequestAndResponse in interface javax.servlet.AsyncContextpublic ContextHandler getContextHandler()
public boolean isResumed()
isResumed in interface ContinuationContinuation.resume(). Returns false after any subsequent call to
suspendContinuation.isResumed()public boolean isExpired()
isExpired in interface ContinuationContinuation.isExpired()public void resume()
Continuation
This method can be called by any thread that has been passed a reference
to a continuation. When called the request is redispatched to the
normal filter chain and servlet processing with Continuation.isInitial() false.
If resume is called before a suspended request is returned to the
container (ie the thread that called Continuation.suspend() is still
within the filter chain and/or servlet service method), then the resume
does not take effect until the call to the filter chain and/or servlet
returns to the container. In this case both Continuation.isSuspended() and
Continuation.isResumed() return true. Multiple calls to resume are ignored.
Typically resume() is used after a call to Continuation.suspend() with
no arguments. The dispatch after a resume call will use the original
request and response objects, even if Continuation.suspend(ServletResponse)
had been passed a wrapped response.
resume in interface ContinuationContinuation.resume()protected void suspend(javax.servlet.ServletContext context,
javax.servlet.ServletRequest request,
javax.servlet.ServletResponse response)
public void suspend(javax.servlet.ServletResponse response)
ContinuationServletResponse.
After this method has been called, the lifecycle of the request will be
extended beyond the return to the container from the
Servlet.service(ServletRequest, ServletResponse) method and
Filter.doFilter(ServletRequest, ServletResponse, FilterChain)
calls. When a suspended request is returned to the container after
a dispatch, then the container will not commit the associated response
(unless an exception other than ContinuationThrowable is thrown).
When the thread calling the filter chain and/or servlet has returned to the container with a suspended request, the thread is freed for other tasks and the request is held until either:
Continuation.resume().Continuation.complete().
Typically suspend with a response argument is uses when a call to Continuation.complete()
is expected. If a call to Continuation.resume() is expected, then the
Continuation.suspend() method should be used instead of this method.
Filters that may wrap the response object should check Continuation.isResponseWrapped()
to decide if they should destroy/finish the wrapper. If Continuation.isResponseWrapped()
returns true, then the wrapped request has been passed to the asynchronous
handler and the wrapper should not be destroyed/finished until after a call to
Continuation.complete() (potentially using a ContinuationListener.onComplete(Continuation)
listener).
suspend in interface Continuationresponse - The response to return via a call to Continuation.getServletResponse()Continuation.suspend()public void suspend()
ContinuationServletResponse.
After this method has been called, the lifecycle of the request will be
extended beyond the return to the container from the
Servlet.service(ServletRequest, ServletResponse) method and
Filter.doFilter(ServletRequest, ServletResponse, FilterChain)
calls. When a suspended request is returned to the container after
a dispatch, then the container will not commit the associated response
(unless an exception other than ContinuationThrowable is thrown).
When the thread calling the filter chain and/or servlet has returned to the container with a suspended request, the thread is freed for other tasks and the request is held until either:
Continuation.resume().Continuation.complete().
Typically suspend with no arguments is uses when a call to Continuation.resume()
is expected. If a call to Continuation.complete() is expected, then the
Continuation.suspend(ServletResponse) method should be used instead of this method.
suspend in interface ContinuationContinuation.suspend()public javax.servlet.ServletResponse getServletResponse()
ContinuationgetServletResponse in interface ContinuationServletResponse passed to Continuation.suspend(ServletResponse).Continuation.getServletResponse()public Object getAttribute(String name)
ContinuationServletRequest.getAttribute(String)
method on the associated request object.
This is a thread safe call and may be called by any thread.getAttribute in interface Continuationname - the attribute nameContinuation.getAttribute(java.lang.String)public void removeAttribute(String name)
ContinuationServletRequest.removeAttribute(String)
method on the associated request object.
This is a thread safe call and may be called by any thread.removeAttribute in interface Continuationname - the attribute nameContinuation.removeAttribute(java.lang.String)public void setAttribute(String name, Object attribute)
ContinuationServletRequest.setAttribute(String, Object)
method on the associated request object.
This is a thread safe call and may be called by any thread.setAttribute in interface Continuationname - the attribute nameattribute - the attribute valueContinuation.setAttribute(java.lang.String, java.lang.Object)public void undispatch()
Continuation
This method can be called on a suspended continuation in order
to exit the dispatch to the filter/servlet by throwing a ContinuationThrowable
which is caught either by the container or the ContinuationFilter.
This is an alternative to simply returning from the dispatch in the case
where filters in the filter chain may not be prepared to handle a suspended
request.
undispatch in interface ContinuationContinuation.undispatch()Copyright © 1995-2013 Mort Bay Consulting. All Rights Reserved.