Class AvailabilityStatusProvider

java.lang.Object
com.github.jpmsilva.jsystemd.DelayableHealthProvider
com.github.jpmsilva.jsystemd.spring.AvailabilityStatusProvider
All Implemented Interfaces:
HealthProvider, StatusProvider, EventListener, ApplicationListener<AvailabilityChangeEvent<?>>

public class AvailabilityStatusProvider extends DelayableHealthProvider implements StatusProvider, ApplicationListener<AvailabilityChangeEvent<?>>
Provides the availability of the application, as Spring Boot reports it with its 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
  • Constructor Details

    • AvailabilityStatusProvider

      public AvailabilityStatusProvider(boolean health)
      Create a new AvailabilityStatusProvider.
      Parameters:
      health - true to report the application as unhealthy while its liveness state is broken
  • Method Details