Author: markt Date: Mon Dec 5 08:55:10 2016 New Revision: 1772604 URL: http://svn.apache.org/viewvc?rev=1772604&view=rev Log: Refactor dispatches processing
Processors such as HTTP/2 need to process these per stream so it needs to be handled in the Processor, not in the SocketWrapper. 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/StreamProcessor.java tomcat/trunk/java/org/apache/tomcat/util/net/SocketWrapperBase.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=1772604&r1=1772603&r2=1772604&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/coyote/AbstractProcessor.java (original) +++ tomcat/trunk/java/org/apache/coyote/AbstractProcessor.java Mon Dec 5 08:55:10 2016 @@ -19,6 +19,7 @@ package org.apache.coyote; import java.io.IOException; import java.io.InterruptedIOException; import java.nio.ByteBuffer; +import java.util.Iterator; import java.util.concurrent.Executor; import java.util.concurrent.atomic.AtomicBoolean; @@ -470,10 +471,7 @@ public abstract class AbstractProcessor break; } case DISPATCH_EXECUTE: { - SocketWrapperBase<?> wrapper = socketWrapper; - if (wrapper != null) { - executeDispatches(wrapper); - } + executeDispatches(); break; } @@ -651,7 +649,36 @@ public abstract class AbstractProcessor protected abstract boolean isReady(); - protected abstract void executeDispatches(SocketWrapperBase<?> wrapper); + protected void executeDispatches() { + SocketWrapperBase<?> socketWrapper = getSocketWrapper(); + Iterator<DispatchType> dispatches = getIteratorAndClearDispatches(); + if (socketWrapper != null) { + synchronized (socketWrapper) { + /* + * This method is called when non-blocking IO is initiated by defining + * a read and/or write listener in a non-container thread. It is called + * once the non-container thread completes so that the first calls to + * onWritePossible() and/or onDataAvailable() as appropriate are made by + * the container. + * + * Processing the dispatches requires (for APR/native at least) + * that the socket has been added to the waitingRequests queue. This may + * not have occurred by the time that the non-container thread completes + * triggering the call to this method. Therefore, the coded syncs on the + * SocketWrapper as the container thread that initiated this + * non-container thread holds a lock on the SocketWrapper. The container + * thread will add the socket to the waitingRequests queue before + * releasing the lock on the socketWrapper. Therefore, by obtaining the + * lock on socketWrapper before processing the dispatches, we can be + * sure that the socket has been added to the waitingRequests queue. + */ + while (dispatches != null && dispatches.hasNext()) { + DispatchType dispatchType = dispatches.next(); + socketWrapper.processSocket(dispatchType.getSocketStatus(), false); + } + } + } + } /** 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=1772604&r1=1772603&r2=1772604&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/coyote/ajp/AjpProcessor.java (original) +++ tomcat/trunk/java/org/apache/coyote/ajp/AjpProcessor.java Mon Dec 5 08:55:10 2016 @@ -1264,12 +1264,6 @@ public class AjpProcessor extends Abstra } - @Override - protected final void executeDispatches(SocketWrapperBase<?> wrapper) { - wrapper.executeNonBlockingDispatches(getIteratorAndClearDispatches()); - } - - /** * Read at least the specified amount of bytes, and place them * in the input buffer. Note that if any data is available to read then this 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=1772604&r1=1772603&r2=1772604&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/coyote/http11/Http11Processor.java (original) +++ tomcat/trunk/java/org/apache/coyote/http11/Http11Processor.java Mon Dec 5 08:55:10 2016 @@ -1565,12 +1565,6 @@ public class Http11Processor extends Abs @Override - protected final void executeDispatches(SocketWrapperBase<?> wrapper) { - wrapper.executeNonBlockingDispatches(getIteratorAndClearDispatches()); - } - - - @Override public UpgradeToken getUpgradeToken() { return upgradeToken; } 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=1772604&r1=1772603&r2=1772604&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/coyote/http2/StreamProcessor.java (original) +++ tomcat/trunk/java/org/apache/coyote/http2/StreamProcessor.java Mon Dec 5 08:55:10 2016 @@ -168,9 +168,9 @@ class StreamProcessor extends AbstractPr @Override - protected final void executeDispatches(SocketWrapperBase<?> wrapper) { + protected final void executeDispatches() { StreamRunnable streamRunnable = new StreamRunnable(this, SocketEvent.OPEN_READ); - wrapper.getEndpoint().getExecutor().execute(streamRunnable); + getSocketWrapper().getEndpoint().getExecutor().execute(streamRunnable); } Modified: tomcat/trunk/java/org/apache/tomcat/util/net/SocketWrapperBase.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/net/SocketWrapperBase.java?rev=1772604&r1=1772603&r2=1772604&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/net/SocketWrapperBase.java (original) +++ tomcat/trunk/java/org/apache/tomcat/util/net/SocketWrapperBase.java Mon Dec 5 08:55:10 2016 @@ -713,32 +713,6 @@ public abstract class SocketWrapperBase< } - public synchronized void executeNonBlockingDispatches(Iterator<DispatchType> dispatches) { - /* - * This method is called when non-blocking IO is initiated by defining - * a read and/or write listener in a non-container thread. It is called - * once the non-container thread completes so that the first calls to - * onWritePossible() and/or onDataAvailable() as appropriate are made by - * the container. - * - * Processing the dispatches requires (for APR/native at least) - * that the socket has been added to the waitingRequests queue. This may - * not have occurred by the time that the non-container thread completes - * triggering the call to this method. Therefore, the coded syncs on the - * SocketWrapper as the container thread that initiated this - * non-container thread holds a lock on the SocketWrapper. The container - * thread will add the socket to the waitingRequests queue before - * releasing the lock on the socketWrapper. Therefore, by obtaining the - * lock on socketWrapper before processing the dispatches, we can be - * sure that the socket has been added to the waitingRequests queue. - */ - while (dispatches != null && dispatches.hasNext()) { - DispatchType dispatchType = dispatches.next(); - processSocket(dispatchType.getSocketStatus(), false); - } - } - - public abstract void registerReadInterest(); public abstract void registerWriteInterest(); --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org