ShutdownHandler implements ExchangeCompletionListener { boolean handle(HttpServerExchange exchange) { activeRequests.getAndIncrement(); exchange.addExchangeCompleteListener(this); if (shutdown) { logger.warn("reject request due to server is shutting down, requestURL={}", exchange.getRequestURL()); exchange.setPersistent(false); exchange.setStatusCode(StatusCodes.SERVICE_UNAVAILABLE); exchange.endExchange(); return true; } return false; }  @Override void exchangeEvent(HttpServerExchange exchange, NextListener next);  }
@Test void handle() { assertThat(handler.handle(exchange)).isFalse(); handler.exchangeEvent(null, () -> { }); assertThat(handler.activeRequests).hasValue(0); }