You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2011/06/18 15:41:17 UTC

svn commit: r1137184 - in /tomcat/trunk/java/org/apache: coyote/ajp/AjpAprProtocol.java coyote/http11/Http11AprProtocol.java tomcat/util/net/AprEndpoint.java

Author: markt
Date: Sat Jun 18 13:41:17 2011
New Revision: 1137184

URL: http://svn.apache.org/viewvc?rev=1137184&view=rev
Log:
Connector re-factoring
Align APR with BIO/NIO

Modified:
    tomcat/trunk/java/org/apache/coyote/ajp/AjpAprProtocol.java
    tomcat/trunk/java/org/apache/coyote/http11/Http11AprProtocol.java
    tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java

Modified: tomcat/trunk/java/org/apache/coyote/ajp/AjpAprProtocol.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/ajp/AjpAprProtocol.java?rev=1137184&r1=1137183&r2=1137184&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/ajp/AjpAprProtocol.java (original)
+++ tomcat/trunk/java/org/apache/coyote/ajp/AjpAprProtocol.java Sat Jun 18 13:41:17 2011
@@ -129,31 +129,46 @@ public class AjpAprProtocol extends Abst
             recycledProcessors.clear();
         }
         
-        // FIXME: Support for this could be added in AJP as well
-        @Override
-        public SocketState event(SocketWrapper<Long> socket, SocketStatus status) {
-            return SocketState.CLOSED;
-        }
-        
         @Override
         public SocketState process(SocketWrapper<Long> socket,
                 SocketStatus status) {
-            AjpAprProcessor processor = recycledProcessors.poll();
+            AjpAprProcessor processor = connections.remove(socket);
+
+            socket.setAsync(false);
+
             try {
                 if (processor == null) {
+                    processor = recycledProcessors.poll();
+                }
+                if (processor == null) {
                     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) {
-                    // Check if the post processing is going to change the state
-                    state = processor.asyncPostProcess();
-                }
-                if (state == SocketState.LONG || state == SocketState.ASYNC_END) {
                     // Need to make socket available for next processing cycle
                     // but no need for the poller
                     connections.put(socket, processor);
                     socket.setAsync(true);
+                } else if (state == SocketState.OPEN){
+                    // In keep-alive but between requests. OK to recycle
+                    // processor. Continue to poll for the next request.
+                    processor.recycle();
+                    recycledProcessors.offer(processor);
+                    ((AprEndpoint)proto.endpoint).getPoller().add(
+                            socket.getSocket().longValue());
                 } else {
                     processor.recycle();
                     recycledProcessors.offer(processor);
@@ -184,44 +199,6 @@ public class AjpAprProtocol extends Abst
             return SocketState.CLOSED;
         }
 
-        @Override
-        public SocketState asyncDispatch(SocketWrapper<Long> socket, SocketStatus status) {
-
-            AjpAprProcessor processor = connections.get(socket);
-            
-            SocketState state = SocketState.CLOSED; 
-            if (processor != null) {
-                // Call the appropriate event
-                try {
-                    state = processor.asyncDispatch(status);
-                }
-                // Future developers: if you discover any other
-                // rare-but-nonfatal exceptions, catch them here, and log as
-                // debug.
-                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.
-                    AjpAprProtocol.log.error
-                        (sm.getString("ajpprotocol.proto.error"), e);
-                } finally {
-                    if (state == SocketState.LONG && processor.isAsync()) {
-                        state = processor.asyncPostProcess();
-                    }
-                    if (state != SocketState.LONG && state != SocketState.ASYNC_END) {
-                        connections.remove(socket);
-                        processor.recycle();
-                        recycledProcessors.offer(processor);
-                        if (state == SocketState.OPEN) {
-                            ((AprEndpoint)proto.endpoint).getPoller().add(socket.getSocket().longValue());
-                        }
-                    }
-                }
-            }
-            return state;
-        }
-        
         protected AjpAprProcessor createProcessor() {
             AjpAprProcessor processor = new AjpAprProcessor(proto.packetSize, (AprEndpoint)proto.endpoint);
             processor.setAdapter(proto.adapter);

Modified: tomcat/trunk/java/org/apache/coyote/http11/Http11AprProtocol.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/Http11AprProtocol.java?rev=1137184&r1=1137183&r2=1137184&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http11/Http11AprProtocol.java (original)
+++ tomcat/trunk/java/org/apache/coyote/http11/Http11AprProtocol.java Sat Jun 18 13:41:17 2011
@@ -212,82 +212,56 @@ public class Http11AprProtocol extends A
         }
         
         @Override
-        public SocketState event(SocketWrapper<Long> socket, SocketStatus status) {
-            Http11AprProcessor processor = connections.get(socket.getSocket());
-            
-            SocketState state = SocketState.CLOSED; 
-            if (processor != null) {
-                if (processor.comet) {
-                    // Call the appropriate event
-                    try {
-                        state = processor.event(status);
-                    } catch (java.net.SocketException e) {
-                        // SocketExceptions are normal
-                        Http11AprProtocol.log.debug(sm.getString(
-                                "http11protocol.proto.socketexception.debug"),
-                                e);
-                    } catch (java.io.IOException e) {
-                        // IOExceptions are normal
-                        Http11AprProtocol.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.
-                        Http11AprProtocol.log.error(sm.getString(
-                                "http11protocol.proto.error"), e);
-                    } finally {
-                        if (state != SocketState.LONG) {
-                            connections.remove(socket.getSocket());
-                            socket.setAsync(false);
-                            processor.recycle();
-                            recycledProcessors.offer(processor);
-                            if (state == SocketState.OPEN) {
-                                ((AprEndpoint)proto.endpoint).getPoller().add(socket.getSocket().longValue());
-                            }
-                        } else {
-                            ((AprEndpoint)proto.endpoint).getCometPoller().add(socket.getSocket().longValue());
-                        }
-                    }
-                } else if (processor.isAsync()) {
-                    state = asyncDispatch(socket, status);
-                }
-            }
-            return state;
-        }
-        
-        @Override
         public SocketState process(SocketWrapper<Long> socket,
                 SocketStatus status) {
-            Http11AprProcessor processor = recycledProcessors.poll();
+            Http11AprProcessor processor =
+                connections.remove(socket.getSocket());
+            
+            socket.setAsync(false);
+
             try {
                 if (processor == null) {
+                    processor = recycledProcessors.poll();
+                }
+                if (processor == null) {
                     processor = createProcessor();
                 }
 
-                SocketState state = processor.process(socket);
-                if (state == SocketState.LONG) {
+                SocketState state = SocketState.CLOSED;
+                do {
+                    if (processor.isAsync() || state == SocketState.ASYNC_END) {
+                        state = processor.asyncDispatch(socket, status);
+                    } else if (processor.comet) {
+                        state = processor.event(status);
+                    } else {
+                        state = processor.process(socket);
+                    }
+
                     if (processor.isAsync()) {
-                        // Check if the post processing is going to change the state
                         state = processor.asyncPostProcess();
                     }
-                }
-                if (state == SocketState.LONG || state == SocketState.ASYNC_END) {
-                    // Need to make socket available for next processing cycle
-                    // but no need for the poller
+                } 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.getSocket(), processor);
+
                     if (processor.isAsync()) {
                         socket.setAsync(true);
                     } else if (processor.comet) {
                         ((AprEndpoint) proto.endpoint).getCometPoller().add(
                                 socket.getSocket().longValue());
                     }
+                } else if (state == SocketState.OPEN){
+                    // In keep-alive but between requests. OK to recycle
+                    // processor. Continue to poll for the next request.
+                    processor.recycle();
+                    recycledProcessors.offer(processor);
+                    ((AprEndpoint)proto.endpoint).getPoller().add(
+                            socket.getSocket().longValue());
                 } else {
+                    // Connection closed. OK to recycle the processor.
                     processor.recycle();
                     recycledProcessors.offer(processor);
                 }
@@ -318,43 +292,6 @@ public class Http11AprProtocol extends A
             return SocketState.CLOSED;
         }
 
-        @Override
-        public SocketState asyncDispatch(SocketWrapper<Long> socket, SocketStatus status) {
-            Http11AprProcessor processor = connections.get(socket.getSocket());
-            
-            SocketState state = SocketState.CLOSED; 
-            if (processor != null) {
-                // Call the appropriate event
-                try {
-                    state = processor.asyncDispatch(socket, status);
-                // Future developers: if you discover any rare-but-nonfatal
-                // exceptions, catch them here, and log as per {@link #event()}
-                // 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.
-                    Http11AprProtocol.log.error
-                        (sm.getString("http11protocol.proto.error"), e);
-                } finally {
-                    if (state == SocketState.LONG && processor.isAsync()) {
-                        state = processor.asyncPostProcess();
-                    }
-                    if (state != SocketState.LONG && state != SocketState.ASYNC_END) {
-                        connections.remove(socket.getSocket());
-                        socket.setAsync(false);
-                        processor.recycle();
-                        recycledProcessors.offer(processor);
-                        if (state == SocketState.OPEN) {
-                            ((AprEndpoint)proto.endpoint).getPoller().add(socket.getSocket().longValue());
-                        }
-                    }
-                }
-            }
-            return state;
-        }
-
         protected Http11AprProcessor createProcessor() {
             Http11AprProcessor processor = new Http11AprProcessor(
                     proto.getMaxHttpHeaderSize(), (AprEndpoint)proto.endpoint,

Modified: tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java?rev=1137184&r1=1137183&r2=1137184&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java Sat Jun 18 13:41:17 2011
@@ -1641,10 +1641,6 @@ public class AprEndpoint extends Abstrac
     public interface Handler extends AbstractEndpoint.Handler {
         public SocketState process(SocketWrapper<Long> socket,
                 SocketStatus status);
-        public SocketState event(SocketWrapper<Long> socket,
-                SocketStatus status);
-        public SocketState asyncDispatch(SocketWrapper<Long> socket,
-                SocketStatus status);
     }
 
 
@@ -1696,11 +1692,6 @@ public class AprEndpoint extends Abstrac
                         if (socket.async) {
                             waitingRequests.add(socket);
                         }
-                    } else if (state == Handler.SocketState.ASYNC_END) {
-                        socket.access();
-                        SocketProcessor proc =
-                            new SocketProcessor(socket, SocketStatus.OPEN);
-                        getExecutor().execute(proc);
                     }
                 }
             }
@@ -1734,7 +1725,7 @@ public class AprEndpoint extends Abstrac
                 if (status == null) {
                     state = handler.process(socket,SocketStatus.OPEN);
                 } else {
-                    state = handler.asyncDispatch(socket, status);
+                    state = handler.process(socket, status);
                 }
                 if (state == Handler.SocketState.CLOSED) {
                     // Close socket and pool
@@ -1777,7 +1768,7 @@ public class AprEndpoint extends Abstrac
         public void run() {
             synchronized (socket) {
                 // Process the request from this socket
-                Handler.SocketState state = handler.event(socket, status);
+                Handler.SocketState state = handler.process(socket, status);
                 if (state == Handler.SocketState.CLOSED) {
                     // Close socket and pool
                     destroySocket(socket.getSocket().longValue());



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