Class ShutdownStatusProvider
- All Implemented Interfaces:
StatusProvider,EventListener,ApplicationListener<ContextClosedEvent>
StatusProvider that provides the stage the application is at while it shuts down, such as
Shutdown: waiting for active requests, so that a slow shutdown can be told apart from a hung one with systemctl status.
The stages follow the shutdown of the application context:
Shutdown: stopping, once the context starts closing, while its life cycle beans stop, such as message listeners;Shutdown: waiting for active requests, while the embedded web server waits for the requests being handled to complete, when it shuts down gracefully, as it does by default;Shutdown: destroying beans, once all life cycle beans are stopped, while the beans are destroyed, such as connection pools.
Every change of stage is sent to systemd right away. The status of the other providers keeps being sent while the application shuts down, such as the connections of the web server, which drop as the requests complete. Nothing is reported until the application starts shutting down, nor when the context is stopped without being closed, as when it is paused, or for a CRaC checkpoint.
The stages are followed by life cycle beans, which the autoconfiguration registers along with this provider.
- Author:
- Joao Silva
-
Constructor Summary
ConstructorsConstructorDescriptionShutdownStatusProvider(ApplicationContext context) Creates a new instance, which sends the status to systemd on every change of stage. -
Method Summary
Modifier and TypeMethodDescriptionReturns the life cycle bean that reports when the beans start being destroyed: it is stopped after every other life cycle bean, after which the context destroys its beans.voidReports that the application started shutting down, when the event is about its own application context: the events of child contexts, such as the one of the management endpoints when they use a port of their own, are also published to their parents.Returns the life cycle bean that reports when the web server starts waiting for the active requests: it is stopped right before the web server shuts down gracefully.status()Exposes status information to send to systemd.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.context.ApplicationListener
supportsAsyncExecution
-
Constructor Details
-
ShutdownStatusProvider
Creates a new instance, which sends the status to systemd on every change of stage.The created instance is not registered as a status provider of
Systemd.instance(): that is up to the caller.- Parameters:
context- the application context of the application, which this instance must be a bean of, rather than a parent or child context
-
-
Method Details
-
onApplicationEvent
Reports that the application started shutting down, when the event is about its own application context: the events of child contexts, such as the one of the management endpoints when they use a port of their own, are also published to their parents.Spring publishes the event first when closing a context, before it stops the life cycle beans and destroys the beans, despite the wording of the documentation of
ContextClosedEvent: the application is still running when the event is received.- Specified by:
onApplicationEventin interfaceApplicationListener<ContextClosedEvent>- Parameters:
event- the event of a context that started closing
-
requestsStage
Returns the life cycle bean that reports when the web server starts waiting for the active requests: it is stopped right before the web server shuts down gracefully. Register it as a bean, for the context to stop it.- Returns:
- the life cycle bean of the stage of waiting for the active requests
-
beansStage
Returns the life cycle bean that reports when the beans start being destroyed: it is stopped after every other life cycle bean, after which the context destroys its beans. Register it as a bean, for the context to stop it.- Returns:
- the life cycle bean of the stage of destroying the beans
-
status
Description copied from interface:StatusProviderExposes status information to send to systemd.- Specified by:
statusin interfaceStatusProvider- Returns:
- the string message to add to the service status
-