Class SystemdLifecycle
java.lang.Object
com.github.jpmsilva.jsystemd.spring.SystemdLifecycle
- All Implemented Interfaces:
EventListener,ApplicationListener<ContextClosedEvent>
Sends the stopping signal to systemd when the application context starts closing, before its life cycle beans stop, such as the embedded web server,
which then waits for the active requests.
Stopping the context without closing it does not send it, as when the context is stopped or paused and started again afterwards, such as by the pause endpoint of Spring Cloud, or for a CRaC checkpoint: the application keeps running, and systemd keeps enforcing the watchdog.
Register it as a bean of the application context it is given, for that context to publish its events to it.
- Author:
- Joao Silva
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionSystemdLifecycle(ApplicationContext context) Creates a new instance, which sends the stopping signal withSystemd.instance()when the given context starts closing. -
Method Summary
Modifier and TypeMethodDescriptionvoidSends the stopping signal, 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.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
-
SystemdLifecycle
Creates a new instance, which sends the stopping signal withSystemd.instance()when the given context starts closing.- 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
Sends the stopping signal, 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
-