use of org.eclipse.microprofile.health.HealthCheck in project wildfly-swarm by wildfly-swarm.
the class HealthExtension method afterDeploymentValidation.
/**
* Instantiates <em>unmanaged instances</em> of HealthCheckProcedure and
* handle manually their CDI creation lifecycle.
* Add them to the {@link Monitor}.
*/
private void afterDeploymentValidation(@Observes final AfterDeploymentValidation abd, BeanManager beanManager) {
try {
for (AnnotatedType delegate : delegates) {
Unmanaged<HealthCheck> unmanagedHealthCheck = new Unmanaged<HealthCheck>(beanManager, delegate.getJavaClass());
Unmanaged.UnmanagedInstance<HealthCheck> healthCheckInstance = unmanagedHealthCheck.newInstance();
HealthCheck healthCheck = healthCheckInstance.produce().inject().postConstruct().get();
healthChecks.add(healthCheck);
healthCheckInstances.add(healthCheckInstance);
monitor.registerHealthBean(healthCheck);
log.info(">> Added health bean impl " + healthCheck);
}
// we don't need the references anymore
delegates.clear();
} catch (Exception e) {
throw new RuntimeException("Failed to register health bean", e);
}
}
use of org.eclipse.microprofile.health.HealthCheck in project wildfly by wildfly.
the class CDIExtension method addHealthChecks.
private void addHealthChecks(AnnotationLiteral qualifier, BiConsumer<HealthCheck, ClassLoader> healthFunction, List<HealthCheck> healthChecks) {
for (HealthCheck healthCheck : instance.select(HealthCheck.class, qualifier)) {
healthFunction.accept(healthCheck, module.getClassLoader());
healthChecks.add(healthCheck);
}
}
use of org.eclipse.microprofile.health.HealthCheck in project wildfly by wildfly.
the class CDIExtension method removeHealthCheck.
private void removeHealthCheck(List<HealthCheck> healthChecks, Consumer<HealthCheck> healthFunction) {
for (HealthCheck healthCheck : healthChecks) {
healthFunction.accept(healthCheck);
instance.destroy(healthCheck);
}
healthChecks.clear();
}
use of org.eclipse.microprofile.health.HealthCheck in project Payara by payara.
the class HealthCDIExtension method registerHealthCheck.
private void registerHealthCheck(Bean<?> bean, BeanManager beanManager) {
HealthCheck healthCheck = (HealthCheck) beanManager.getReference(bean, HealthCheck.class, beanManager.createCreationalContext(bean));
healthService.registerHealthCheck(appName, healthCheck, HealthCheckType.fromQualifiers(bean.getQualifiers()));
healthService.registerClassLoader(appName, healthCheck.getClass().getClassLoader());
LOGGER.log(Level.INFO, "Registered {0} as a HealthCheck for app: {1}", new Object[] { bean.getBeanClass().getCanonicalName(), appName });
}
use of org.eclipse.microprofile.health.HealthCheck in project Payara by payara.
the class HealthCheckService method getCollectiveHealthChecks.
private Map<String, Set<HealthCheck>> getCollectiveHealthChecks(HealthCheckType type) {
final Map<String, Set<HealthCheck>> healthChecks;
if (type == READINESS) {
healthChecks = readiness;
} else if (type == LIVENESS) {
healthChecks = liveness;
} else if (type == STARTUP) {
healthChecks = startup;
} else {
// Make sure we do a deep-copy first, otherwise the first map the foreach consumer gets used on will be a
// shallow copy: the two maps will essentially be the same map (changes to one affecting the other)
healthChecks = readiness.entrySet().stream().collect(Collectors.toMap(entry -> entry.getKey(), entry -> new HashSet(entry.getValue())));
BiConsumer<? super String, ? super Set<HealthCheck>> mergeHealthCheckMap = (key, value) -> healthChecks.merge(key, value, (oldValue, newValue) -> {
oldValue.addAll(newValue);
return oldValue;
});
liveness.forEach(mergeHealthCheckMap);
startup.forEach(mergeHealthCheckMap);
}
return healthChecks;
}
Aggregations