APISonar


org.eclipse.microprofile.metrics.Timer.time

> org > eclipse > microprofile > metrics > Timer > time
org APIs eclipse APIs microprofile APIs metrics APIs Timer APIs time APIs

Example 1
private <E extends Member & AnnotatedElement> Object timedCallable(InvocationContext context, E element) throws Exception {
        String name = resolver.timed(bean.getBeanClass(), element).metricName();
        Timer timer = (Timer) registry.getMetrics().get(name);
        if (timer == null)
            throw new IllegalStateException("No timer with name [" + name + "] found in registry [" + registry + "]");

        Timer.Context time = timer.time();
        try {
            return context.proceed();
        } finally {
            time.stop();
        }
    }
Example 2
private final Timer defaultMessageTimer;

    private void getDefaultMessageHandler(ServerRequest request,
                                          ServerResponse response) {
        Timer.Context timerContext = defaultMessageTimer.time();
        sendResponse(response, "World");
        response.whenSent()
                .thenAccept(res -> timerContext.stop());
    }
Example 3
void testContextTime() {
        TestClock clock = TestClock.create();
        Timer timer = HelidonTimer.create("application", meta, clock);
        Timer.Context context = timer.time();

        clock.add(1, TimeUnit.SECONDS);

        long diff = context.stop();

        assertThat(diff, is(TimeUnit.SECONDS.toNanos(1)));
    }
Example 4
protected void handleCreatedEvent(ExchangeCreatedEvent createdEvent) {
        String name = namingStrategy.getName(createdEvent.getExchange(), createdEvent.getExchange().getFromEndpoint());
        Tag[] tags = namingStrategy.getTags(createdEvent, createdEvent.getExchange().getFromEndpoint());
        Timer timer = getMetricRegistry().timer(name + PROCESSING_METRICS_SUFFIX, tags);
        createdEvent.getExchange().setProperty("eventTimer:" + name, timer);
        createdEvent.getExchange().setProperty("eventTimerContext:" + name, timer.time());
        exchangeRecorder.recordExchangeBegin();
    }
Example 5
private void handleStart(Exchange exchange, Metadata metadata, List<Tag> tags) {
        String propertyName = getPropertyName(metadata.getName());
        Context context = getTimerContextFromExchange(exchange, propertyName);
        if (context == null) {
            Timer timer = getOrRegisterMetric(metadata, tags);
            exchange.setProperty(propertyName, timer.time());
        } else {
            LOG.warn("Timer '{}' is already running", metadata.getName());
        }
    }