java.io.Serializable
, javax.servlet.Servlet
, javax.servlet.ServletConfig
, FutureResponseModel
public abstract class AbstractAsyncServlet extends java.lang.Object implements FutureResponseModel
Implementations of AbstractAsyncServlet
decouple the
receiving of a servlet request from the sending of its
response. Responses may be sent in the future through the use of
the notify(weblogic.servlet.http.RequestResponseKey, java.lang.Object)
function. The servlet does not consume any
threads while waiting for notify(weblogic.servlet.http.RequestResponseKey, java.lang.Object)
to be called making it
suitable for scalable proxying to remote systems. The servlet
instance used for sending the response is only guaranteed to be the
same as that used to process the request when
SingleThreadModel
is used.
Stale requests are scavanged based on timeout settings
modifiable through setTimeout(int)
and setScavangeInterval(int)
.
The scavange interval is global to all
AbstractAsyncServlet
s. The timeout period is
per-servlet instance. If a timeout occurs then the doTimeout(weblogic.servlet.http.RequestResponseKey)
method
is called on an appropriate servlet instance, giving implementors a
chance to feedback timeout information to the caller.
Only direct client requests can be used with
AbstractAsyncServlet
, it cannot be used as the target
of request dispatching includes or forwards. It can however be used
to dispatch to forwards and includes that are not instances of
AbstractAsyncServlet
Servlet filters which get applied before
AbstractAsyncServlet
s, will not be able to take
advantage of post processing of the response.
Modifier and Type | Field | Description |
---|---|---|
static int |
DEFAULT_SCAVANGE_INTERVAL |
The default interval period in milliseconds at which requests
will be checked for timeouts.
|
static int |
DEFAULT_TIMEOUT |
The default request timeout period in milliseconds.
|
Modifier and Type | Method | Description |
---|---|---|
protected abstract boolean |
doRequest(RequestResponseKey rrk) |
Process the servlet request.
|
protected abstract void |
doResponse(RequestResponseKey rrk,
java.lang.Object context) |
Process the servlet response.
|
protected abstract void |
doTimeout(RequestResponseKey rrk) |
Send back a servlet response error when
notify(weblogic.servlet.http.RequestResponseKey, java.lang.Object) is not
called within the timeout period. |
static void |
notify(RequestResponseKey id,
java.lang.Object context) |
notify the servlet implementation that a response should be sent
for the key
id . |
protected void |
service(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse rsp) |
Implementation of the standard
HttpServlet.service(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) method. |
static void |
setScavangeInterval(int period) |
Sets the interval period in milliseconds at which requests will
be checked for timeouts.
|
protected void |
setTimeout(int period) |
Sets the request timeout period in milliseconds for this
servlet.
|
public static final int DEFAULT_TIMEOUT
public static final int DEFAULT_SCAVANGE_INTERVAL
protected final void service(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse rsp) throws java.io.IOException, javax.servlet.ServletException
HttpServlet.service(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
method. This method
cannot be overridden, implementors should instead override
doRequest(weblogic.servlet.http.RequestResponseKey)
and doResponse(weblogic.servlet.http.RequestResponseKey, java.lang.Object)
.java.io.IOException
javax.servlet.ServletException
public static final void notify(RequestResponseKey id, java.lang.Object context) throws java.io.IOException
id
. id
must be the key
provided as an argument to doRequest(weblogic.servlet.http.RequestResponseKey)
. Then
notify>
synchronously sends out the servlet response
after having called doResponse(weblogic.servlet.http.RequestResponseKey, java.lang.Object)
. Notify will pass the
context
object to doResponse(weblogic.servlet.http.RequestResponseKey, java.lang.Object)
, if provided
with one.id
- - the key used to identify the request/response that should be
sent back.context
- - object that will be passed onto doResponse(weblogic.servlet.http.RequestResponseKey, java.lang.Object)
java.io.IOException
- - if an input or output error occursprotected abstract boolean doRequest(RequestResponseKey rrk) throws java.io.IOException, javax.servlet.ServletException
rrk
- the RequestResponseKey, containing the servlet request
and responsejava.io.IOException
- - if an input or output error occursjavax.servlet.ServletException
- - if the HTTP request cannot be handledprotected abstract void doResponse(RequestResponseKey rrk, java.lang.Object context) throws java.io.IOException, javax.servlet.ServletException
doResponse
as doRequest(weblogic.servlet.http.RequestResponseKey)
. If an exception occurs during processing then the
container will arrange for the error to be sent back to the
client. The request and response streams are available in the
RequestResponseKey. This method may get invoked on a different
thread.rrk
- - the RequestResponseKey, containing the servlet request
and responsecontext
- - the context object that was passed to notify(weblogic.servlet.http.RequestResponseKey, java.lang.Object)
java.io.IOException
- - if an input or output error occursjavax.servlet.ServletException
- - if the HTTP request cannot be handledprotected abstract void doTimeout(RequestResponseKey rrk) throws java.io.IOException, javax.servlet.ServletException
notify(weblogic.servlet.http.RequestResponseKey, java.lang.Object)
is not
called within the timeout period. Implementors should override
this method. There is no guarantee that the same servlet instance
is used for processing doTimeout
as doRequest(weblogic.servlet.http.RequestResponseKey)
. The request and response streams are available in
the RequestResponseKey.rrk
- - the RequestResponseKey, containing the servlet request and responsejava.io.IOException
- - if an input or output error occursjavax.servlet.ServletException
- - if the HTTP request cannot be handledprotected void setTimeout(int period)
GenericServlet.init(javax.servlet.ServletConfig)
method. The new value applies
only to requests started after this method call. To set the
timeout for a specific servlet request, use RequestResponseKey.setTimeout(int)
period
- the timeout period in milliseconds. A timeout
period <= 0 means that requests will never be timed out.< dd>
=>public static final void setScavangeInterval(int period)
AbstractAsyncServlet
.period
- the interval period in milliseconds. A timeout
period <= 0 is illegal.< dd>
=>