org.eclipse.microprofile.health.spi.HealthCheckResponseProvider Java Examples

The following examples show how to use org.eclipse.microprofile.health.spi.HealthCheckResponseProvider. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HealthCheckResponse.java    From microprofile-health with Apache License 2.0 6 votes vote down vote up
private static HealthCheckResponseProvider getProvider() {
    if (provider == null) {
        synchronized (HealthCheckResponse.class) {
            if (provider != null) {
                return provider;
            }

            HealthCheckResponseProvider newInstance = find(HealthCheckResponseProvider.class);

            if (newInstance == null) {
                throw new IllegalStateException("No HealthCheckResponseProvider implementation found!");
            }

            provider = newInstance;
        }
    }
    return provider;
}
 
Example #2
Source File: SmallRyeHealthRecorder.java    From quarkus with Apache License 2.0 5 votes vote down vote up
public void registerHealthCheckResponseProvider(Class<? extends HealthCheckResponseProvider> providerClass) {
    try {
        HealthCheckResponse.setResponseProvider(providerClass.getConstructor().newInstance());
    } catch (Exception e) {
        throw new IllegalStateException(
                "Unable to instantiate service " + providerClass + " using the no-arg constructor.");
    }
}
 
Example #3
Source File: SmallRyeHealthProcessor.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@BuildStep
@Record(ExecutionTime.STATIC_INIT)
@SuppressWarnings("unchecked")
void build(SmallRyeHealthRecorder recorder, RecorderContext recorderContext,
        BuildProducer<FeatureBuildItem> feature,
        BuildProducer<AdditionalBeanBuildItem> additionalBean,
        BuildProducer<BeanDefiningAnnotationBuildItem> beanDefiningAnnotation,
        BuildProducer<NotFoundPageDisplayableEndpointBuildItem> displayableEndpoints,
        LaunchModeBuildItem launchModeBuildItem) throws IOException {

    feature.produce(new FeatureBuildItem(Feature.SMALLRYE_HEALTH));

    // add health endpoints to not found page
    if (launchModeBuildItem.getLaunchMode().isDevOrTest()) {
        displayableEndpoints.produce(new NotFoundPageDisplayableEndpointBuildItem(health.rootPath));
        displayableEndpoints.produce(new NotFoundPageDisplayableEndpointBuildItem(health.rootPath + health.livenessPath));
        displayableEndpoints
                .produce(new NotFoundPageDisplayableEndpointBuildItem(health.rootPath + health.readinessPath));
        displayableEndpoints.produce(new NotFoundPageDisplayableEndpointBuildItem(health.rootPath + health.groupPath));
    }

    // Discover the beans annotated with @Health, @Liveness, @Readiness, @HealthGroup and @HealthGroups even if no scope is defined
    beanDefiningAnnotation.produce(new BeanDefiningAnnotationBuildItem(HEALTH));
    beanDefiningAnnotation.produce(new BeanDefiningAnnotationBuildItem(LIVENESS));
    beanDefiningAnnotation.produce(new BeanDefiningAnnotationBuildItem(READINESS));
    beanDefiningAnnotation.produce(new BeanDefiningAnnotationBuildItem(HEALTH_GROUP));
    beanDefiningAnnotation.produce(new BeanDefiningAnnotationBuildItem(HEALTH_GROUPS));

    // Add additional beans
    additionalBean.produce(new AdditionalBeanBuildItem(SmallRyeHealthReporter.class));

    // Make ArC discover @HealthGroup as a qualifier
    additionalBean.produce(new AdditionalBeanBuildItem(HealthGroup.class));

    // Discover and register the HealthCheckResponseProvider
    Set<String> providers = ServiceUtil.classNamesNamedIn(getClass().getClassLoader(),
            "META-INF/services/" + HealthCheckResponseProvider.class.getName());

    if (providers.isEmpty()) {
        throw new IllegalStateException("No HealthCheckResponseProvider implementation found.");
    } else if (providers.size() > 1) {
        throw new IllegalStateException(
                String.format("Multiple HealthCheckResponseProvider implementations found: %s", providers));
    }

    recorder.registerHealthCheckResponseProvider(
            (Class<? extends HealthCheckResponseProvider>) recorderContext.classProxy(providers.iterator().next()));
}
 
Example #4
Source File: HealthCheckResponse.java    From microprofile-health with Apache License 2.0 2 votes vote down vote up
/**
 * Used by OSGi environment where the service loader pattern is not supported.
 *
 * @param provider the provider instance to use.
 */
public static void setResponseProvider(HealthCheckResponseProvider provider) {
    HealthCheckResponse.provider = provider;
}