tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1137059 - in /tomcat/trunk/java/org/apache: coyote/ajp/AjpNioProtocol.java coyote/http11/Http11NioProtocol.java tomcat/util/net/NioEndpoint.java
Date Fri, 17 Jun 2011 22:37:53 GMT
Author: markt
Date: Fri Jun 17 22:37:53 2011
New Revision: 1137059

URL: http://svn.apache.org/viewvc?rev=1137059&view=rev
Log:
Connector re-factoring
Broadly align NIO Handler.process with BIO Handler.process
Remove event() method from NIO handler

Modified:
    tomcat/trunk/java/org/apache/coyote/ajp/AjpNioProtocol.java
    tomcat/trunk/java/org/apache/coyote/http11/Http11NioProtocol.java
    tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java

Modified: tomcat/trunk/java/org/apache/coyote/ajp/AjpNioProtocol.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/ajp/AjpNioProtocol.java?rev=1137059&r1=1137058&r2=1137059&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/ajp/AjpNioProtocol.java (original)
+++ tomcat/trunk/java/org/apache/coyote/ajp/AjpNioProtocol.java Fri Jun 17 22:37:53 2011
@@ -165,50 +165,13 @@ public class AjpNioProtocol extends Abst
             recycledProcessors.offer(processor);
         }
 
-        // FIXME: Support for Comet could be added in AJP as well
-        @Override
-        public SocketState event(NioChannel socket, SocketStatus status) {
-            AjpNioProcessor processor = connections.get(socket);
-            NioEndpoint.KeyAttachment att = (NioEndpoint.KeyAttachment)socket.getAttachment(false);
-            att.setAsync(false); //no longer check for timeout
-            SocketState state = SocketState.CLOSED; 
-            if (processor != null) {
-                try {
-                    state = processor.asyncDispatch(status);
-                }
-                // Future developers: if you discover any other
-                // rare-but-nonfatal exceptions, catch them here, and log as
-                // above.
-                catch (Throwable e) {
-                    ExceptionUtils.handleThrowable(e);
-                    // any other exception or error is odd. Here we log it
-                    // with "ERROR" level, so it will show up even on
-                    // less-than-verbose logs.
-                    AjpNioProtocol.log.error
-                        (sm.getString("ajpprotocol.proto.error"), e);
-                } finally {
-                    if (processor.isAsync()) {
-                        state = processor.asyncPostProcess();
-                    }
-                    if (state == SocketState.OPEN || state == SocketState.CLOSED) {
-                        release(socket, processor);
-                        if (state == SocketState.OPEN) {
-                            socket.getPoller().add(socket);
-                        }
-                    } else if (state == SocketState.LONG) {
-                        att.setAsync(true); // Re-enable timeouts
-                    } else {
-                        // state == SocketState.ASYNC_END
-                        // No further work required
-                    }
-                }
-            }
-            return state;
-        }
-        
         @Override
         public SocketState process(NioChannel socket, SocketStatus status) {
             AjpNioProcessor processor = connections.remove(socket);
+
+            NioEndpoint.KeyAttachment att = (NioEndpoint.KeyAttachment)socket.getAttachment(false);
+            att.setAsync(false); //no longer check for timeout
+
             try {
                 if (processor == null) {
                     processor = recycledProcessors.poll();
@@ -217,20 +180,25 @@ public class AjpNioProtocol extends Abst
                     processor = createProcessor();
                 }
 
-                SocketState state = processor.process(socket);
+                SocketState state = SocketState.CLOSED;
+                do {
+                    if (processor.isAsync() || state == SocketState.ASYNC_END) {
+                        state = processor.asyncDispatch(status);
+                    } else {
+                        state = processor.process(socket);
+                    }
+
+                    if (processor.isAsync()) {
+                        state = processor.asyncPostProcess();
+                    }
+                } while (state == SocketState.ASYNC_END);
+
                 if (state == SocketState.LONG) {
                     // In the middle of processing a request/response. Keep the
                     // socket associated with the processor.
                     connections.put(socket, processor);
                     
-                    NioEndpoint.KeyAttachment att = (NioEndpoint.KeyAttachment)socket.getAttachment(false);
                     att.setAsync(true);
-                    // longPoll may change socket state (e.g. to trigger a
-                    // complete or dispatch)
-                    state = processor.asyncPostProcess();
-                }
-                if (state == SocketState.LONG || state == SocketState.ASYNC_END) {
-                    // Already done all we need to do.
                 } else if (state == SocketState.OPEN){
                     // In keep-alive but between requests. OK to recycle
                     // processor. Continue to poll for the next request.

Modified: tomcat/trunk/java/org/apache/coyote/http11/Http11NioProtocol.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/Http11NioProtocol.java?rev=1137059&r1=1137058&r2=1137059&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http11/Http11NioProtocol.java (original)
+++ tomcat/trunk/java/org/apache/coyote/http11/Http11NioProtocol.java Fri Jun 17 22:37:53
2011
@@ -228,73 +228,12 @@ public class Http11NioProtocol extends A
 
 
         @Override
-        public SocketState event(NioChannel socket, SocketStatus status) {
-            Http11NioProcessor processor = connections.get(socket);
+        public SocketState process(NioChannel socket, SocketStatus status) {
+            Http11NioProcessor processor = connections.remove(socket);
+
             NioEndpoint.KeyAttachment att = (NioEndpoint.KeyAttachment)socket.getAttachment(false);
             att.setAsync(false); //no longer check for timeout
-            SocketState state = SocketState.CLOSED; 
-            if (processor != null) {
-                if (log.isDebugEnabled()) log.debug("Http11NioProcessor.error="+processor.error);
-                // Call the appropriate event
-                try {
-                    if (processor.comet) {
-                        state = processor.event(status);
-                    } else {
-                        state = processor.asyncDispatch(status);
-                    }
-                } catch (java.net.SocketException e) {
-                    // SocketExceptions are normal
-                    Http11NioProtocol.log.debug
-                        (sm.getString
-                            ("http11protocol.proto.socketexception.debug"), e);
-                } catch (java.io.IOException e) {
-                    // IOExceptions are normal
-                    Http11NioProtocol.log.debug
-                        (sm.getString
-                            ("http11protocol.proto.ioexception.debug"), e);
-                }
-                // Future developers: if you discover any other
-                // rare-but-nonfatal exceptions, catch them here, and log as
-                // above.
-                catch (Throwable e) {
-                    ExceptionUtils.handleThrowable(e);
-                    // any other exception or error is odd. Here we log it
-                    // with "ERROR" level, so it will show up even on
-                    // less-than-verbose logs.
-                    Http11NioProtocol.log.error
-                        (sm.getString("http11protocol.proto.error"), e);
-                } finally {
-                    if (processor.isAsync()) {
-                        state = processor.asyncPostProcess();
-                    }
-                    if (state == SocketState.OPEN || state == SocketState.CLOSED) {
-                        release(socket, processor);
-                        if (state == SocketState.OPEN) {
-                            socket.getPoller().add(socket);
-                        }
-                    } else if (state == SocketState.LONG) {
-                        if (processor.isAsync()) {
-                            att.setAsync(true); // Re-enable timeouts
-                        } else {
-                            // Comet
-                            if (log.isDebugEnabled()) log.debug("Keeping processor["+processor);
-                            // May receive more data from client
-                            SelectionKey key = socket.getIOChannel().keyFor(socket.getPoller().getSelector());
-                            key.interestOps(SelectionKey.OP_READ);
-                            att.interestOps(SelectionKey.OP_READ);
-                        }
-                    } else {
-                        // state == SocketState.ASYNC_END
-                        // No further work required
-                    }
-                }
-            }
-            return state;
-        }
 
-        @Override
-        public SocketState process(NioChannel socket, SocketStatus status) {
-            Http11NioProcessor processor = connections.remove(socket);
             try {
                 if (processor == null) {
                     processor = recycledProcessors.poll();
@@ -314,18 +253,28 @@ public class Http11NioProtocol extends A
                     processor.setSslSupport(null);
                 }
 
-                SocketState state = processor.process(socket);
+                SocketState state = SocketState.CLOSED;
+                do {
+                    if (processor.isAsync() || state == SocketState.ASYNC_END) {
+                        state = processor.asyncDispatch(status);
+                    } else if (processor.comet) {
+                        state = processor.event(status);
+                    } else {
+                        state = processor.process(socket);
+                    }
+
+                    if (processor.isAsync()) {
+                        state = processor.asyncPostProcess();
+                    }
+                } while (state == SocketState.ASYNC_END);
+
                 if (state == SocketState.LONG) {
                     // In the middle of processing a request/response. Keep the
                     // socket associated with the processor.
                     connections.put(socket, processor);
                     
                     if (processor.isAsync()) {
-                        NioEndpoint.KeyAttachment att = (NioEndpoint.KeyAttachment)socket.getAttachment(false);
                         att.setAsync(true);
-                        // longPoll may change socket state (e.g. to trigger a
-                        // complete or dispatch)
-                        state = processor.asyncPostProcess();
                     } else {
                         // Either:
                         //  - this is comet request
@@ -333,14 +282,9 @@ public class Http11NioProtocol extends A
                         //    read
                         SelectionKey key = socket.getIOChannel().keyFor(
                                 socket.getPoller().getSelector());
-                        NioEndpoint.KeyAttachment att =
-                            (NioEndpoint.KeyAttachment)socket.getAttachment(false);
                         key.interestOps(SelectionKey.OP_READ);
                         att.interestOps(SelectionKey.OP_READ);
                     }
-                }
-                if (state == SocketState.LONG || state == SocketState.ASYNC_END) {
-                    // Already done all we need to do.
                 } else if (state == SocketState.OPEN){
                     // In keep-alive but between requests. OK to recycle
                     // processor. Continue to poll for the next request.

Modified: tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java?rev=1137059&r1=1137058&r2=1137059&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java Fri Jun 17 22:37:53 2011
@@ -1483,7 +1483,6 @@ public class NioEndpoint extends Abstrac
      */
     public interface Handler extends AbstractEndpoint.Handler {
         public SocketState process(NioChannel socket, SocketStatus status);
-        public SocketState event(NioChannel socket, SocketStatus status);
         public void release(NioChannel socket);
         public void release(SocketChannel socket);
         public SSLImplementation getSslImplementation();
@@ -1532,7 +1531,7 @@ public class NioEndpoint extends Abstrac
                         if (status == null) {
                             state = handler.process(socket, SocketStatus.OPEN);
                         } else {
-                            state = handler.event(socket, status);
+                            state = handler.process(socket, status);
                         }
     
                         if (state == SocketState.CLOSED) {
@@ -1551,8 +1550,6 @@ public class NioEndpoint extends Abstrac
                             }catch ( Exception x ) {
                                 log.error("",x);
                             }
-                        } else if (state == SocketState.ASYNC_END) {
-                            launch = true;
                         }
                     } else if (handshake == -1 ) {
                         KeyAttachment ka = null;



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


Mime
View raw message