Interface HealthChecker
- All Known Subinterfaces:
ListenableHealthChecker
- All Known Implementing Classes:
SettableHealthChecker
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
Determines whether the
Server
is healthy. All registered HealthChecker
s must return
true
for the Server
to be considered healthy.-
Method Summary
Modifier and TypeMethodDescriptionboolean
Returnstrue
if and only if theServer
is healthy.static ListenableHealthChecker
of
(Supplier<? extends CompletionStage<HealthCheckStatus>> healthChecker, Duration fallbackTtl) Returns a newly createdListenableHealthChecker
that invokes the specified health checker function repetitively on an arbitraryEventExecutor
fromCommonPools.workerGroup()
.static ListenableHealthChecker
of
(Supplier<? extends CompletionStage<HealthCheckStatus>> healthChecker, Duration fallbackTtl, EventExecutor eventExecutor) Returns a newly createdListenableHealthChecker
that invokes the specified health checker function repetitively on the specifiedEventExecutor
.static HealthChecker
ofCpu
(double targetSystemCpuUsage, double targetProcessCpuUsage) Creates a new instance ofHealthChecker
which reports health based on cpu usage reported byOperatingSystemMXBean
.
-
Method Details
-
of
@UnstableApi static ListenableHealthChecker of(Supplier<? extends CompletionStage<HealthCheckStatus>> healthChecker, Duration fallbackTtl) Returns a newly createdListenableHealthChecker
that invokes the specified health checker function repetitively on an arbitraryEventExecutor
fromCommonPools.workerGroup()
.- Parameters:
healthChecker
- ASupplier
that performs a health check asynchronously and returns a future that will complete with aHealthCheckStatus
.HealthCheckStatus.ttlMillis()
determines the delay before the next health check. If the future completed exceptionally, the specifiedfallbackTtl
will be used instead to determine the delay.Supplier
should avoid returning null or throwing exception. TheCompletionStage
fromSupplier
should avoid completing with null result or failing.fallbackTtl
- The amount of delay between each health check if the previous health check failed unexpectedly so it's not possible to determine how long we have to wait until the next health check.- See Also:
-
of
@UnstableApi static ListenableHealthChecker of(Supplier<? extends CompletionStage<HealthCheckStatus>> healthChecker, Duration fallbackTtl, EventExecutor eventExecutor) Returns a newly createdListenableHealthChecker
that invokes the specified health checker function repetitively on the specifiedEventExecutor
.- Parameters:
healthChecker
- ASupplier
that performs a health check asynchronously and returns a future that will complete with aHealthCheckStatus
.HealthCheckStatus.ttlMillis()
determines the delay before the next health check. If the future completed exceptionally, the specifiedfallbackTtl
will be used instead to determine the delay.Supplier
should avoid returning null or throwing exception. TheCompletionStage
fromSupplier
should avoid completing with null result or failing.fallbackTtl
- The amount of delay between each health check if the previous health check failed unexpectedly so it's not possible to determine how long we have to wait until the next health check.eventExecutor
- TheEventExecutor
that will invoke the specifiedhealthChecker
.
-
ofCpu
Creates a new instance ofHealthChecker
which reports health based on cpu usage reported byOperatingSystemMXBean
. Both system and process cpu usage must be (inclusive) lower than the specified threshold in order for theHealthChecker
to report as healthy. If theHealthChecker
is unable to find a suitableOperatingSystemMXBean
, an exception is thrown on construction.- Parameters:
targetSystemCpuUsage
- Target system CPU usage as a percentage (0 - 1).targetProcessCpuUsage
- Target process CPU usage as a percentage (0 - 1).- Returns:
- an instance of
HealthChecker
configured with the provided CPU usage targets.
-
isHealthy
boolean isHealthy()Returnstrue
if and only if theServer
is healthy.
-