1 package lv.id.jc.piglatin.actuator; 2 3 import java.util.function.IntFunction; 4 import java.util.function.IntSupplier; 5 6 import org.springframework.boot.actuate.health.Health; 7 import org.springframework.boot.actuate.health.HealthIndicator; 8 import org.springframework.stereotype.Component; 9 10 11 @Component 12 public class BlogHealthIndicator implements HealthIndicator { 13 private final IntFunction<Health> healthFunction; 14 private final IntSupplier statusCodeSupplier; 15 16 public BlogHealthIndicator(IntSupplier statusCodeSupplier, IntFunction<Health> healthFunction) { 17 this.healthFunction = healthFunction; 18 this.statusCodeSupplier = statusCodeSupplier; 19 } 20 21 @Override 22 public Health health() { 23 try { 24 return healthFunction.apply(statusCodeSupplier.getAsInt()); 25 } catch (RuntimeException e) { 26 return Health.down(e).withException(e.getCause()).build(); 27 } 28 } 29 }