Add optional comet timeout support
authorfhanik <fhanik@13f79535-47bb-0310-9956-ffa450edef68>
Thu, 13 Jul 2006 15:12:56 +0000 (15:12 +0000)
committerfhanik <fhanik@13f79535-47bb-0310-9956-ffa450edef68>
Thu, 13 Jul 2006 15:12:56 +0000 (15:12 +0000)
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
java/org/apache/catalina/servlets/CometServlet.java

index 743889d..aac7fb4 100644 (file)
@@ -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.<br/>
+     * 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 <code>response.flushBuffer()</code>. If a timeout occurs, the 
+     * <code>error(HttpServletRequest, HttpServletResponse)</code> method is invoked. The 
+     * web application SHOULD NOT attempt to reuse the request and response objects after a timeout
+     * as the <code>error(HttpServletRequest, HttpServletResponse)</code> method indicates.<br/>
+     * 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;
 
 }
index 8cfa862..ff21e15 100644 (file)
@@ -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();
+        }
+    }
+
 
 }