-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathHealthOutcome.java
More file actions
25 lines (21 loc) · 855 Bytes
/
Copy pathHealthOutcome.java
File metadata and controls
25 lines (21 loc) · 855 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package com.retailsvc.http;
import java.util.List;
import java.util.Objects;
/**
* Carrier for the {@link Handlers#healthHandler health handler} response.
*
* <p>Overall health is derived from {@link #dependencies()}: an empty list reports as {@code "Up"};
* otherwise the outcome is {@code "Up"} only when every dependency is up. Callers describe their
* dependencies and the library aggregates.
*
* @param dependencies per-dependency statuses; {@code null} is normalised to an empty list
*/
public record HealthOutcome(List<Dependency> dependencies) {
public HealthOutcome {
dependencies = List.copyOf(Objects.requireNonNullElse(dependencies, List.of()));
}
/** {@code true} when every dependency is up (vacuously true for an empty list). */
public boolean up() {
return dependencies.stream().allMatch(Dependency::up);
}
}