Author: markt
Date: Tue Sep 29 21:54:39 2015
New Revision: 1705930

URL: http://svn.apache.org/viewvc?rev=1705930&view=rev
Log:
More refactoring to align the dispatch() method between Processors

Modified:
    tomcat/trunk/java/org/apache/coyote/AbstractProcessor.java
    tomcat/trunk/java/org/apache/coyote/ajp/AjpProcessor.java
    tomcat/trunk/java/org/apache/coyote/http11/Http11Processor.java
    tomcat/trunk/java/org/apache/coyote/http2/LocalStrings.properties
    tomcat/trunk/java/org/apache/coyote/http2/StreamProcessor.java

Modified: tomcat/trunk/java/org/apache/coyote/AbstractProcessor.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/AbstractProcessor.java?rev=1705930&r1=1705929&r2=1705930&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/AbstractProcessor.java (original)
+++ tomcat/trunk/java/org/apache/coyote/AbstractProcessor.java Tue Sep 29 
21:54:39 2015
@@ -229,6 +229,18 @@ public abstract class AbstractProcessor
     public abstract SocketState dispatch(SocketStatus status);
 
     /**
+     * Flush any pending writes. Used during non-blocking writes to flush any
+     * remaining data from a previous incomplete write.
+     *
+     * @return <code>true</code> if data remains to be flushed at the end of
+     *         method
+     *
+     * @throws IOException If an I/O error occurs while attempting to flush the
+     *         data
+     */
+    protected abstract boolean flushBufferedWrite() throws IOException ;
+
+    /**
      * Perform any necessary processing for a non-blocking read before
      * dispatching to the adapter.
      */

Modified: tomcat/trunk/java/org/apache/coyote/ajp/AjpProcessor.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/ajp/AjpProcessor.java?rev=1705930&r1=1705929&r2=1705930&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/ajp/AjpProcessor.java (original)
+++ tomcat/trunk/java/org/apache/coyote/ajp/AjpProcessor.java Tue Sep 29 
21:54:39 2015
@@ -623,14 +623,8 @@ public class AjpProcessor extends Abstra
         if (status == SocketStatus.OPEN_WRITE && response.getWriteListener() 
!= null) {
             asyncStateMachine.asyncOperation();
             try {
-                if (hasDataToWrite()) {
-                    socketWrapper.flush(false);
-                    if (hasDataToWrite()) {
-                        // There is data to write but go via Response to
-                        // maintain a consistent view of non-blocking state
-                        response.checkRegisterForWrite();
-                        return SocketState.LONG;
-                    }
+                if (flushBufferedWrite()) {
+                    return SocketState.LONG;
                 }
             } catch (IOException ioe) {
                 if (getLog().isDebugEnabled()) {
@@ -646,7 +640,7 @@ public class AjpProcessor extends Abstra
         RequestInfo rp = request.getRequestProcessor();
         try {
             rp.setStage(org.apache.coyote.Constants.STAGE_SERVICE);
-            if(!getAdapter().asyncDispatch(request, response, status)) {
+            if (!getAdapter().asyncDispatch(request, response, status)) {
                 setErrorState(ErrorState.CLOSE_NOW, null);
             }
         } catch (InterruptedIOException e) {
@@ -675,6 +669,20 @@ public class AjpProcessor extends Abstra
     }
 
     @Override
+    protected boolean flushBufferedWrite() throws IOException {
+        if (hasDataToWrite()) {
+            socketWrapper.flush(false);
+            if (hasDataToWrite()) {
+                // There is data to write but go via Response to
+                // maintain a consistent view of non-blocking state
+                response.checkRegisterForWrite();
+                return true;
+            }
+        }
+        return false;
+    }
+
+    @Override
     protected void dispatchNonBlockingRead() {
         if (available()) {
             super.dispatchNonBlockingRead();

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=1705930&r1=1705929&r2=1705930&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http11/Http11Processor.java (original)
+++ tomcat/trunk/java/org/apache/coyote/http11/Http11Processor.java Tue Sep 29 
21:54:39 2015
@@ -1700,22 +1700,12 @@ public class Http11Processor extends Abs
         if (status == SocketStatus.OPEN_WRITE && response.getWriteListener() 
!= null) {
             asyncStateMachine.asyncOperation();
             try {
-                if (outputBuffer.hasDataToWrite()) {
-                    if (outputBuffer.flushBuffer(false)) {
-                        // The buffer wasn't fully flushed so re-register the
-                        // socket for write. Note this does not go via the
-                        // Response since the write registration state at
-                        // that level should remain unchanged. Once the buffer
-                        // has been emptied then the code below will call
-                        // Adaptor.asyncDispatch() which will enable the
-                        // Response to respond to this event.
-                        outputBuffer.registerWriteInterest();
-                        return SocketState.LONG;
-                    }
+                if (flushBufferedWrite()) {
+                    return SocketState.LONG;
                 }
             } catch (IOException ioe) {
-                if (log.isDebugEnabled()) {
-                    log.debug("Unable to write async data.", ioe);
+                if (getLog().isDebugEnabled()) {
+                    getLog().debug("Unable to write async data.", ioe);
                 }
                 status = SocketStatus.ASYNC_WRITE_ERROR;
                 request.setAttribute(RequestDispatcher.ERROR_EXCEPTION, ioe);
@@ -1735,7 +1725,7 @@ public class Http11Processor extends Abs
         } catch (Throwable t) {
             ExceptionUtils.handleThrowable(t);
             setErrorState(ErrorState.CLOSE_NOW, t);
-            log.error(sm.getString("http11processor.request.process"), t);
+            getLog().error(sm.getString("http11processor.request.process"), t);
         }
 
         rp.setStage(org.apache.coyote.Constants.STAGE_ENDED);
@@ -1762,6 +1752,25 @@ public class Http11Processor extends Abs
     }
 
 
+    @Override
+    protected boolean flushBufferedWrite() throws IOException {
+        if (outputBuffer.hasDataToWrite()) {
+            if (outputBuffer.flushBuffer(false)) {
+                // The buffer wasn't fully flushed so re-register the
+                // socket for write. Note this does not go via the
+                // Response since the write registration state at
+                // that level should remain unchanged. Once the buffer
+                // has been emptied then the code below will call
+                // Adaptor.asyncDispatch() which will enable the
+                // Response to respond to this event.
+                outputBuffer.registerWriteInterest();
+                return true;
+            }
+        }
+        return false;
+    }
+
+
     @Override
     public boolean isUpgrade() {
         return httpUpgradeHandler != null;

Modified: tomcat/trunk/java/org/apache/coyote/http2/LocalStrings.properties
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http2/LocalStrings.properties?rev=1705930&r1=1705929&r2=1705930&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http2/LocalStrings.properties (original)
+++ tomcat/trunk/java/org/apache/coyote/http2/LocalStrings.properties Tue Sep 
29 21:54:39 2015
@@ -72,7 +72,6 @@ stream.write=Connection [{0}], Stream [{
 
 stream.outputBuffer.flush.debug=Connection [{0}], Stream [{1}], flushing 
output with buffer at position [{2}], writeInProgress [{3}] and closed [{4}]
 
-streamProcessor.dispatch=Connection [{0}], Stream [{1}], status [{2}]
 streamProcessor.httpupgrade.notsupported=HTTP upgrade is not supported within 
HTTP/2 streams
 streamProcessor.process.loopend=Connection [{0}], Stream [{1}], loop end, 
state [{2}], dispatches [{3}]
 streamProcessor.process.loopstart=Connection [{0}], Stream [{1}], loop start, 
status [{2}], dispatches [{3}]

Modified: tomcat/trunk/java/org/apache/coyote/http2/StreamProcessor.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http2/StreamProcessor.java?rev=1705930&r1=1705929&r2=1705930&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http2/StreamProcessor.java (original)
+++ tomcat/trunk/java/org/apache/coyote/http2/StreamProcessor.java Tue Sep 29 
21:54:39 2015
@@ -402,30 +402,16 @@ public class StreamProcessor extends Abs
 
     @Override
     public SocketState dispatch(SocketStatus status) {
-        if (log.isDebugEnabled()) {
-            log.debug(sm.getString("streamProcessor.dispatch", 
stream.getConnectionId(),
-                    stream.getIdentifier(), status));
-        }
+
         if (status == SocketStatus.OPEN_WRITE && response.getWriteListener() 
!= null) {
             asyncStateMachine.asyncOperation();
             try {
-                if (stream.getOutputBuffer().flush(false)) {
-                    // The buffer wasn't fully flushed so re-register the
-                    // stream for write. Note this does not go via the
-                    // Response since the write registration state at
-                    // that level should remain unchanged. Once the buffer
-                    // has been emptied then the code below will call
-                    // dispatch() which will enable the
-                    // Response to respond to this event.
-                    if (stream.getOutputBuffer().isReady()) {
-                        // Unexpected
-                        throw new IllegalStateException();
-                    }
+                if (flushBufferedWrite()) {
                     return SocketState.LONG;
                 }
             } catch (IOException ioe) {
-                if (log.isDebugEnabled()) {
-                    log.debug("Unable to write async data.", ioe);
+                if (getLog().isDebugEnabled()) {
+                    getLog().debug("Unable to write async data.", ioe);
                 }
                 status = SocketStatus.ASYNC_WRITE_ERROR;
                 request.setAttribute(RequestDispatcher.ERROR_EXCEPTION, ioe);
@@ -445,7 +431,7 @@ public class StreamProcessor extends Abs
         } catch (Throwable t) {
             ExceptionUtils.handleThrowable(t);
             setErrorState(ErrorState.CLOSE_NOW, t);
-            log.error(sm.getString("http11processor.request.process"), t);
+            getLog().error(sm.getString("http11processor.request.process"), t);
         }
 
         rp.setStage(org.apache.coyote.Constants.STAGE_ENDED);
@@ -462,6 +448,26 @@ public class StreamProcessor extends Abs
     }
 
 
+    @Override
+    protected boolean flushBufferedWrite() throws IOException {
+        if (stream.getOutputBuffer().flush(false)) {
+            // The buffer wasn't fully flushed so re-register the
+            // stream for write. Note this does not go via the
+            // Response since the write registration state at
+            // that level should remain unchanged. Once the buffer
+            // has been emptied then the code below will call
+            // dispatch() which will enable the
+            // Response to respond to this event.
+            if (stream.getOutputBuffer().isReady()) {
+                // Unexpected
+                throw new IllegalStateException();
+            }
+            return true;
+        }
+        return false;
+    }
+
+
     public void addDispatch(DispatchType dispatchType) {
         synchronized (dispatches) {
             dispatches.add(dispatchType);



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

Reply via email to