From 02193ce0805dff9eac81728298f84c94b7d2212d Mon Sep 17 00:00:00 2001 From: fhanik Date: Thu, 13 Jul 2006 15:12:56 +0000 Subject: [PATCH] Add optional comet timeout support git-svn-id: https://svn.apache.org/repos/asf/tomcat/tc6.0.x/trunk@421645 13f79535-47bb-0310-9956-ffa450edef68 --- java/org/apache/catalina/CometProcessor.java | 25 +++++++++++++++++++++- .../org/apache/catalina/servlets/CometServlet.java | 11 +++++++++- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/java/org/apache/catalina/CometProcessor.java b/java/org/apache/catalina/CometProcessor.java index 743889d93..aac7fb4a1 100644 --- a/java/org/apache/catalina/CometProcessor.java +++ b/java/org/apache/catalina/CometProcessor.java @@ -88,7 +88,7 @@ public interface CometProcessor { * Reader may be used to determine if there is a risk of blocking: the servlet * should read while data is reported available, and can make one additional read * without blocking. When encountering a read error or an EOF, the servlet MUST - * report it by either returning null or throwing an exception such as an + * report it by either returning false or throwing an exception such as an * IOException. This will cause the error method to be invoked, and the connection * will be closed. It is not allowed to attempt reading data from the request object * outside of the execution of this method. @@ -104,5 +104,28 @@ public interface CometProcessor { */ public boolean read(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException; + + /** + * Sets the timeout for this Comet connection. Please NOTE, that the implementation + * of a per connection timeout is OPTIONAL and MAY NOT be implemented.
+ * This method sets the timeout in milliseconds of idle time on the connection. + * The timeout is reset every time data is received from the connection or data is flushed + * using response.flushBuffer(). If a timeout occurs, the + * error(HttpServletRequest, HttpServletResponse) method is invoked. The + * web application SHOULD NOT attempt to reuse the request and response objects after a timeout + * as the error(HttpServletRequest, HttpServletResponse) method indicates.
+ * This method should not be called asynchronously, as that will have no effect. + * @param request The HTTP servlet request instance + * @param response The HTTP servlet response instance + * @param timeout The timeout in milliseconds for this connection + * @throws IOException An IOException may be thrown to indicate an IO error, + * or that the EOF has been reached on the connection + * @throws ServletException An exception has occurred, as specified by the root + * cause + * @throws UnsupportedOperationException if per connection timeout is not supported, either at all or at this phase + * of the invocation. + */ + public void setTimeout(HttpServletRequest request, HttpServletResponse response, int timeout) + throws IOException, ServletException, UnsupportedOperationException; } diff --git a/java/org/apache/catalina/servlets/CometServlet.java b/java/org/apache/catalina/servlets/CometServlet.java index 8cfa862d3..ff21e158f 100644 --- a/java/org/apache/catalina/servlets/CometServlet.java +++ b/java/org/apache/catalina/servlets/CometServlet.java @@ -86,7 +86,16 @@ public abstract class CometServlet } } } - } + + public void setTimeout(HttpServletRequest request, HttpServletResponse response, int timeout) + throws IOException, ServletException, UnsupportedOperationException { + if (request.getAttribute("org.apache.tomcat.comet.timeout.support") == Boolean.TRUE) { + request.setAttribute("org.apache.tomcat.comet.timeout",new Integer(timeout)); + } else { + throw new UnsupportedOperationException(); + } + } + } -- 2.11.0