Package ratpack.hikari
Class HikariHealthCheck
- java.lang.Object
-
- ratpack.hikari.HikariHealthCheck
-
- All Implemented Interfaces:
HealthCheck
public abstract class HikariHealthCheck extends java.lang.Object implements HealthCheck
Reports on the health of HikariCP JDBC connection pool.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; } } }
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface ratpack.health.HealthCheck
HealthCheck.Result
-
-
Constructor Summary
Constructors Constructor Description HikariHealthCheck()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description Promise<HealthCheck.Result>check(Registry registry)Checks the health of the component, providing a promise for the result.abstract com.zaxxer.hikari.pool.HikariPoolgetHikariPool()java.lang.StringgetName()The unique name of the health check.java.time.DurationgetTimeout()
-
-
-
Method Detail
-
getName
public java.lang.String getName()
Description copied from interface:HealthCheckThe unique name of the health check.Each health check within an application must have a unique name.
- Specified by:
getNamein interfaceHealthCheck- Returns:
- the name of the health check
-
getTimeout
public java.time.Duration getTimeout()
-
getHikariPool
public abstract com.zaxxer.hikari.pool.HikariPool getHikariPool()
-
check
public Promise<HealthCheck.Result> check(Registry registry)
Description copied from interface:HealthCheckChecks the health of the component, providing a promise for the result.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
registryargument 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).- Specified by:
checkin interfaceHealthCheck- Parameters:
registry- the server registry- Returns:
- a promise for the result
-
-