Package org.apache.camel.health
Class HealthCheckHelper
- java.lang.Object
-
- org.apache.camel.health.HealthCheckHelper
-
public final class HealthCheckHelper extends Object
Helper for invokingHealthCheck
's. The helper will look up theHealthCheckRegistry
fromCamelContext
and gather all the registeredHealthCheck
s and invoke them and gather their results. The helper allows filtering out unwanted health checks usingPredicate
or to invoke only readiness or liveness checks.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static HealthCheck
getHealthCheck(CamelContext context, String id)
Gets theHealthCheck
by the given id (will resolve from classpath if necessary)static <T extends HealthCheck>
TgetHealthCheck(CamelContext context, String id, Class<T> type)
Gets theHealthCheck
by the given id (will resolve from classpath if necessary)static HealthCheckRegistry
getHealthCheckRegistry(CamelContext context)
Gets theHealthCheckRegistry
.static HealthCheckRepository
getHealthCheckRepository(CamelContext context, String id)
Gets theHealthCheckRepository
by the given id (will resolve from classpath if necessary)static <T extends HealthCheckRepository>
TgetHealthCheckRepository(CamelContext context, String id, Class<T> type)
Gets theHealthCheckRepository
by the given id (will resolve from classpath if necessary)static Collection<HealthCheck.Result>
invoke(CamelContext camelContext)
Invokes the checks and returns a collection of results.static Optional<HealthCheck.Result>
invoke(CamelContext camelContext, String id, Map<String,Object> options)
Invoke a check by id.static Collection<HealthCheck.Result>
invoke(CamelContext camelContext, Function<HealthCheck,Map<String,Object>> optionsSupplier)
Invokes the checks and returns a collection of results.static Collection<HealthCheck.Result>
invoke(CamelContext camelContext, Function<HealthCheck,Map<String,Object>> optionsSupplier, Predicate<HealthCheck> filter)
Invokes the checks and returns a collection of results.static Collection<HealthCheck.Result>
invoke(CamelContext camelContext, Predicate<HealthCheck> filter)
Invokes the checks and returns a collection of results.static Collection<HealthCheck.Result>
invokeLiveness(CamelContext camelContext)
Invokes the liveness checks and returns a collection of results.static Collection<HealthCheck.Result>
invokeReadiness(CamelContext camelContext)
Invokes the readiness checks and returns a collection of results.static boolean
isResultsUp(Collection<HealthCheck.Result> results, boolean readiness)
Checks the overall status of the results.
-
-
-
Method Detail
-
invoke
public static Collection<HealthCheck.Result> invoke(CamelContext camelContext)
Invokes the checks and returns a collection of results.
-
invokeReadiness
public static Collection<HealthCheck.Result> invokeReadiness(CamelContext camelContext)
Invokes the readiness checks and returns a collection of results.
-
invokeLiveness
public static Collection<HealthCheck.Result> invokeLiveness(CamelContext camelContext)
Invokes the liveness checks and returns a collection of results.
-
invoke
public static Collection<HealthCheck.Result> invoke(CamelContext camelContext, Function<HealthCheck,Map<String,Object>> optionsSupplier)
Invokes the checks and returns a collection of results.
-
invoke
public static Collection<HealthCheck.Result> invoke(CamelContext camelContext, Predicate<HealthCheck> filter)
Invokes the checks and returns a collection of results.
-
invoke
public static Collection<HealthCheck.Result> invoke(CamelContext camelContext, Function<HealthCheck,Map<String,Object>> optionsSupplier, Predicate<HealthCheck> filter)
Invokes the checks and returns a collection of results.- Parameters:
camelContext
- the camel context.optionsSupplier
- a supplier for options.filter
- filter to exclude some checks.
-
invoke
public static Optional<HealthCheck.Result> invoke(CamelContext camelContext, String id, Map<String,Object> options)
Invoke a check by id.- Parameters:
camelContext
- the camel context.id
- the check id.options
- the check options.- Returns:
- an optional
HealthCheck.Result
.
-
getHealthCheckRegistry
public static HealthCheckRegistry getHealthCheckRegistry(CamelContext context)
Gets theHealthCheckRegistry
.- Parameters:
context
- the camel context- Returns:
- the health check registry, or null if health-check is not enabled.
-
getHealthCheck
public static HealthCheck getHealthCheck(CamelContext context, String id)
Gets theHealthCheck
by the given id (will resolve from classpath if necessary)- Parameters:
context
- the camel contextid
- the id of the health check- Returns:
- the health check, or null if no health check exists with this id
-
getHealthCheck
public static <T extends HealthCheck> T getHealthCheck(CamelContext context, String id, Class<T> type)
Gets theHealthCheck
by the given id (will resolve from classpath if necessary)- Parameters:
context
- the camel contextid
- the id of the health checktype
- the expected type of the health check repository- Returns:
- the health check, or null if no health check exists with this id
-
getHealthCheckRepository
public static HealthCheckRepository getHealthCheckRepository(CamelContext context, String id)
Gets theHealthCheckRepository
by the given id (will resolve from classpath if necessary)- Parameters:
context
- the camel contextid
- the id of the health check repository- Returns:
- the health check repository, or null if no health check repository exists with this id
-
getHealthCheckRepository
public static <T extends HealthCheckRepository> T getHealthCheckRepository(CamelContext context, String id, Class<T> type)
Gets theHealthCheckRepository
by the given id (will resolve from classpath if necessary)- Parameters:
context
- the camel contextid
- the id of the health check repositorytype
- the expected type of the health check repository- Returns:
- the health check repository, or null if no health check repository exists with this id
-
isResultsUp
public static boolean isResultsUp(Collection<HealthCheck.Result> results, boolean readiness)
Checks the overall status of the results.- Parameters:
results
- the results from the invoked health checksreadiness
- readiness or liveness mode- Returns:
- true if up, or false if down
-
-