Create an AbstractProcessor. Start to pull common code from AJP and HTTP processors...
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Sat, 4 Jun 2011 20:41:39 +0000 (20:41 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Sat, 4 Jun 2011 20:41:39 +0000 (20:41 +0000)
git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1131490 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/coyote/AbstractProcessor.java [new file with mode: 0644]
java/org/apache/coyote/ajp/AbstractAjpProcessor.java
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

diff --git a/java/org/apache/coyote/AbstractProcessor.java b/java/org/apache/coyote/AbstractProcessor.java
new file mode 100644 (file)
index 0000000..20d29c8
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.coyote;
+
+import org.apache.tomcat.util.net.AbstractEndpoint;
+
+public abstract class AbstractProcessor implements ActionHook, Processor {
+
+    protected AbstractEndpoint endpoint;
+    
+    protected AbstractEndpoint getEndpoint() {
+        return endpoint;
+    }
+}
index 5a40a1c..7c69da3 100644 (file)
@@ -26,13 +26,12 @@ import java.security.cert.X509Certificate;
 import java.util.concurrent.Executor;
 import java.util.concurrent.atomic.AtomicBoolean;
 
+import org.apache.coyote.AbstractProcessor;
 import org.apache.coyote.ActionCode;
-import org.apache.coyote.ActionHook;
 import org.apache.coyote.Adapter;
 import org.apache.coyote.AsyncContextCallback;
 import org.apache.coyote.AsyncStateMachine;
 import org.apache.coyote.InputBuffer;
-import org.apache.coyote.Processor;
 import org.apache.coyote.Request;
 import org.apache.coyote.Response;
 import org.apache.juli.logging.Log;
@@ -41,7 +40,6 @@ import org.apache.tomcat.util.buf.HexUtils;
 import org.apache.tomcat.util.buf.MessageBytes;
 import org.apache.tomcat.util.http.HttpMessages;
 import org.apache.tomcat.util.http.MimeHeaders;
-import org.apache.tomcat.util.net.AbstractEndpoint;
 import org.apache.tomcat.util.net.AbstractEndpoint.Handler.SocketState;
 import org.apache.tomcat.util.net.SSLSupport;
 import org.apache.tomcat.util.res.StringManager;
@@ -49,7 +47,7 @@ import org.apache.tomcat.util.res.StringManager;
 /**
  * Base class for AJP Processor implementations.
  */
-public abstract class AbstractAjpProcessor implements ActionHook, Processor {
+public abstract class AbstractAjpProcessor extends AbstractProcessor {
 
     protected abstract Log getLog();
 
@@ -69,12 +67,6 @@ public abstract class AbstractAjpProcessor implements ActionHook, Processor {
 
 
     /**
-     * Associated endpoint.
-     */
-    protected AbstractEndpoint endpoint;
-
-
-    /**
      * Request object.
      */
     protected Request request = null;
index b212b51..59fb424 100644 (file)
@@ -22,12 +22,11 @@ import java.util.concurrent.Executor;
 import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.regex.Pattern;
 
+import org.apache.coyote.AbstractProcessor;
 import org.apache.coyote.ActionCode;
-import org.apache.coyote.ActionHook;
 import org.apache.coyote.Adapter;
 import org.apache.coyote.AsyncContextCallback;
 import org.apache.coyote.AsyncStateMachine;
-import org.apache.coyote.Processor;
 import org.apache.coyote.Request;
 import org.apache.coyote.Response;
 import org.apache.coyote.http11.filters.BufferedInputFilter;
@@ -46,11 +45,10 @@ import org.apache.tomcat.util.buf.ByteChunk;
 import org.apache.tomcat.util.buf.MessageBytes;
 import org.apache.tomcat.util.http.FastHttpDateFormat;
 import org.apache.tomcat.util.http.MimeHeaders;
-import org.apache.tomcat.util.net.AbstractEndpoint;
 import org.apache.tomcat.util.net.AbstractEndpoint.Handler.SocketState;
 import org.apache.tomcat.util.res.StringManager;
 
-public abstract class AbstractHttp11Processor implements ActionHook, Processor {
+public abstract class AbstractHttp11Processor extends AbstractProcessor {
 
     protected abstract Log getLog();
 
@@ -968,7 +966,6 @@ public abstract class AbstractHttp11Processor implements ActionHook, Processor {
 
     }
 
-    abstract AbstractEndpoint getEndpoint();
     abstract boolean prepareSendfile(OutputFilter[] outputFilters);
     
     public void endRequest() {
index a6cb615..60358e6 100644 (file)
@@ -42,7 +42,6 @@ import org.apache.tomcat.util.buf.ByteChunk;
 import org.apache.tomcat.util.buf.HexUtils;
 import org.apache.tomcat.util.buf.MessageBytes;
 import org.apache.tomcat.util.http.MimeHeaders;
-import org.apache.tomcat.util.net.AbstractEndpoint;
 import org.apache.tomcat.util.net.AbstractEndpoint.Handler.SocketState;
 import org.apache.tomcat.util.net.AprEndpoint;
 import org.apache.tomcat.util.net.SSLSupport;
@@ -131,16 +130,6 @@ public class Http11AprProcessor extends AbstractHttp11Processor {
 
 
     /**
-     * Associated endpoint.
-     */
-    protected AprEndpoint endpoint;
-    @Override
-    protected AbstractEndpoint getEndpoint() {
-        return endpoint;
-    }
-
-
-    /**
      * When client certificate information is presented in a form other than
      * instances of {@link java.security.cert.X509Certificate} it needs to be
      * converted before it can be used and this property controls which JSSE
@@ -246,7 +235,7 @@ public class Http11AprProcessor extends AbstractHttp11Processor {
                     // and the method should return true
                     openSocket = true;
                     // Add the socket to the poller
-                    endpoint.getPoller().add(socketRef);
+                    ((AprEndpoint)endpoint).getPoller().add(socketRef);
                     if (endpoint.isPaused()) {
                         // 503 - Service unavailable
                         response.setStatus(503);
@@ -353,7 +342,7 @@ public class Http11AprProcessor extends AbstractHttp11Processor {
             if (sendfileData != null && !error) {
                 sendfileData.socket = socketRef;
                 sendfileData.keepAlive = keepAlive;
-                if (!endpoint.getSendfile().add(sendfileData)) {
+                if (!((AprEndpoint)endpoint).getSendfile().add(sendfileData)) {
                     openSocket = true;
                     break;
                 }
@@ -594,7 +583,7 @@ public class Http11AprProcessor extends AbstractHttp11Processor {
                 try {
                     // Configure connection to require a certificate
                     SSLSocket.setVerify(socketRef, SSL.SSL_CVERIFY_REQUIRE,
-                            endpoint.getSSLVerifyDepth());
+                            ((AprEndpoint)endpoint).getSSLVerifyDepth());
                     // Renegotiate certificates
                     if (SSLSocket.renegotiate(socketRef) == 0) {
                         // Don't look for certs unless we know renegotiation worked.
@@ -628,12 +617,14 @@ public class Http11AprProcessor extends AbstractHttp11Processor {
         } else if (actionCode == ActionCode.COMET_END) {
             comet = false;
         } else if (actionCode == ActionCode.COMET_CLOSE) {
-            endpoint.processSocketAsync(this.socket, SocketStatus.OPEN);
+            ((AprEndpoint)endpoint).processSocketAsync(this.socket,
+                    SocketStatus.OPEN);
         } else if (actionCode == ActionCode.COMET_SETTIMEOUT) {
             //no op
         } else if (actionCode == ActionCode.ASYNC_COMPLETE) {
             if (asyncStateMachine.asyncComplete()) {
-                endpoint.processSocketAsync(this.socket, SocketStatus.OPEN);
+                ((AprEndpoint)endpoint).processSocketAsync(this.socket,
+                        SocketStatus.OPEN);
             }
         } else if (actionCode == ActionCode.ASYNC_SETTIMEOUT) {
             if (param==null) return;
@@ -641,7 +632,8 @@ public class Http11AprProcessor extends AbstractHttp11Processor {
             socket.setTimeout(timeout);
         } else if (actionCode == ActionCode.ASYNC_DISPATCH) {
             if (asyncStateMachine.asyncDispatch()) {
-                endpoint.processSocketAsync(this.socket, SocketStatus.OPEN);
+                ((AprEndpoint)endpoint).processSocketAsync(this.socket,
+                        SocketStatus.OPEN);
             }
         }
         
index 609d337..273d514 100644 (file)
@@ -38,7 +38,6 @@ import org.apache.tomcat.util.buf.ByteChunk;
 import org.apache.tomcat.util.buf.HexUtils;
 import org.apache.tomcat.util.buf.MessageBytes;
 import org.apache.tomcat.util.http.MimeHeaders;
-import org.apache.tomcat.util.net.AbstractEndpoint;
 import org.apache.tomcat.util.net.AbstractEndpoint.Handler.SocketState;
 import org.apache.tomcat.util.net.NioChannel;
 import org.apache.tomcat.util.net.NioEndpoint;
@@ -138,23 +137,6 @@ public class Http11NioProcessor extends AbstractHttp11Processor {
     protected NioChannel socket = null;
 
 
-    /**
-     * Associated endpoint.
-     */
-    protected NioEndpoint endpoint;
-
-    
-    // ------------------------------------------------------------- Properties
-
-    /**
-     * Expose the endpoint.
-     */
-    @Override
-    protected AbstractEndpoint getEndpoint() {
-        return endpoint;
-    }
-
-
     // --------------------------------------------------------- Public Methods
 
 
@@ -288,8 +270,8 @@ public class Http11NioProcessor extends AbstractHttp11Processor {
         this.socket = socket;
         inputBuffer.setSocket(socket);
         outputBuffer.setSocket(socket);
-        inputBuffer.setSelectorPool(endpoint.getSelectorPool());
-        outputBuffer.setSelectorPool(endpoint.getSelectorPool());
+        inputBuffer.setSelectorPool(((NioEndpoint)endpoint).getSelectorPool());
+        outputBuffer.setSelectorPool(((NioEndpoint)endpoint).getSelectorPool());
 
         // Error flag
         error = false;
@@ -636,9 +618,9 @@ public class Http11NioProcessor extends AbstractHttp11Processor {
                     engine.setNeedClientAuth(true);
                     try {
                         sslChannel.rehandshake(endpoint.getSoTimeout());
-                        sslSupport =
-                            endpoint.getHandler().getSslImplementation().getSSLSupport(
-                                    engine.getSession());
+                        sslSupport = ((NioEndpoint)endpoint).getHandler()
+                                .getSslImplementation().getSSLSupport(
+                                        engine.getSession());
                     } catch (IOException ioe) {
                         log.warn(sm.getString("http11processor.socket.sslreneg",ioe));
                     }
@@ -682,7 +664,8 @@ public class Http11NioProcessor extends AbstractHttp11Processor {
                 attach.setTimeout(timeout);
         } else if (actionCode == ActionCode.ASYNC_COMPLETE) {
             if (asyncStateMachine.asyncComplete()) {
-                endpoint.processSocket(this.socket, SocketStatus.OPEN, true);
+                ((NioEndpoint)endpoint).processSocket(this.socket,
+                        SocketStatus.OPEN, true);
             }
         } else if (actionCode == ActionCode.ASYNC_SETTIMEOUT) {
             if (param==null) return;
@@ -693,7 +676,8 @@ public class Http11NioProcessor extends AbstractHttp11Processor {
             attach.setTimeout(timeout);
         } else if (actionCode == ActionCode.ASYNC_DISPATCH) {
             if (asyncStateMachine.asyncDispatch()) {
-                endpoint.processSocket(this.socket, SocketStatus.OPEN, true);
+                ((NioEndpoint)endpoint).processSocket(this.socket,
+                        SocketStatus.OPEN, true);
             }
         }
     }
index 5e5cc2d..f14c8c2 100644 (file)
@@ -37,7 +37,6 @@ import org.apache.tomcat.util.buf.ByteChunk;
 import org.apache.tomcat.util.buf.HexUtils;
 import org.apache.tomcat.util.buf.MessageBytes;
 import org.apache.tomcat.util.http.MimeHeaders;
-import org.apache.tomcat.util.net.AbstractEndpoint;
 import org.apache.tomcat.util.net.AbstractEndpoint.Handler.SocketState;
 import org.apache.tomcat.util.net.JIoEndpoint;
 import org.apache.tomcat.util.net.SSLSupport;
@@ -113,12 +112,6 @@ public class Http11Processor extends AbstractHttp11Processor {
 
 
     /**
-     * Associated endpoint.
-     */
-    protected JIoEndpoint endpoint;
-
-
-    /**
      * The percentage of threads that have to be in use before keep-alive is
      * disabled to aid scalability.
      */
@@ -128,14 +121,6 @@ public class Http11Processor extends AbstractHttp11Processor {
 
 
     /**
-     * Expose the endpoint.
-     */
-    @Override
-    protected AbstractEndpoint getEndpoint() {
-        return this.endpoint;
-    }
-
-    /**
      * Set the SSL information for this HTTP connection.
      */
     public void setSSLSupport(SSLSupport sslSupport) {
@@ -584,7 +569,8 @@ public class Http11Processor extends AbstractHttp11Processor {
             }
         } else if (actionCode == ActionCode.ASYNC_COMPLETE) {
             if (asyncStateMachine.asyncComplete()) {
-                endpoint.processSocketAsync(this.socket, SocketStatus.OPEN);
+                ((JIoEndpoint) endpoint).processSocketAsync(this.socket,
+                        SocketStatus.OPEN);
             }
         } else if (actionCode == ActionCode.ASYNC_SETTIMEOUT) {
             if (param == null) return;
@@ -593,7 +579,8 @@ public class Http11Processor extends AbstractHttp11Processor {
             socket.setTimeout(timeout);
         } else if (actionCode == ActionCode.ASYNC_DISPATCH) {
             if (asyncStateMachine.asyncDispatch()) {
-                endpoint.processSocketAsync(this.socket, SocketStatus.OPEN);
+                ((JIoEndpoint) endpoint).processSocketAsync(this.socket,
+                        SocketStatus.OPEN);
             }
         }
     }