Class DelayableHealthProvider

java.lang.Object
com.github.jpmsilva.jsystemd.DelayableHealthProvider
All Implemented Interfaces:
HealthProvider
Direct Known Subclasses:
ActuatorHealthStatusProvider, AvailabilityStatusProvider, FileDescriptorStatusProvider, HikariStatusProvider

public abstract class DelayableHealthProvider extends Object implements HealthProvider
Base class for the health providers that support delaying their unhealthy state: while the delay has not elapsed since the application became unhealthy, it is reported as healthy, so that the systemd watchdog does not restart it on short outages.

Only health providers whose unhealthy state may resolve by itself should extend this class, such as those that depend on external systems. Those whose unhealthy state never resolves by itself, such as a deadlock, should implement HealthProvider directly instead, as delaying a restart would only delay the recovery.

Subclasses implement evaluateHealth(), which provides the actual health, without the delay. There is no delay until one is set with setUnhealthyDelay(Duration). The delay is measured with System.nanoTime(), so that changes of the system clock, such as those made to synchronize it, neither shorten nor lengthen it.

Author:
Christian Lorenz, Joao Silva
  • Constructor Details

    • DelayableHealthProvider

      protected DelayableHealthProvider()
      Create a new DelayableHealthProvider, without delay.
  • Method Details

    • getUnhealthyDelay

      public @Nullable Duration getUnhealthyDelay()
      Returns the delay before the unhealthy state is reported.
      Returns:
      the delay, or null if there is no delay
    • setUnhealthyDelay

      public void setUnhealthyDelay(@Nullable Duration unhealthyDelay)
      Sets the delay before the unhealthy state is reported.
      Parameters:
      unhealthyDelay - the delay, or null for no delay
      Throws:
      IllegalArgumentException - if the delay is negative
    • health

      public final HealthProvider.Health health()
      Provides the health of the application, reporting it as healthy while it has been unhealthy for less than the delay.
      Specified by:
      health in interface HealthProvider
      Returns:
      the health of the application, with the delay applied
    • evaluateHealth

      protected abstract HealthProvider.Health evaluateHealth()
      Provides the actual health of the application, without the delay.
      Returns:
      the actual health of the application