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/04 22:41:39 UTC

svn commit: r1131490 - in /tomcat/trunk/java/org/apache/coyote: AbstractProcessor.java ajp/AbstractAjpProcessor.java http11/AbstractHttp11Processor.java http11/Http11AprProcessor.java http11/Http11NioProcessor.java http11/Http11Processor.java

Author: markt
Date: Sat Jun  4 20:41:39 2011
New Revision: 1131490

URL: http://svn.apache.org/viewvc?rev=1131490&view=rev
Log:
Create an AbstractProcessor. Start to pull common code from AJP and HTTP processors to this abstract class.

Added:
    tomcat/trunk/java/org/apache/coyote/AbstractProcessor.java   (with props)
Modified:
    tomcat/trunk/java/org/apache/coyote/ajp/AbstractAjpProcessor.java
    tomcat/trunk/java/org/apache/coyote/http11/AbstractHttp11Processor.java
    tomcat/trunk/java/org/apache/coyote/http11/Http11AprProcessor.java
    tomcat/trunk/java/org/apache/coyote/http11/Http11NioProcessor.java
    tomcat/trunk/java/org/apache/coyote/http11/Http11Processor.java

Added: tomcat/trunk/java/org/apache/coyote/AbstractProcessor.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/AbstractProcessor.java?rev=1131490&view=auto
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/AbstractProcessor.java (added)
+++ tomcat/trunk/java/org/apache/coyote/AbstractProcessor.java Sat Jun  4 20:41:39 2011
@@ -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;
+    }
+}

Propchange: tomcat/trunk/java/org/apache/coyote/AbstractProcessor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: tomcat/trunk/java/org/apache/coyote/ajp/AbstractAjpProcessor.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/ajp/AbstractAjpProcessor.java?rev=1131490&r1=1131489&r2=1131490&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/ajp/AbstractAjpProcessor.java (original)
+++ tomcat/trunk/java/org/apache/coyote/ajp/AbstractAjpProcessor.java Sat Jun  4 20:41:39 2011
@@ -26,13 +26,12 @@ import java.security.cert.X509Certificat
 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.HexUti
 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.String
 /**
  * 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 AbstractAjpProcess
 
 
     /**
-     * Associated endpoint.
-     */
-    protected AbstractEndpoint endpoint;
-
-
-    /**
      * Request object.
      */
     protected Request request = null;

Modified: tomcat/trunk/java/org/apache/coyote/http11/AbstractHttp11Processor.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/AbstractHttp11Processor.java?rev=1131490&r1=1131489&r2=1131490&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http11/AbstractHttp11Processor.java (original)
+++ tomcat/trunk/java/org/apache/coyote/http11/AbstractHttp11Processor.java Sat Jun  4 20:41:39 2011
@@ -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.ByteCh
 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 AbstractHttp11Proc
 
     }
 
-    abstract AbstractEndpoint getEndpoint();
     abstract boolean prepareSendfile(OutputFilter[] outputFilters);
     
     public void endRequest() {

Modified: tomcat/trunk/java/org/apache/coyote/http11/Http11AprProcessor.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/Http11AprProcessor.java?rev=1131490&r1=1131489&r2=1131490&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http11/Http11AprProcessor.java (original)
+++ tomcat/trunk/java/org/apache/coyote/http11/Http11AprProcessor.java Sat Jun  4 20:41:39 2011
@@ -42,7 +42,6 @@ import org.apache.tomcat.util.buf.ByteCh
 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 
 
 
     /**
-     * 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 
                     // 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 
             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 
                 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 
         } 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 
             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);
             }
         }
         

Modified: tomcat/trunk/java/org/apache/coyote/http11/Http11NioProcessor.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/Http11NioProcessor.java?rev=1131490&r1=1131489&r2=1131490&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http11/Http11NioProcessor.java (original)
+++ tomcat/trunk/java/org/apache/coyote/http11/Http11NioProcessor.java Sat Jun  4 20:41:39 2011
@@ -38,7 +38,6 @@ import org.apache.tomcat.util.buf.ByteCh
 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 
     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 
         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 
                     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 
                 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 
             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);
             }
         }
     }

Modified: tomcat/trunk/java/org/apache/coyote/http11/Http11Processor.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/Http11Processor.java?rev=1131490&r1=1131489&r2=1131490&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http11/Http11Processor.java (original)
+++ tomcat/trunk/java/org/apache/coyote/http11/Http11Processor.java Sat Jun  4 20:41:39 2011
@@ -37,7 +37,6 @@ import org.apache.tomcat.util.buf.ByteCh
 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 Abs
 
 
     /**
-     * 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 Abs
 
 
     /**
-     * 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 Abs
             }
         } 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 Abs
             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);
             }
         }
     }



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


Re: svn commit: r1131490 - in /tomcat/trunk/java/org/apache/coyote: AbstractProcessor.java ajp/AbstractAjpProcessor.java http11/AbstractHttp11Processor.java http11/Http11AprProcessor.java http11/Http11NioProcessor.java http11/Http11Processor.java

Posted by Mark Thomas <ma...@apache.org>.
On 04/06/2011 21:41, markt@apache.org wrote:
> Author: markt
> Date: Sat Jun  4 20:41:39 2011
> New Revision: 1131490
> 
> URL: http://svn.apache.org/viewvc?rev=1131490&view=rev
> Log:
> Create an AbstractProcessor. Start to pull common code from AJP and HTTP processors to this abstract class.

I have started this refactoring with SocketIO / web sockets in mind.
There are subtle (and not so subtle) differences between the connectors
that I would like to iron out to:
- provide more consistent behaviour between connectors
- allow more refactoring to reduce (currently almost) duplicate code

The async implementation had to be slightly different between the
connectors because of the differences. This increased the complexity of
the original implementation and the ongoing maintenance. As far as
possible I would like to avoid that for SocketIO, hence this upfront
refactoring.

This should simplify any future SocketIO work as well as reducing
(removing?) the need for endpoint specific variations. I want to avoid,
as far as possible, copy and pasting code across multiple connectors and
the tweaking it slightly for that end point.

How far I'll be able to get with this is TBD but there is enough
commonality there to make me think it is worth the attempt. I'm going to
do this, as far as possible, in lots of small commits so it is easy to
review, easy for me to do a bit when I have a spare 5 mins and easy for
other folks to join in.

Mark




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