Eclipse MicroProfile Metrics批注@Timed线程在Payara上安全吗?

由于@Timed批注不适用于我的基于SOAP的Web服务,因此我编写了SOAP处理程序以能够自己测量Web服务的持续时间。 我想知道此解决方案是否是线程安全的。

我的SOAP处理程序的源代码:

package nl.tent.laboratory.emp.metrics;

import javax.inject.Inject;
import javax.xml.namespace.QName;
import javax.xml.ws.handler.MessageContext;
import javax.xml.ws.handler.soap.SOAPMessageContext;
import org.eclipse.microprofile.metrics.MetricID;
import org.eclipse.microprofile.metrics.MetricRegistry;
import org.eclipse.microprofile.metrics.Timer;

/**
 * Deze klasse klokt de web service calls.
 *
 * Daar de eclipse microProfile Metrics annotatie @Timed niet werkt in combinatie met de annotatie @WebService klokken we zelf.
 */
public class TimerSOAPHandler extends AbstractGenericSOAPHandler {

    @Inject
    MetricRegistry metricRegistry;

    public TimerSOAPHandler() {
        super();
    }

    @Override
    public boolean handleMessage(SOAPMessageContext context) {
        // Bij het inkomende bericht (request) wordt de tijdsmeting gestart.
        if (isInbound(context)) {
            startTiming(context);
        }
        // Bij het uitgaande bericht (response) wordt de tijdsmeting gestopt.
        if (isOutbound(context)) {
            stopTiming(context);
        }

        return true;
    }

    @Override
    public boolean handleFault(SOAPMessageContext context) {
        // Bij het inkomende bericht (request) wordt de tijdsmeting gestart.
        if (isInbound(context)) {
            startTiming(context);
        }
        // Bij het uitgaande bericht (response) wordt de tijdsmeting gestopt.
        if (isOutbound(context)) {
            stopTiming(context);
        }

        return true;
    }

    private void startTiming(SOAPMessageContext context) {
        String serviceName = ((QName) context.get(MessageContext.WSDL_SERVICE)).toString();
        String operationName = ((QName) context.get(MessageContext.WSDL_OPERATION)).getLocalPart();

        Timer timer = metricRegistry.timer(serviceName + "_" + operationName + "_timer");

        Timer.Context timerContext = timer.time(); // start
    }

    private void stopTiming(SOAPMessageContext context) {
        String serviceName = ((QName) context.get(MessageContext.WSDL_SERVICE)).toString();
        String operationName = ((QName) context.get(MessageContext.WSDL_OPERATION)).getLocalPart();

        MetricID metricID = new MetricID(serviceName + "_" + operationName + "_timer");

        Timer timer = metricRegistry.getTimers().get(metricID);

        Timer.Context timerContext = timer.time();
        timerContext.stop();
    }

}

在此期间,@ Timed批注正在运行,我希望使用@Timed批注。 但是,我不知道这个(@Timed)是否是线程安全的。

我使用eclipse microProfile Metrics的Payara实现。

SophiaBJ 回答:Eclipse MicroProfile Metrics批注@Timed线程在Payara上安全吗?

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/2942495.html

大家都在问