Package com.github.jpmsilva.jsystemd
Class DelayableHealthProvider
java.lang.Object
com.github.jpmsilva.jsystemd.DelayableHealthProvider
- All Implemented Interfaces:
HealthProvider
- Direct Known Subclasses:
ActuatorHealthStatusProvider,AvailabilityStatusProvider,FileDescriptorStatusProvider,HikariStatusProvider
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
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.github.jpmsilva.jsystemd.HealthProvider
HealthProvider.Health -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedCreate a new DelayableHealthProvider, without delay. -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract HealthProvider.HealthProvides the actual health of the application, without the delay.@Nullable DurationReturns the delay before the unhealthy state is reported.final HealthProvider.Healthhealth()Provides the health of the application, reporting it as healthy while it has been unhealthy for less than the delay.voidsetUnhealthyDelay(@Nullable Duration unhealthyDelay) Sets the delay before the unhealthy state is reported.
-
Constructor Details
-
DelayableHealthProvider
protected DelayableHealthProvider()Create a new DelayableHealthProvider, without delay.
-
-
Method Details
-
getUnhealthyDelay
Returns the delay before the unhealthy state is reported.- Returns:
- the delay, or
nullif there is no delay
-
setUnhealthyDelay
Sets the delay before the unhealthy state is reported.- Parameters:
unhealthyDelay- the delay, ornullfor no delay- Throws:
IllegalArgumentException- if the delay is negative
-
health
Provides the health of the application, reporting it as healthy while it has been unhealthy for less than the delay.- Specified by:
healthin interfaceHealthProvider- Returns:
- the health of the application, with the delay applied
-
evaluateHealth
Provides the actual health of the application, without the delay.- Returns:
- the actual health of the application
-