Author: markt Date: Mon Dec 5 08:54:49 2016 New Revision: 1772603 URL: http://svn.apache.org/viewvc?rev=1772603&view=rev Log: Extract the Runnable implementation from the StreamProcessor
Added: tomcat/trunk/java/org/apache/coyote/http2/StreamRunnable.java Modified: tomcat/trunk/java/org/apache/coyote/http2/Http2UpgradeHandler.java tomcat/trunk/java/org/apache/coyote/http2/StreamProcessor.java Modified: tomcat/trunk/java/org/apache/coyote/http2/Http2UpgradeHandler.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http2/Http2UpgradeHandler.java?rev=1772603&r1=1772602&r2=1772603&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/coyote/http2/Http2UpgradeHandler.java (original) +++ tomcat/trunk/java/org/apache/coyote/http2/Http2UpgradeHandler.java Mon Dec 5 08:54:49 2016 @@ -144,7 +144,7 @@ class Http2UpgradeHandler extends Abstra // Stream concurrency control private int maxConcurrentStreamExecution = Http2Protocol.DEFAULT_MAX_CONCURRENT_STREAM_EXECUTION; private AtomicInteger streamConcurrency = null; - private Queue<StreamProcessor> queuedProcessors = null; + private Queue<StreamRunnable> queuedRunnable = null; // Limits private Set<String> allowedTrailerHeaders = Collections.emptySet(); @@ -191,7 +191,7 @@ class Http2UpgradeHandler extends Abstra // Init concurrency control if needed if (maxConcurrentStreamExecution < localSettings.getMaxConcurrentStreams()) { streamConcurrency = new AtomicInteger(0); - queuedProcessors = new ConcurrentLinkedQueue<>(); + queuedRunnable = new ConcurrentLinkedQueue<>(); } parser = new Http2Parser(connectionId, this, this); @@ -268,15 +268,16 @@ class Http2UpgradeHandler extends Abstra private void processStreamOnContainerThread(Stream stream) { StreamProcessor streamProcessor = new StreamProcessor(this, stream, adapter, socketWrapper); + StreamRunnable streamRunnable = new StreamRunnable(streamProcessor, SocketEvent.OPEN_READ); streamProcessor.setSslSupport(sslSupport); if (streamConcurrency == null) { - socketWrapper.getEndpoint().getExecutor().execute(streamProcessor); + socketWrapper.getEndpoint().getExecutor().execute(streamRunnable); } else { if (getStreamConcurrency() < maxConcurrentStreamExecution) { increaseStreamConcurrency(); - socketWrapper.getEndpoint().getExecutor().execute(streamProcessor); + socketWrapper.getEndpoint().getExecutor().execute(streamRunnable); } else { - queuedProcessors.offer(streamProcessor); + queuedRunnable.offer(streamRunnable); } } } @@ -440,10 +441,10 @@ class Http2UpgradeHandler extends Abstra } decreaseStreamConcurrency(); if (getStreamConcurrency() < maxConcurrentStreamExecution) { - StreamProcessor streamProcessor = queuedProcessors.poll(); - if (streamProcessor != null) { + StreamRunnable streamRunnable = queuedRunnable.poll(); + if (streamRunnable != null) { increaseStreamConcurrency(); - socketWrapper.getEndpoint().getExecutor().execute(streamProcessor); + socketWrapper.getEndpoint().getExecutor().execute(streamRunnable); } } } 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=1772603&r1=1772602&r2=1772603&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:54:49 2016 @@ -32,7 +32,7 @@ import org.apache.tomcat.util.net.Socket import org.apache.tomcat.util.net.SocketWrapperBase; import org.apache.tomcat.util.res.StringManager; -class StreamProcessor extends AbstractProcessor implements Runnable { +class StreamProcessor extends AbstractProcessor { private static final Log log = LogFactory.getLog(StreamProcessor.class); private static final StringManager sm = StringManager.getManager(StreamProcessor.class); @@ -50,8 +50,7 @@ class StreamProcessor extends AbstractPr } - @Override - public final void run() { + final void process(SocketEvent event) { try { // FIXME: the regular processor syncs on socketWrapper, but here this deadlocks synchronized (this) { @@ -60,7 +59,7 @@ class StreamProcessor extends AbstractPr ContainerThreadMarker.set(); SocketState state = SocketState.CLOSED; try { - state = process(socketWrapper, SocketEvent.OPEN_READ); + state = process(socketWrapper, event); if (state == SocketState.CLOSED) { if (!getErrorState().isConnectionIoAllowed()) { @@ -170,7 +169,8 @@ class StreamProcessor extends AbstractPr @Override protected final void executeDispatches(SocketWrapperBase<?> wrapper) { - wrapper.getEndpoint().getExecutor().execute(this); + StreamRunnable streamRunnable = new StreamRunnable(this, SocketEvent.OPEN_READ); + wrapper.getEndpoint().getExecutor().execute(streamRunnable); } Added: tomcat/trunk/java/org/apache/coyote/http2/StreamRunnable.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http2/StreamRunnable.java?rev=1772603&view=auto ============================================================================== --- tomcat/trunk/java/org/apache/coyote/http2/StreamRunnable.java (added) +++ tomcat/trunk/java/org/apache/coyote/http2/StreamRunnable.java Mon Dec 5 08:54:49 2016 @@ -0,0 +1,37 @@ +/* + * 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.http2; + +import org.apache.tomcat.util.net.SocketEvent; + +class StreamRunnable implements Runnable { + + private final StreamProcessor processor; + private final SocketEvent event; + + + public StreamRunnable(StreamProcessor processor, SocketEvent event) { + this.processor = processor; + this.event = event; + } + + + @Override + public void run() { + processor.process(event); + } +} --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org