Class GracefulShutdownHandler

  • All Implemented Interfaces:

    public class GracefulShutdownHandler
    extends Object
    implements HttpHandler
    Handler that allows for graceful server shutdown. Basically it provides a way to prevent the server from accepting new requests, and wait for existing requests to complete.

    The handler itself does not shut anything down.

    Import: The thread safety semantics of the handler are very important. Don't touch anything unless you know what you are doing.

    Stuart Douglas
    • Constructor Detail

      • GracefulShutdownHandler

        public GracefulShutdownHandler​(HttpHandler next)
    • Method Detail

      • shutdown

        public void shutdown()
      • start

        public void start()
      • awaitShutdown

        public boolean awaitShutdown​(long millis)
                              throws InterruptedException
        Waits a set length of time for the handler to shut down
        millis - The length of time
        true If the handler successfully shut down
      • addShutdownListener

        public void addShutdownListener​(GracefulShutdownHandler.ShutdownListener shutdownListener)
        Adds a shutdown listener that will be invoked when all requests have finished. If all requests have already been finished the listener will be invoked immediately.
        shutdownListener - The shutdown listener