diff --git a/jetty-server/src/main/config/etc/jetty-stats.xml b/jetty-server/src/main/config/etc/jetty-stats.xml index f8fd0ba9dff9..8ba66e60d701 100644 --- a/jetty-server/src/main/config/etc/jetty-stats.xml +++ b/jetty-server/src/main/config/etc/jetty-stats.xml @@ -6,7 +6,7 @@ - + diff --git a/jetty-server/src/main/config/modules/stats.mod b/jetty-server/src/main/config/modules/stats.mod index 23b0f16237ad..a6289c4174bb 100644 --- a/jetty-server/src/main/config/modules/stats.mod +++ b/jetty-server/src/main/config/modules/stats.mod @@ -19,4 +19,4 @@ jetty.webapp.addServerClasses+=,-org.eclipse.jetty.servlet.StatisticsServlet [ini-template] ## If the Graceful shutdown should wait for async requests as well as the currently dispatched ones. -# jetty.statistics.asyncGraceful=true +# jetty.statistics.gracefulShutdownWaitsForRequests=true diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/StatisticsHandler.java b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/StatisticsHandler.java index 70650b7a04cc..965895512958 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/StatisticsHandler.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/StatisticsHandler.java @@ -67,7 +67,7 @@ public class StatisticsHandler extends HandlerWrapper implements Graceful private final LongAdder _responses5xx = new LongAdder(); private final LongAdder _responsesTotalBytes = new LongAdder(); - private boolean asyncGraceful = true; + private boolean _gracefulShutdownWaitsForRequests = true; private final Graceful.Shutdown _shutdown = new Graceful.Shutdown() { @@ -81,25 +81,25 @@ protected FutureCallback newShutdownCallback() private final AsyncListener _onCompletion = new AsyncListener() { @Override - public void onStartAsync(AsyncEvent event) throws IOException + public void onStartAsync(AsyncEvent event) { event.getAsyncContext().addListener(this); } @Override - public void onTimeout(AsyncEvent event) throws IOException + public void onTimeout(AsyncEvent event) { _expires.increment(); } @Override - public void onError(AsyncEvent event) throws IOException + public void onError(AsyncEvent event) { _errors.increment(); } @Override - public void onComplete(AsyncEvent event) throws IOException + public void onComplete(AsyncEvent event) { HttpChannelState state = ((AsyncContextEvent)event).getHttpChannelState(); @@ -113,8 +113,7 @@ public void onComplete(AsyncEvent event) throws IOException _asyncWaitStats.decrement(); - // If we have no more dispatches, should we signal shutdown? - if (numRequests == 0 && asyncGraceful) + if (numRequests == 0 && _gracefulShutdownWaitsForRequests) { FutureCallback shutdown = _shutdown.get(); if (shutdown != null) @@ -207,9 +206,7 @@ public void handle(String path, Request baseRequest, HttpServletRequest request, if (shutdown != null) { response.flushBuffer(); - - // If we either have no more requests or dispatches, we can complete shutdown. - if (asyncGraceful ? (numRequests == 0) : (numDispatches == 0)) + if (_gracefulShutdownWaitsForRequests ? (numRequests == 0) : (numDispatches == 0)) shutdown.succeeded(); } } @@ -268,11 +265,23 @@ protected void doStop() throws Exception * Set whether the graceful shutdown should wait for all requests to complete including * async requests which are not currently dispatched, or whether it should only wait for all the * actively dispatched requests to complete. - * @param asyncGraceful true to wait for async requests on graceful shutdown. + * @param gracefulShutdownWaitsForRequests true to wait for async requests on graceful shutdown. + */ + public void setGracefulShutdownWaitsForRequests(boolean gracefulShutdownWaitsForRequests) + { + _gracefulShutdownWaitsForRequests = gracefulShutdownWaitsForRequests; + } + + /** + * @return whether the graceful shutdown will wait for all requests to complete including + * async requests which are not currently dispatched, or whether it will only wait for all the + * actively dispatched requests to complete. + * @see #getAsyncDispatches() */ - public void setAsyncGraceful(boolean asyncGraceful) + @ManagedAttribute("if graceful shutdown will wait for all requests") + public boolean getGracefulShutdownWaitsForRequests() { - this.asyncGraceful = asyncGraceful; + return _gracefulShutdownWaitsForRequests; } /** 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 c4bbc702cf9a..7ce2b5b0718c 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 @@ -431,7 +431,7 @@ public void waitForSuspendedRequestTest() throws Exception CyclicBarrier barrier = new CyclicBarrier(3); final AtomicReference asyncHolder = new AtomicReference<>(); final CountDownLatch dispatched = new CountDownLatch(1); - _statsHandler.setAsyncGraceful(true); + _statsHandler.setGracefulShutdownWaitsForRequests(true); _statsHandler.setHandler(new AbstractHandler() { @Override @@ -487,7 +487,7 @@ public void doNotWaitForSuspendedRequestTest() throws Exception CyclicBarrier barrier = new CyclicBarrier(3); final AtomicReference asyncHolder = new AtomicReference<>(); final CountDownLatch dispatched = new CountDownLatch(1); - _statsHandler.setAsyncGraceful(false); + _statsHandler.setGracefulShutdownWaitsForRequests(false); _statsHandler.setHandler(new AbstractHandler() { @Override