Oracle Fusion Middleware
Oracle WebLogic Server API Reference
11g Release 1 (10.3.3)

Part Number E13941-03

weblogic.servlet.http
Class AbstractAsyncServlet

java.lang.Object
  extended by HttpServlet
      extended by weblogic.servlet.http.AbstractAsyncServlet
All Implemented Interfaces:
FutureResponseModel

public abstract class AbstractAsyncServlet
extends HttpServlet
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 AbstractAsyncServlet.notify(weblogic.servlet.http.RequestResponseKey, java.lang.Object) function. The servlet does not consume any threads while waiting for AbstractAsyncServlet.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 AbstractAsyncServlet.setTimeout(int) and AbstractAsyncServlet.setScavangeInterval(int). The scavange interval is global to all AbstractAsyncServlets. The timeout period is per-servlet instance. If a timeout occurs then the AbstractAsyncServlet.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 AbstractAsyncServlets, will not be able to take advantage of post processing of the response.


Field Summary
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.
 
Constructor Summary
AbstractAsyncServlet()
           
 
Method Summary
protected abstract  boolean doRequest(RequestResponseKey rrk)
          Process the servlet request.
protected abstract  void doResponse(RequestResponseKey rrk, Object context)
          Process the servlet response.
protected abstract  void doTimeout(RequestResponseKey rrk)
          Send back a servlet response error when AbstractAsyncServlet.notify(weblogic.servlet.http.RequestResponseKey, java.lang.Object) is not called within the timeout period.
static void notify(RequestResponseKey id, Object context)
          notify the servlet implementation that a response should be sent for the key id.
protected  void service(HttpServletRequest req, HttpServletResponse rsp)
          Implementation of the standard HttpServlet 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_TIMEOUT

public static final int DEFAULT_TIMEOUT
The default request timeout period in milliseconds.

See Also:
Constant Field Values

DEFAULT_SCAVANGE_INTERVAL

public static final int DEFAULT_SCAVANGE_INTERVAL
The default interval period in milliseconds at which requests will be checked for timeouts.

See Also:
Constant Field Values
Constructor Detail

AbstractAsyncServlet

public AbstractAsyncServlet()
Method Detail

service

protected final void service(HttpServletRequest req,
                             HttpServletResponse rsp)
                      throws IOException,
                             ServletException
Implementation of the standard HttpServlet method. This method cannot be overridden, implementors should instead override AbstractAsyncServlet.doRequest(weblogic.servlet.http.RequestResponseKey) and AbstractAsyncServlet.doResponse(weblogic.servlet.http.RequestResponseKey, java.lang.Object).

Throws:
IOException
ServletException

notify

public static final void notify(RequestResponseKey id,
                                Object context)
                         throws IOException
notify the servlet implementation that a response should be sent for the key id. id must be the key provided as an argument to AbstractAsyncServlet.doRequest(weblogic.servlet.http.RequestResponseKey). Then notify> synchronously sends out the servlet response after having called AbstractAsyncServlet.doResponse(weblogic.servlet.http.RequestResponseKey, java.lang.Object). Notify will pass the context object to AbstractAsyncServlet.doResponse(weblogic.servlet.http.RequestResponseKey, java.lang.Object), if provided with one.

Parameters:
id - - the key used to identify the request/response that should be sent back.
context - - object that will be passed onto AbstractAsyncServlet.doResponse(weblogic.servlet.http.RequestResponseKey, java.lang.Object)
Throws:
IOException - - if an input or output error occurs

doRequest

protected abstract boolean doRequest(RequestResponseKey rrk)
                              throws IOException,
                                     ServletException
Process the servlet request. Implementors should override this method. If a future response is to be handled, this method should return true. If a response needs to be sent immediately, this method should return false. The request and response streams are available in the RequestResponseKey.

Parameters:
rrk - the RequestResponseKey, containing the servlet request and response
Returns:
true if the response will be handled in the future.
Throws:
IOException - - if an input or output error occurs
ServletException - - if the HTTP request cannot be handled

doResponse

protected abstract void doResponse(RequestResponseKey rrk,
                                   Object context)
                            throws IOException,
                                   ServletException
Process the servlet response. Implementors should override this method. There is no guarantee that the same servlet instance is used for processing doResponse as AbstractAsyncServlet.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.

Parameters:
rrk - - the RequestResponseKey, containing the servlet request and response
context - - the context object that was passed to AbstractAsyncServlet.notify(weblogic.servlet.http.RequestResponseKey, java.lang.Object)
Throws:
IOException - - if an input or output error occurs
ServletException - - if the HTTP request cannot be handled

doTimeout

protected abstract void doTimeout(RequestResponseKey rrk)
                           throws IOException,
                                  ServletException
Send back a servlet response error when AbstractAsyncServlet.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 AbstractAsyncServlet.doRequest(weblogic.servlet.http.RequestResponseKey). The request and response streams are available in the RequestResponseKey.

Parameters:
rrk - - the RequestResponseKey, containing the servlet request and response
Throws:
IOException - - if an input or output error occurs
ServletException - - if the HTTP request cannot be handled

setTimeout

protected void setTimeout(int period)
Sets the request timeout period in milliseconds for this servlet. This method should typically be called from the GenericServlet 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)

Parameters:
period - the timeout period in milliseconds. A timeout period <= 0 means that requests will never be timed out.

setScavangeInterval

public static final void setScavangeInterval(int period)
Sets the interval period in milliseconds at which requests will be checked for timeouts. This setting affects all implementations of AbstractAsyncServlet.

Parameters:
period - the interval period in milliseconds. A timeout period <= 0 is illegal.

Copyright 1996, 2010, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners.

Oracle Fusion Middleware
Oracle WebLogic Server 10.3.3 API Reference
11g Release 1 (10.3.3)

Part Number E13941-03