tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject svn commit: r544243 - in /tomcat/sandbox/comet/java/org/apache: catalina/ catalina/connector/ coyote/ coyote/http11/ tomcat/util/net/
Date Mon, 04 Jun 2007 20:21:49 GMT
Author: remm
Date: Mon Jun  4 13:21:47 2007
New Revision: 544243

URL: http://svn.apache.org/viewvc?view=rev&rev=544243
Log:
- Further API simplification.
- isWriteable can be used as a hidden callback to place the socket in the poller for
  write events.
- Remove the configure flag.
- I don't see much point in using blocking mode in Comet, since the API usage is actually
identical.
- CometEvent.sleep will be used to disable read events (but the name is more explicit).
- As before, no full implementation at the moment.

Modified:
    tomcat/sandbox/comet/java/org/apache/catalina/CometEvent.java
    tomcat/sandbox/comet/java/org/apache/catalina/connector/CometEventImpl.java
    tomcat/sandbox/comet/java/org/apache/catalina/connector/OutputBuffer.java
    tomcat/sandbox/comet/java/org/apache/catalina/connector/Request.java
    tomcat/sandbox/comet/java/org/apache/coyote/ActionCode.java
    tomcat/sandbox/comet/java/org/apache/coyote/http11/Http11AprProcessor.java
    tomcat/sandbox/comet/java/org/apache/coyote/http11/InternalAprOutputBuffer.java
    tomcat/sandbox/comet/java/org/apache/tomcat/util/net/AprEndpoint.java

Modified: tomcat/sandbox/comet/java/org/apache/catalina/CometEvent.java
URL: http://svn.apache.org/viewvc/tomcat/sandbox/comet/java/org/apache/catalina/CometEvent.java?view=diff&rev=544243&r1=544242&r2=544243
==============================================================================
--- tomcat/sandbox/comet/java/org/apache/catalina/CometEvent.java (original)
+++ tomcat/sandbox/comet/java/org/apache/catalina/CometEvent.java Mon Jun  4 13:21:47 2007
@@ -118,7 +118,7 @@
      * @see #EventSubType
      */
     public EventSubType getEventSubType();
-    
+
     /**
      * Ends the Comet session. This signals to the container that 
      * the container wants to end the comet session. This will send back to the
@@ -129,7 +129,7 @@
      * @throws IOException if an IO exception occurs
      */
     public void close() throws IOException;
-    
+
     /**
      * 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/>
@@ -142,16 +142,17 @@
      * This method should not be called asynchronously, as that will have no effect.
      * 
      * @param timeout The timeout in milliseconds for this connection, must be a positive
value, larger than 0
-     * @throws IOException An IOException may be thrown to indicate an IO error, 
-     *         or that the EOF has been reached on the connection
      */
-    public void setTimeout(int timeout)
-        throws IOException;
+    public void setTimeout(int timeout);
 
     /**
      * Returns true if write notifications are disabled, or is they are enabled and data
may
      * be written to the connection (the flag becomes false when the client is unable to
accept
-     * data fast enough). When the flag becomes 
+     * data fast enough). When the flag becomes false, the servlet must stop writing data.
If there's
+     * an attempt to flush additional data to the client and data still cannot be written
immediately,
+     * an IOException will be thrown. If calling this method returns false, it will also

+     * request notification when the connection becomes available for writing again, and
the  
+     * servlet will recieve a write event.
      * 
      * @return boolean true if you can write to the response 
      */
@@ -167,23 +168,15 @@
     public boolean isReadable();
 
     /**
-     * Configure notifications that will be recieved. This method should be called during
the processing of
-     * the begin event. If configure is not called, the behavior will be the same as if configure(true,
false)
-     * is called.
-     * 
-     * @param read if true, read events will be sent to the servlet
-     * @param write if true, the connection will be placed in non blocking mode, and write
notifications
-     *        may be requested by using the sendNotify method
+     * Will ask the servlet container to send a notify event to the servlet, where the request
can be processed
+     * synchronously (for example, it is possible to use this to complete the request after
some asynchronous
+     * processing is done).
      */
-    public void configure(boolean read, boolean write);
+    public void callback();
 
     /**
-     * Send a notify event to the servlet.
-     * 
-     * @param write with the value true should be called when isWriteable becomes false,
to request notification
-     *        when the connection becomes available for writing again; with the value false,
a notify event 
-     *        will be sent to the servlet
+     * Delay processing of the connection until the configured timeout occurs, or callback(true)
is called.
      */
-    public void callback(boolean write);
+    public void sleep();
 
 }

Modified: tomcat/sandbox/comet/java/org/apache/catalina/connector/CometEventImpl.java
URL: http://svn.apache.org/viewvc/tomcat/sandbox/comet/java/org/apache/catalina/connector/CometEventImpl.java?view=diff&rev=544243&r1=544242&r2=544243
==============================================================================
--- tomcat/sandbox/comet/java/org/apache/catalina/connector/CometEventImpl.java (original)
+++ tomcat/sandbox/comet/java/org/apache/catalina/connector/CometEventImpl.java Mon Jun  4
13:21:47 2007
@@ -109,8 +109,7 @@
         return response.getResponse();
     }
 
-    public void setTimeout(int timeout)
-        throws IOException {
+    public void setTimeout(int timeout) {
         request.setTimeout(timeout);
     }
     
@@ -118,30 +117,35 @@
         return request.isReadable();
     }
 
+    /**
+     * Returns true if write notifications are disabled, or is they are enabled and data
may
+     * be written to the connection (the flag becomes false when the client is unable to
accept
+     * data fast enough). When the flag becomes false, the servlet must stop writing data.
If there's
+     * an attempt to flush additional data to the client and data still cannot be written
immediately,
+     * an IOException will be thrown. If calling this method returns false, it will also

+     * request notification when the connection becomes available for writing again, and
the  
+     * servlet will recieve a write event.
+     * 
+     * @return boolean true if you can write to the response 
+     */
     public boolean isWriteable() {
         return response.isWriteable();
     }
     
     /**
-     * Configure notifications that will be recieved.
-     * 
-     * @param read if true, read events will be sent to the servlet 
-     * @param write if true, the connection will be placed in non blocking mode, and write
notifications
-     *        may be requested by using the sendNotify method
+     * Will ask the servlet container to send a notify event to the servlet, where the request
can be processed
+     * synchronously (for example, it is possible to use this to complete the request after
some asynchronous
+     * processing is done).
      */
-    public void configure(boolean read, boolean write) {
-        request.configure(read, write);
+    public void callback() {
+        request.callback();
     }
 
     /**
-     * Send a notify event to the servlet.
-     * 
-     * @param write with the value true should be called when isWriteable becomes false,
to request notification
-     *        when the connection becomes available for writing again; with the value false,
a notify event 
-     *        will be sent to the servlet
+     * Delay processing of the connection until the configured timeout occurs, or callback
is called.
      */
-    public void callback(boolean write) {
-        request.callback(write);
+    public void sleep() {
+        request.sleep();
     }
 
     public String toString() {

Modified: tomcat/sandbox/comet/java/org/apache/catalina/connector/OutputBuffer.java
URL: http://svn.apache.org/viewvc/tomcat/sandbox/comet/java/org/apache/catalina/connector/OutputBuffer.java?view=diff&rev=544243&r1=544242&r2=544243
==============================================================================
--- tomcat/sandbox/comet/java/org/apache/catalina/connector/OutputBuffer.java (original)
+++ tomcat/sandbox/comet/java/org/apache/catalina/connector/OutputBuffer.java Mon Jun  4 13:21:47
2007
@@ -328,7 +328,12 @@
      * Return the amount of bytes written by the lower layer.
      */
     protected int lastWrite() {
-        return coyoteResponse.getLastWrite();
+        int res = coyoteResponse.getLastWrite();
+        if (res == 0) {
+            // FIXME: For efficiency, it would be nice to check if not calling it twice,
and reset than when that is done
+            coyoteResponse.action(ActionCode.ACTION_COMET_WRITE, null);
+        }
+        return res;
     }
     
 

Modified: tomcat/sandbox/comet/java/org/apache/catalina/connector/Request.java
URL: http://svn.apache.org/viewvc/tomcat/sandbox/comet/java/org/apache/catalina/connector/Request.java?view=diff&rev=544243&r1=544242&r2=544243
==============================================================================
--- tomcat/sandbox/comet/java/org/apache/catalina/connector/Request.java (original)
+++ tomcat/sandbox/comet/java/org/apache/catalina/connector/Request.java Mon Jun  4 13:21:47
2007
@@ -2266,26 +2266,20 @@
     
     
     /**
-     * Configure notifications that will be recieved.
-     * 
-     * @param read if true, read events will be sent to the servlet 
-     * @param write if true, the connection will be placed in non blocking mode, and write
notifications
-     *        may be requested by using the sendNotify method
+     * Will ask the servlet container to send a notify event to the servlet, where the request
can be processed
+     * synchronously (for example, it is possible to use this to complete the request after
some asynchronous
+     * processing is done).
      */
-    public void configure(boolean read, boolean write) {
-        coyoteRequest.action(ActionCode.ACTION_COMET_READ_NOTIFICATIONS, Boolean.valueOf(read));
-        coyoteRequest.action(ActionCode.ACTION_COMET_WRITE_NOTIFICATIONS, Boolean.valueOf(write));
+    public void callback() {
+        coyoteRequest.action(ActionCode.ACTION_COMET_CALLBACK, null);
     }
-
+    
+    
     /**
-     * Send a notify event to the servlet.
-     * 
-     * @param write with the value true should be called when isWriteable becomes false,
to request notification
-     *        when the connection becomes available for writing again; with the value false,
a notify event 
-     *        will be sent to the servlet
+     * Delay processing of the connection until the configured timeout occurs, or callback
is called.
      */
-    public void callback(boolean write) {
-        coyoteRequest.action(ActionCode.ACTION_COMET_CALLBACK, Boolean.valueOf(write));
+    public void sleep() {
+        coyoteRequest.action(ActionCode.ACTION_COMET_SLEEP, null);
     }
     
     

Modified: tomcat/sandbox/comet/java/org/apache/coyote/ActionCode.java
URL: http://svn.apache.org/viewvc/tomcat/sandbox/comet/java/org/apache/coyote/ActionCode.java?view=diff&rev=544243&r1=544242&r2=544243
==============================================================================
--- tomcat/sandbox/comet/java/org/apache/coyote/ActionCode.java (original)
+++ tomcat/sandbox/comet/java/org/apache/coyote/ActionCode.java Mon Jun  4 13:21:47 2007
@@ -157,21 +157,20 @@
     public static final ActionCode ACTION_COMET_TIMEOUT = new ActionCode(24);
     
     /**
-     * Configure a Comet connection
+     * Ask for a callback
      */
     public static final ActionCode ACTION_COMET_CALLBACK = new ActionCode(25);
     
     /**
-     * Register notifications for read events
+     * Put this request to sleep (no read notifications)
      */
-    public static final ActionCode ACTION_COMET_READ_NOTIFICATIONS = new ActionCode(26);
+    public static final ActionCode ACTION_COMET_SLEEP = new ActionCode(26);
     
     /**
-     * Register notifications for write events
+     * Ask for a write callback
      */
-    public static final ActionCode ACTION_COMET_WRITE_NOTIFICATIONS = new ActionCode(27);
+    public static final ActionCode ACTION_COMET_WRITE = new ActionCode(27);
     
-
     // ----------------------------------------------------------- Constructors
     int code;
 

Modified: tomcat/sandbox/comet/java/org/apache/coyote/http11/Http11AprProcessor.java
URL: http://svn.apache.org/viewvc/tomcat/sandbox/comet/java/org/apache/coyote/http11/Http11AprProcessor.java?view=diff&rev=544243&r1=544242&r2=544243
==============================================================================
--- tomcat/sandbox/comet/java/org/apache/coyote/http11/Http11AprProcessor.java (original)
+++ tomcat/sandbox/comet/java/org/apache/coyote/http11/Http11AprProcessor.java Mon Jun  4
13:21:47 2007
@@ -320,7 +320,7 @@
     
     protected int cometTimeout = -1;
     protected boolean readNotifications = true;
-    protected boolean writeNotifications = false;
+    protected boolean nonBlocking = true;
     
 
     // ------------------------------------------------------------- Properties
@@ -331,8 +331,8 @@
     }
     
 
-    public boolean getWriteNotifications() {
-        return readNotifications;
+    public boolean getNonBlocking() {
+        return nonBlocking;
     }
     
 
@@ -1219,13 +1219,12 @@
             comet = true;
         } else if (actionCode == ActionCode.ACTION_COMET_END) {
             comet = false;
-        } else if (actionCode == ActionCode.ACTION_COMET_READ_NOTIFICATIONS) {
-            readNotifications = ((Boolean) param).booleanValue();
-        } else if (actionCode == ActionCode.ACTION_COMET_WRITE_NOTIFICATIONS) {
-            writeNotifications = ((Boolean) param).booleanValue();
-            // FIXME: If true, should switch to non blocking mode for the socket
+        } else if (actionCode == ActionCode.ACTION_COMET_SLEEP) {
+            readNotifications = false;
         } else if (actionCode == ActionCode.ACTION_COMET_CALLBACK) {
-            endpoint.getCometPoller().add(socket, timeout, false, ((Boolean) param).booleanValue());
+            endpoint.getCometPoller().add(socket, timeout, false, false);
+        } else if (actionCode == ActionCode.ACTION_COMET_WRITE) {
+            endpoint.getCometPoller().add(socket, timeout, false, true);
         } else if (actionCode == ActionCode.ACTION_COMET_TIMEOUT) {
             cometTimeout = ((Integer) param).intValue();
         }

Modified: tomcat/sandbox/comet/java/org/apache/coyote/http11/InternalAprOutputBuffer.java
URL: http://svn.apache.org/viewvc/tomcat/sandbox/comet/java/org/apache/coyote/http11/InternalAprOutputBuffer.java?view=diff&rev=544243&r1=544242&r2=544243
==============================================================================
--- tomcat/sandbox/comet/java/org/apache/coyote/http11/InternalAprOutputBuffer.java (original)
+++ tomcat/sandbox/comet/java/org/apache/coyote/http11/InternalAprOutputBuffer.java Mon Jun
 4 13:21:47 2007
@@ -171,6 +171,12 @@
     protected ByteBuffer bbuf = null;
 
     
+    /**
+     * Leftover bytes which could not be written during a non blocking write. 
+     */
+    protected ByteChunk leftover = null;
+
+
     // ------------------------------------------------------------- Properties
 
 
@@ -688,7 +694,12 @@
     protected void flushBuffer()
         throws IOException {
         if (bbuf.position() > 0) {
-            if (Socket.sendbb(socket, 0, bbuf.position()) < 0) {
+            int res = Socket.sendbb(socket, 0, bbuf.position());
+            response.setLastWrite(res);
+            // FIXME: If in Comet mode and non blocking, and if it did not write the whole
thing,
+            // then retry until it writes 0 bytes (?), and put the leftover bytes in the
leftover
+            // byte chunk
+            if (res < 0) {
                 throw new IOException();
             }
             bbuf.clear();

Modified: tomcat/sandbox/comet/java/org/apache/tomcat/util/net/AprEndpoint.java
URL: http://svn.apache.org/viewvc/tomcat/sandbox/comet/java/org/apache/tomcat/util/net/AprEndpoint.java?view=diff&rev=544243&r1=544242&r2=544243
==============================================================================
--- tomcat/sandbox/comet/java/org/apache/tomcat/util/net/AprEndpoint.java (original)
+++ tomcat/sandbox/comet/java/org/apache/tomcat/util/net/AprEndpoint.java Mon Jun  4 13:21:47
2007
@@ -1335,6 +1335,7 @@
                         keepAliveCount -= rv;
                         for (int n = 0; n < rv; n++) {
                             // Check for failed sockets and hand this socket off to a worker
+                            System.out.println("Desc: " + desc[n*2]);
                             if (((desc[n*2] & Poll.APR_POLLHUP) == Poll.APR_POLLHUP)
                                     || ((desc[n*2] & Poll.APR_POLLERR) == Poll.APR_POLLERR)
                                     || (comet && (!processSocket(desc[n*2+1], SocketStatus.OPEN_READ)))




---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Mime
View raw message