diff --git a/jetty-fcgi/fcgi-server/src/main/java/org/eclipse/jetty/fcgi/server/HttpTransportOverFCGI.java b/jetty-fcgi/fcgi-server/src/main/java/org/eclipse/jetty/fcgi/server/HttpTransportOverFCGI.java index a2747fa45f3..316824e42fe 100644 --- a/jetty-fcgi/fcgi-server/src/main/java/org/eclipse/jetty/fcgi/server/HttpTransportOverFCGI.java +++ b/jetty-fcgi/fcgi-server/src/main/java/org/eclipse/jetty/fcgi/server/HttpTransportOverFCGI.java @@ -138,7 +138,7 @@ public class HttpTransportOverFCGI implements HttpTransport } @Override - public void completed() + public void onCompleted() { } } diff --git a/jetty-http2/http2-server/src/main/java/org/eclipse/jetty/http2/server/HttpTransportOverHTTP2.java b/jetty-http2/http2-server/src/main/java/org/eclipse/jetty/http2/server/HttpTransportOverHTTP2.java index 6d2705ce113..28b80de9fb4 100644 --- a/jetty-http2/http2-server/src/main/java/org/eclipse/jetty/http2/server/HttpTransportOverHTTP2.java +++ b/jetty-http2/http2-server/src/main/java/org/eclipse/jetty/http2/server/HttpTransportOverHTTP2.java @@ -176,7 +176,7 @@ public class HttpTransportOverHTTP2 implements HttpTransport } @Override - public void completed() + public void onCompleted() { } diff --git a/jetty-io/src/main/java/org/eclipse/jetty/io/ByteArrayEndPoint.java b/jetty-io/src/main/java/org/eclipse/jetty/io/ByteArrayEndPoint.java index e3f25e7ff99..8aec3c17516 100644 --- a/jetty-io/src/main/java/org/eclipse/jetty/io/ByteArrayEndPoint.java +++ b/jetty-io/src/main/java/org/eclipse/jetty/io/ByteArrayEndPoint.java @@ -41,6 +41,15 @@ public class ByteArrayEndPoint extends AbstractEndPoint static final Logger LOG = Log.getLogger(ByteArrayEndPoint.class); public final static InetSocketAddress NOIP=new InetSocketAddress(0); + private final Runnable _runFillable = new Runnable() + { + @Override + public void run() + { + getFillInterest().fillable(); + } + }; + protected volatile ByteBuffer _in; protected volatile ByteBuffer _out; protected volatile boolean _ishut; @@ -110,6 +119,12 @@ public class ByteArrayEndPoint extends AbstractEndPoint // Don't need to do anything here as takeOutput does the signalling. } + /* ------------------------------------------------------------ */ + protected void execute(Runnable task) + { + new Thread(task,"BAEPoint-"+Integer.toHexString(hashCode())); + } + /* ------------------------------------------------------------ */ @Override protected void needsFillInterest() throws IOException @@ -117,14 +132,7 @@ public class ByteArrayEndPoint extends AbstractEndPoint if (_closed) throw new ClosedChannelException(); if (BufferUtil.hasContent(_in) || _in==null) - getScheduler().schedule(new Runnable() - { - public void run() - { - if (!_closed && _in!=null) - getFillInterest().fillable(); - } - },1,TimeUnit.MILLISECONDS); + execute(_runFillable); } /* ------------------------------------------------------------ */ diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpChannel.java b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpChannel.java index 38c714b64cf..05750ad3257 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpChannel.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpChannel.java @@ -549,7 +549,7 @@ public class HttpChannel implements Runnable, HttpOutput.Interceptor { if (_requestLog!=null ) _requestLog.log(_request,_committedMetaData==null?-1:_committedMetaData.getStatus(), _written); - _transport.completed(); + _transport.onCompleted(); } public void onEarlyEOF() diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpConnection.java b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpConnection.java index 62ff5a3cc0d..efd4fd88e5a 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpConnection.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpConnection.java @@ -330,7 +330,7 @@ public class HttpConnection extends AbstractConnection implements Runnable, Http } @Override - public void completed() + public void onCompleted() { // Handle connection upgrades if (_channel.getResponse().getStatus() == HttpStatus.SWITCHING_PROTOCOLS_101) diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpTransport.java b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpTransport.java index 493acf45f14..84badcd610e 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpTransport.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpTransport.java @@ -31,7 +31,7 @@ public interface HttpTransport void push(MetaData.Request request); - void completed(); + void onCompleted(); /** * Aborts this transport. diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/LocalConnector.java b/jetty-server/src/main/java/org/eclipse/jetty/server/LocalConnector.java index 4d4fcfc4247..e7440ff0857 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/LocalConnector.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/LocalConnector.java @@ -190,6 +190,11 @@ public class LocalConnector extends AbstractConnector super(LocalConnector.this.getScheduler(), LocalConnector.this.getIdleTimeout()); setGrowOutput(true); } + + protected void execute(Runnable task) + { + getExecutor().execute(task); + } public void addInput(String s) { diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/HttpServerTestBase.java b/jetty-server/src/test/java/org/eclipse/jetty/server/HttpServerTestBase.java index a4de039cd9b..cf9b22912a1 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/HttpServerTestBase.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/HttpServerTestBase.java @@ -986,8 +986,8 @@ public abstract class HttpServerTestBase extends HttpServerTestFixture } String in = new String(b, 0, i, StandardCharsets.UTF_8); - assertTrue(in.contains("123456789")); - assertTrue(in.contains("abcdefghZ")); + assertThat(in,containsString("123456789")); + assertThat(in,containsString("abcdefghZ")); assertFalse(in.contains("Wibble")); in = new String(b, i, b.length - i, StandardCharsets.UTF_16); @@ -1086,9 +1086,9 @@ public abstract class HttpServerTestBase extends HttpServerTestFixture os.flush(); String in = IO.toString(is); - assertTrue(in.contains("123456789")); - assertTrue(in.contains("abcdefghi")); - assertTrue(in.contains("Wibble")); + assertThat(in,containsString("123456789")); + assertThat(in,containsString("abcdefghi")); + assertThat(in,containsString("Wibble")); } } @@ -1154,7 +1154,7 @@ public abstract class HttpServerTestBase extends HttpServerTestFixture assertEquals(-1, is.read()); // Closed by error! - assertTrue(in.contains("HTTP/1.1 200 OK")); + assertThat(in,containsString("HTTP/1.1 200 OK")); assertTrue(in.indexOf("Transfer-Encoding: chunked") > 0); assertTrue(in.indexOf("Now is the time for all good men to come to the aid of the party") > 0); assertThat(in, Matchers.not(Matchers.containsString("\r\n0\r\n"))); diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/ResponseTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/ResponseTest.java index 2d831558597..96d3c4c327e 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/ResponseTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/ResponseTest.java @@ -101,7 +101,7 @@ public class ResponseTest } @Override - public void completed() + public void onCompleted() { } diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/handler/StatisticsHandlerTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/handler/StatisticsHandlerTest.java index 4e5dc2d3fc7..e7eae90224f 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/handler/StatisticsHandlerTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/handler/StatisticsHandlerTest.java @@ -171,42 +171,68 @@ public class StatisticsHandlerTest assertEquals(0, _statsHandler.getAsyncDispatches()); assertEquals(0, _statsHandler.getExpires()); assertEquals(2, _statsHandler.getResponses2xx()); + } + + @Test + public void testTwoRequests() throws Exception + { + final CyclicBarrier barrier[] = {new CyclicBarrier(3), new CyclicBarrier(3)}; _latchHandler.reset(2); - barrier[0] = new CyclicBarrier(3); - barrier[1] = new CyclicBarrier(3); + _statsHandler.setHandler(new AbstractHandler() + { + @Override + public void handle(String path, Request request, HttpServletRequest httpRequest, HttpServletResponse httpResponse) throws IOException, ServletException + { + request.setHandled(true); + try + { + barrier[0].await(); + barrier[1].await(); + } + catch (Exception x) + { + Thread.currentThread().interrupt(); + throw (IOException)new IOException().initCause(x); + } + } + }); + _server.start(); + String request = "GET / HTTP/1.1\r\n" + + "Host: localhost\r\n" + + "\r\n"; + _connector.executeRequest(request); _connector.executeRequest(request); barrier[0].await(); - assertEquals(4, _statistics.getConnectionsOpen()); + assertEquals(2, _statistics.getConnectionsOpen()); - assertEquals(4, _statsHandler.getRequests()); + assertEquals(2, _statsHandler.getRequests()); assertEquals(2, _statsHandler.getRequestsActive()); assertEquals(2, _statsHandler.getRequestsActiveMax()); - assertEquals(4, _statsHandler.getDispatched()); + assertEquals(2, _statsHandler.getDispatched()); assertEquals(2, _statsHandler.getDispatchedActive()); assertEquals(2, _statsHandler.getDispatchedActiveMax()); - barrier[1].await(); assertTrue(_latchHandler.await()); - assertEquals(4, _statsHandler.getRequests()); + assertEquals(2, _statsHandler.getRequests()); assertEquals(0, _statsHandler.getRequestsActive()); assertEquals(2, _statsHandler.getRequestsActiveMax()); - assertEquals(4, _statsHandler.getDispatched()); + assertEquals(2, _statsHandler.getDispatched()); assertEquals(0, _statsHandler.getDispatchedActive()); assertEquals(2, _statsHandler.getDispatchedActiveMax()); assertEquals(0, _statsHandler.getAsyncRequests()); assertEquals(0, _statsHandler.getAsyncDispatches()); assertEquals(0, _statsHandler.getExpires()); - assertEquals(4, _statsHandler.getResponses2xx()); + assertEquals(2, _statsHandler.getResponses2xx()); } @Test diff --git a/jetty-server/src/test/resources/jetty-logging.properties b/jetty-server/src/test/resources/jetty-logging.properties index adf68c7c337..d2d9f09e73e 100644 --- a/jetty-server/src/test/resources/jetty-logging.properties +++ b/jetty-server/src/test/resources/jetty-logging.properties @@ -1,3 +1,3 @@ org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog -#org.eclipse.jetty.LEVEL=DEBUG +org.eclipse.jetty.LEVEL=DEBUG #org.eclipse.jetty.server.LEVEL=DEBUG diff --git a/jetty-spdy/spdy-http-server/src/main/java/org/eclipse/jetty/spdy/server/http/HttpTransportOverSPDY.java b/jetty-spdy/spdy-http-server/src/main/java/org/eclipse/jetty/spdy/server/http/HttpTransportOverSPDY.java index 3a7a983dfd5..196d2e7fff0 100644 --- a/jetty-spdy/spdy-http-server/src/main/java/org/eclipse/jetty/spdy/server/http/HttpTransportOverSPDY.java +++ b/jetty-spdy/spdy-http-server/src/main/java/org/eclipse/jetty/spdy/server/http/HttpTransportOverSPDY.java @@ -224,7 +224,7 @@ public class HttpTransportOverSPDY implements HttpTransport } @Override - public void completed() + public void onCompleted() { if (LOG.isDebugEnabled()) LOG.debug("Completed {}", this); @@ -264,7 +264,7 @@ public class HttpTransportOverSPDY implements HttpTransport } @Override - public void completed() + public void onCompleted() { Stream stream = getStream(); if (LOG.isDebugEnabled()) diff --git a/jetty-spdy/spdy-http-server/src/main/java/org/eclipse/jetty/spdy/server/proxy/ProxyHTTPSPDYConnection.java b/jetty-spdy/spdy-http-server/src/main/java/org/eclipse/jetty/spdy/server/proxy/ProxyHTTPSPDYConnection.java index 0cc288ef5b3..71aec5c13d7 100644 --- a/jetty-spdy/spdy-http-server/src/main/java/org/eclipse/jetty/spdy/server/proxy/ProxyHTTPSPDYConnection.java +++ b/jetty-spdy/spdy-http-server/src/main/java/org/eclipse/jetty/spdy/server/proxy/ProxyHTTPSPDYConnection.java @@ -141,12 +141,12 @@ public class ProxyHTTPSPDYConnection extends HttpConnection implements HttpParse } @Override - public void completed() + public void onCompleted() { headers.clear(); stream = null; content = null; - super.completed(); + super.onCompleted(); } @Override @@ -275,7 +275,7 @@ public class ProxyHTTPSPDYConnection extends HttpConnection implements HttpParse }); if (replyInfo.isClose()) - completed(); + onCompleted(); handler.succeeded(); } @@ -311,7 +311,7 @@ public class ProxyHTTPSPDYConnection extends HttpConnection implements HttpParse }); if (dataInfo.isClose()) - completed(); + onCompleted(); handler.succeeded(); } diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/thread/ExecutionStrategy.java b/jetty-util/src/main/java/org/eclipse/jetty/util/thread/ExecutionStrategy.java index 81ea3a00738..c43893c59fd 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/thread/ExecutionStrategy.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/thread/ExecutionStrategy.java @@ -21,6 +21,9 @@ package org.eclipse.jetty.util.thread; import java.util.concurrent.Executor; import java.util.concurrent.atomic.AtomicReference; +import org.eclipse.jetty.util.log.Log; +import org.eclipse.jetty.util.log.Logger; + /** *
An {@link ExecutionStrategy} executes {@link Runnable} tasks produced by a {@link Producer}.
* The strategy to execute the task may vary depending on the implementation; the task may be
@@ -59,6 +62,7 @@ public interface ExecutionStrategy
*/
public static class ProduceExecuteRun implements ExecutionStrategy
{
+ private static final Logger LOG = Log.getLogger(ExecutionStrategy.class);
private final Producer _producer;
private final Executor _executor;
@@ -76,6 +80,8 @@ public interface ExecutionStrategy
{
// Produce a task.
Runnable task = _producer.produce();
+ if (LOG.isDebugEnabled())
+ LOG.debug("{} PER produced {}",_producer,task);
if (task == null)
break;
@@ -107,6 +113,7 @@ public interface ExecutionStrategy
*/
public static class ExecuteProduceRun implements ExecutionStrategy, Runnable
{
+ private static final Logger LOG = Log.getLogger(ExecutionStrategy.class);
private final AtomicReference