Issue #5105 - change asyncGraceful to gracefulShutdownWaitsForRequests
Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
This commit is contained in:
parent
8edb7682cd
commit
a9c90d3309
|
@ -6,7 +6,7 @@
|
||||||
<Call name="insertHandler">
|
<Call name="insertHandler">
|
||||||
<Arg>
|
<Arg>
|
||||||
<New id="StatsHandler" class="org.eclipse.jetty.server.handler.StatisticsHandler">
|
<New id="StatsHandler" class="org.eclipse.jetty.server.handler.StatisticsHandler">
|
||||||
<Set name="asyncGraceful"><Property name="jetty.statistics.asyncGraceful" default="true"/></Set>
|
<Set name="gracefulShutdownWaitsForRequests"><Property name="jetty.statistics.gracefulShutdownWaitsForRequests" default="true"/></Set>
|
||||||
</New>
|
</New>
|
||||||
</Arg>
|
</Arg>
|
||||||
</Call>
|
</Call>
|
||||||
|
|
|
@ -19,4 +19,4 @@ jetty.webapp.addServerClasses+=,-org.eclipse.jetty.servlet.StatisticsServlet
|
||||||
[ini-template]
|
[ini-template]
|
||||||
|
|
||||||
## If the Graceful shutdown should wait for async requests as well as the currently dispatched ones.
|
## If the Graceful shutdown should wait for async requests as well as the currently dispatched ones.
|
||||||
# jetty.statistics.asyncGraceful=true
|
# jetty.statistics.gracefulShutdownWaitsForRequests=true
|
||||||
|
|
|
@ -67,7 +67,7 @@ public class StatisticsHandler extends HandlerWrapper implements Graceful
|
||||||
private final LongAdder _responses5xx = new LongAdder();
|
private final LongAdder _responses5xx = new LongAdder();
|
||||||
private final LongAdder _responsesTotalBytes = new LongAdder();
|
private final LongAdder _responsesTotalBytes = new LongAdder();
|
||||||
|
|
||||||
private boolean asyncGraceful = true;
|
private boolean _gracefulShutdownWaitsForRequests = true;
|
||||||
|
|
||||||
private final Graceful.Shutdown _shutdown = new Graceful.Shutdown()
|
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()
|
private final AsyncListener _onCompletion = new AsyncListener()
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public void onStartAsync(AsyncEvent event) throws IOException
|
public void onStartAsync(AsyncEvent event)
|
||||||
{
|
{
|
||||||
event.getAsyncContext().addListener(this);
|
event.getAsyncContext().addListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTimeout(AsyncEvent event) throws IOException
|
public void onTimeout(AsyncEvent event)
|
||||||
{
|
{
|
||||||
_expires.increment();
|
_expires.increment();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onError(AsyncEvent event) throws IOException
|
public void onError(AsyncEvent event)
|
||||||
{
|
{
|
||||||
_errors.increment();
|
_errors.increment();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onComplete(AsyncEvent event) throws IOException
|
public void onComplete(AsyncEvent event)
|
||||||
{
|
{
|
||||||
HttpChannelState state = ((AsyncContextEvent)event).getHttpChannelState();
|
HttpChannelState state = ((AsyncContextEvent)event).getHttpChannelState();
|
||||||
|
|
||||||
|
@ -113,8 +113,7 @@ public class StatisticsHandler extends HandlerWrapper implements Graceful
|
||||||
|
|
||||||
_asyncWaitStats.decrement();
|
_asyncWaitStats.decrement();
|
||||||
|
|
||||||
// If we have no more dispatches, should we signal shutdown?
|
if (numRequests == 0 && _gracefulShutdownWaitsForRequests)
|
||||||
if (numRequests == 0 && asyncGraceful)
|
|
||||||
{
|
{
|
||||||
FutureCallback shutdown = _shutdown.get();
|
FutureCallback shutdown = _shutdown.get();
|
||||||
if (shutdown != null)
|
if (shutdown != null)
|
||||||
|
@ -207,9 +206,7 @@ public class StatisticsHandler extends HandlerWrapper implements Graceful
|
||||||
if (shutdown != null)
|
if (shutdown != null)
|
||||||
{
|
{
|
||||||
response.flushBuffer();
|
response.flushBuffer();
|
||||||
|
if (_gracefulShutdownWaitsForRequests ? (numRequests == 0) : (numDispatches == 0))
|
||||||
// If we either have no more requests or dispatches, we can complete shutdown.
|
|
||||||
if (asyncGraceful ? (numRequests == 0) : (numDispatches == 0))
|
|
||||||
shutdown.succeeded();
|
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
|
* 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
|
* async requests which are not currently dispatched, or whether it should only wait for all the
|
||||||
* actively dispatched requests to complete.
|
* 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -431,7 +431,7 @@ public class StatisticsHandlerTest
|
||||||
CyclicBarrier barrier = new CyclicBarrier(3);
|
CyclicBarrier barrier = new CyclicBarrier(3);
|
||||||
final AtomicReference<AsyncContext> asyncHolder = new AtomicReference<>();
|
final AtomicReference<AsyncContext> asyncHolder = new AtomicReference<>();
|
||||||
final CountDownLatch dispatched = new CountDownLatch(1);
|
final CountDownLatch dispatched = new CountDownLatch(1);
|
||||||
_statsHandler.setAsyncGraceful(true);
|
_statsHandler.setGracefulShutdownWaitsForRequests(true);
|
||||||
_statsHandler.setHandler(new AbstractHandler()
|
_statsHandler.setHandler(new AbstractHandler()
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
|
@ -487,7 +487,7 @@ public class StatisticsHandlerTest
|
||||||
CyclicBarrier barrier = new CyclicBarrier(3);
|
CyclicBarrier barrier = new CyclicBarrier(3);
|
||||||
final AtomicReference<AsyncContext> asyncHolder = new AtomicReference<>();
|
final AtomicReference<AsyncContext> asyncHolder = new AtomicReference<>();
|
||||||
final CountDownLatch dispatched = new CountDownLatch(1);
|
final CountDownLatch dispatched = new CountDownLatch(1);
|
||||||
_statsHandler.setAsyncGraceful(false);
|
_statsHandler.setGracefulShutdownWaitsForRequests(false);
|
||||||
_statsHandler.setHandler(new AbstractHandler()
|
_statsHandler.setHandler(new AbstractHandler()
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in New Issue