Class AvailabilityStatusProvider
- All Implemented Interfaces:
HealthProvider,StatusProvider,EventListener,ApplicationListener<AvailabilityChangeEvent<?>>
AvailabilityChangeEvent: as a StatusProvider,
whether it is live, and whether it is ready to accept traffic, such as Liveness: correct; readiness: accepting traffic, and as a
HealthProvider, for the systemd watchdog, reporting the application as unhealthy while its liveness is broken, if enabled.
Spring Boot reports the application as live and ready once it starts, and, for web applications, as refusing traffic once it starts shutting down.
The application can also report a change of availability itself, such as LivenessState.BROKEN when it can no longer recover, with
AvailabilityChangeEvent.publish(org.springframework.context.ApplicationEventPublisher, Object, AvailabilityState).
Each state is only reported once it is first published.
The health is enabled on its own, as it lets systemd restart the application: while disabled, the application is always healthy. When enabled, it is
unhealthy while the liveness state is LivenessState.BROKEN, which Spring Boot defines as a state the application cannot recover from, so that
restarting it is the way out; the state is reported in the health details, under livenessState. Unlike the health indicators of Spring Boot
Actuator, the liveness state does not depend on external systems. The unhealthy state can still be delayed, with
DelayableHealthProvider.setUnhealthyDelay(java.time.Duration), for applications that may report a broken liveness state and then recover from it.
- Author:
- Joao Silva
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.github.jpmsilva.jsystemd.HealthProvider
HealthProvider.Health -
Constructor Summary
ConstructorsConstructorDescriptionAvailabilityStatusProvider(boolean health) Create a new AvailabilityStatusProvider. -
Method Summary
Modifier and TypeMethodDescriptionprotected HealthProvider.HealthProvides the health of the application, without the delay: unhealthy while the liveness state is broken, if enabled.voidonApplicationEvent(AvailabilityChangeEvent<?> event) Keeps the latest liveness and readiness states of the event.status()Exposes status information to send to systemd.Methods inherited from class com.github.jpmsilva.jsystemd.DelayableHealthProvider
getUnhealthyDelay, health, setUnhealthyDelayMethods 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
-
AvailabilityStatusProvider
public AvailabilityStatusProvider(boolean health) Create a new AvailabilityStatusProvider.- Parameters:
health-trueto report the application as unhealthy while its liveness state is broken
-
-
Method Details
-
onApplicationEvent
Keeps the latest liveness and readiness states of the event. Other states are ignored.- Specified by:
onApplicationEventin interfaceApplicationListener<AvailabilityChangeEvent<?>>- Parameters:
event- the event of a change of availability
-
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
-
evaluateHealth
Provides the health of the application, without the delay: unhealthy while the liveness state is broken, if enabled.- Specified by:
evaluateHealthin classDelayableHealthProvider- Returns:
- the health of the application
-