public abstract class HikariHealthCheck extends java.lang.Object implements HealthCheck
import com.zaxxer.hikari.pool.HikariPool;
import ratpack.guice.Guice;
import ratpack.health.HealthCheckHandler;
import ratpack.hikari.HikariHealthCheck;
import ratpack.hikari.HikariModule;
import ratpack.test.embed.EmbeddedApp;
import javax.inject.Inject;
import static org.junit.Assert.assertEquals;
public class Example {
public static void main(String... args) throws Exception {
EmbeddedApp.of(s -> s
.registry(Guice.registry(b -> b
.module(HikariModule.class, hikariConfig -> {
hikariConfig.setDataSourceClassName("org.h2.jdbcx.JdbcDataSource");
hikariConfig.addDataSourceProperty("URL", "jdbc:h2:mem:dev"); // Use H2 in memory database
})
.bind(MyHealthCheck.class)
))
.handlers(chain -> chain
.get("health-checks", new HealthCheckHandler())
)
).test(httpClient -> assertEquals("my-health-check : HEALTHY", httpClient.getText("health-checks")));
}
static class MyHealthCheck extends HikariHealthCheck {
private HikariPool hikariPool;
@Inject
MyHealthCheck(HikariPool hikariPool) {
this.hikariPool = hikariPool;
}
@Override
public String getName() {
return "my-health-check";
}
@Override
public HikariPool getHikariPool() {
return hikariPool;
}
}
}
HealthCheck.Result| Constructor and Description |
|---|
HikariHealthCheck() |
| Modifier and Type | Method and Description |
|---|---|
Promise<HealthCheck.Result> |
check(Registry registry)
Checks the health of the component, providing a promise for the result.
|
abstract com.zaxxer.hikari.pool.HikariPool |
getHikariPool() |
java.lang.String |
getName()
The unique name of the health check.
|
java.time.Duration |
getTimeout() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitcheckAll, checkAll, ofpublic java.lang.String getName()
HealthCheckEach health check within an application must have a unique name.
getName in interface HealthCheckpublic java.time.Duration getTimeout()
public abstract com.zaxxer.hikari.pool.HikariPool getHikariPool()
public Promise<HealthCheck.Result> check(Registry registry)
HealthCheck
This method returns a promise to allow check implementations to be asynchronous.
If the implementation does not need to be asynchronous, the result can be returned via Promise.value(Object).
The registry argument is the server registry, from which other supporting objects can be obtained.
If this method throws an exception, it is logically equivalent to returned an unhealthy result with the thrown exception.
If the method returns a failed promise, it will be converted to a result using HealthCheck.Result.unhealthy(Throwable).
check in interface HealthCheckregistry - the server registry