diff --git a/jetty-server/src/main/config/etc/jetty-stats.xml b/jetty-server/src/main/config/etc/jetty-stats.xml
index f8fd0ba9dff..8ba66e60d70 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 23b0f16237a..a6289c4174b 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 70650b7a04c..96589551295 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 @@ public class StatisticsHandler extends HandlerWrapper implements Graceful
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 class StatisticsHandler extends HandlerWrapper implements Graceful
_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 class StatisticsHandler extends HandlerWrapper implements Graceful
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 @@ public class StatisticsHandler extends HandlerWrapper implements Graceful
* 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 setAsyncGraceful(boolean asyncGraceful)
+ public void setGracefulShutdownWaitsForRequests(boolean gracefulShutdownWaitsForRequests)
{
- this.asyncGraceful = asyncGraceful;
+ _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()
+ */
+ @ManagedAttribute("if graceful shutdown will wait for all requests")
+ public boolean getGracefulShutdownWaitsForRequests()
+ {
+ 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 c4bbc702cf9..7ce2b5b0718 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 class StatisticsHandlerTest
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 class StatisticsHandlerTest
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