Package io.undertow.server.handlers
Class GracefulShutdownHandler
- java.lang.Object
-
- io.undertow.server.handlers.GracefulShutdownHandler
-
- All Implemented Interfaces:
HttpHandler
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.
- Author:
- Stuart Douglas
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
GracefulShutdownHandler.ShutdownListener
A listener which can be registered with the handler to be notified when all pending requests have finished.
-
Constructor Summary
Constructors Constructor Description GracefulShutdownHandler(HttpHandler next)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addShutdownListener(GracefulShutdownHandler.ShutdownListener shutdownListener)
Adds a shutdown listener that will be invoked when all requests have finished.void
awaitShutdown()
Waits for the handler to shutdown.boolean
awaitShutdown(long millis)
Waits a set length of time for the handler to shut downvoid
handleRequest(HttpServerExchange exchange)
Handle the request.void
shutdown()
void
start()
-
-
-
Constructor Detail
-
GracefulShutdownHandler
public GracefulShutdownHandler(HttpHandler next)
-
-
Method Detail
-
handleRequest
public void handleRequest(HttpServerExchange exchange) throws Exception
Description copied from interface:HttpHandler
Handle the request.- Specified by:
handleRequest
in interfaceHttpHandler
- Parameters:
exchange
- the HTTP request/response exchange- Throws:
Exception
-
shutdown
public void shutdown()
-
start
public void start()
-
awaitShutdown
public void awaitShutdown() throws InterruptedException
Waits for the handler to shutdown.- Throws:
InterruptedException
-
awaitShutdown
public boolean awaitShutdown(long millis) throws InterruptedException
Waits a set length of time for the handler to shut down- Parameters:
millis
- The length of time- Returns:
true
If the handler successfully shut down- Throws:
InterruptedException
-
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.- Parameters:
shutdownListener
- The shutdown listener
-
-