Java源码示例:io.smallrye.metrics.MetricsRequestHandler

示例1
private void addInterceptorBindings(@Observes BeforeBeanDiscovery bbd, BeanManager manager) {
    SmallRyeMetricsLogging.log.logSmallRyeMetricsVersion(getImplementationVersion().orElse("unknown"));

    String extensionName = MetricCdiInjectionExtension.class.getName();

    // It seems that fraction deployment module cannot be picked up as a CDI bean archive - see also SWARM-1725
    for (Class clazz : new Class[] {
            MetricProducer.class,
            MetricNameFactory.class,
            GaugeRegistrationInterceptor.class,
            MetricRegistries.class,

            MeteredInterceptor.class,
            CountedInterceptor.class,
            ConcurrentGaugeInterceptor.class,
            TimedInterceptor.class,
            SimplyTimedInterceptor.class,
            MetricsRequestHandler.class
    }) {
        bbd.addAnnotatedType(manager.createAnnotatedType(clazz), extensionName + "_" + clazz.getName());
    }
}
 
示例2
@BuildStep
void beans(BuildProducer<AdditionalBeanBuildItem> additionalBeans,
        BuildProducer<UnremovableBeanBuildItem> unremovableBeans) {
    additionalBeans.produce(new AdditionalBeanBuildItem(MetricProducer.class,
            MetricNameFactory.class,
            MetricRegistries.class,
            MetricsInterceptor.class,
            MeteredInterceptor.class,
            ConcurrentGaugeInterceptor.class,
            CountedInterceptor.class,
            TimedInterceptor.class,
            SimplyTimedInterceptor.class,
            MetricsRequestHandler.class));
    unremovableBeans.produce(new UnremovableBeanBuildItem(
            new UnremovableBeanBuildItem.BeanClassNameExclusion(MetricsRequestHandler.class.getName())));
}
 
示例3
@Override
public void handle(RoutingContext routingContext) {
    MetricsRequestHandler internalHandler = CDI.current().select(MetricsRequestHandler.class).get();
    HttpServerResponse response = routingContext.response();
    HttpServerRequest request = routingContext.request();
    Stream<String> acceptHeaders = request.headers().getAll("Accept").stream();

    try {
        internalHandler.handleRequest(request.path(), metricsPath, request.rawMethod(), acceptHeaders,
                (status, message, headers) -> {
                    response.setStatusCode(status);
                    headers.forEach(response::putHeader);
                    response.end(Buffer.buffer(message));
                });
    } catch (IOException e) {
        response.setStatusCode(503);
        response.end();
        LOGGER.error(e);
    }
}