Align keep-alive disable capability across all HTTP processors
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Tue, 16 Aug 2011 15:45:46 +0000 (15:45 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Tue, 16 Aug 2011 15:45:46 +0000 (15:45 +0000)
git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1158331 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/coyote/http11/AbstractHttp11Processor.java
java/org/apache/coyote/http11/Http11AprProcessor.java
java/org/apache/coyote/http11/Http11NioProcessor.java
java/org/apache/coyote/http11/Http11Processor.java

index bc28feb..0baadc0 100644 (file)
@@ -778,6 +778,14 @@ public abstract class AbstractHttp11Processor<S> extends AbstractProcessor<S> {
     
 
     /**
+     * Processors (currently only HTTP BIO) may elect to disable HTTP keep-alive
+     * in some circumstances. This method allows the processor implementation to
+     * determine if keep-alive should be disabled or not. 
+     */
+    protected abstract boolean disableKeepAlive();
+
+
+    /**
      * After reading the request headers, we have to setup the request filters.
      */
     protected void prepareRequest() {
index df0076d..dd62aa3 100644 (file)
@@ -184,6 +184,10 @@ public class Http11AprProcessor extends AbstractHttp11Processor<Long> {
 
         long soTimeout = endpoint.getSoTimeout();
 
+        if (disableKeepAlive()) {
+            socketWrapper.setKeepAliveLeft(0);
+        }
+
         boolean keptAlive = false;
         boolean openSocket = false;
         boolean sendfileInProgress = false;
@@ -353,6 +357,12 @@ public class Http11AprProcessor extends AbstractHttp11Processor<Long> {
 
 
     @Override
+    protected boolean disableKeepAlive() {
+        return false;
+    }
+
+
+    @Override
     protected void resetTimeouts() {
         // NOOP for APR
     }
index c0dd576..564e2fb 100644 (file)
@@ -213,6 +213,10 @@ public class Http11NioProcessor extends AbstractHttp11Processor<NioChannel> {
         
         long soTimeout = endpoint.getSoTimeout();
 
+        if (disableKeepAlive()) {
+            socketWrapper.setKeepAliveLeft(0);
+        }
+
         boolean keptAlive = false;
         boolean openSocket = false;
         boolean readComplete = true;
@@ -399,6 +403,12 @@ public class Http11NioProcessor extends AbstractHttp11Processor<NioChannel> {
 
 
     @Override
+    protected boolean disableKeepAlive() {
+        return false;
+    }
+
+
+    @Override
     public void recycleInternal() {
         socket = null;
         cometClose = false;
index 48af529..25bbea3 100644 (file)
@@ -148,17 +148,7 @@ public class Http11Processor extends AbstractHttp11Processor<Socket> {
 
         int soTimeout = endpoint.getSoTimeout();
 
-        int threadRatio = -1;   
-        // These may return zero or negative values     
-        // Only calculate a thread ratio when both are >0 to ensure we get a    
-        // sensible result      
-        if (endpoint.getCurrentThreadsBusy() >0 &&      
-                endpoint.getMaxThreads() >0) {      
-            threadRatio = (endpoint.getCurrentThreadsBusy() * 100)      
-                    / endpoint.getMaxThreads();     
-        }   
-        // Disable keep-alive if we are running low on threads      
-        if (threadRatio > getDisableKeepAlivePercentage()) {     
+        if (disableKeepAlive()) {
             socketWrapper.setKeepAliveLeft(0);
         }
 
@@ -368,6 +358,26 @@ public class Http11Processor extends AbstractHttp11Processor<Socket> {
     
     
     @Override
+    protected boolean disableKeepAlive() {
+        int threadRatio = -1;   
+        // These may return zero or negative values     
+        // Only calculate a thread ratio when both are >0 to ensure we get a    
+        // sensible result      
+        if (endpoint.getCurrentThreadsBusy() >0 &&      
+                endpoint.getMaxThreads() >0) {      
+            threadRatio = (endpoint.getCurrentThreadsBusy() * 100)      
+                    / endpoint.getMaxThreads();     
+        }   
+        // Disable keep-alive if we are running low on threads      
+        if (threadRatio > getDisableKeepAlivePercentage()) {     
+            return true;
+        }
+        
+        return false;
+    }
+
+
+    @Override
     protected void resetTimeouts() {
         // NOOP for APR
     }