All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.codahale.metrics.jdbi3.InstrumentedTimingCollector Maven / Gradle / Ivy

There is a newer version: 4.2.28
Show newest version
package com.codahale.metrics.jdbi3;

import com.codahale.metrics.MetricRegistry;
import com.codahale.metrics.jdbi3.strategies.SmartNameStrategy;
import com.codahale.metrics.jdbi3.strategies.StatementNameStrategy;
import org.jdbi.v3.core.statement.SqlLogger;
import org.jdbi.v3.core.statement.StatementContext;
import org.jdbi.v3.core.statement.TimingCollector;

import java.util.concurrent.TimeUnit;

/**
 * A {@link TimingCollector} implementation for JDBI which uses the SQL objects' class names and
 * method names for millisecond-precision timers.
 *
 * @deprecated Use {@link InstrumentedSqlLogger} and {@link org.jdbi.v3.core.Jdbi#setSqlLogger(SqlLogger)} instead.
 */
@Deprecated
public class InstrumentedTimingCollector implements TimingCollector {

    private final MetricRegistry registry;
    private final StatementNameStrategy statementNameStrategy;

    public InstrumentedTimingCollector(MetricRegistry registry) {
        this(registry, new SmartNameStrategy());
    }

    public InstrumentedTimingCollector(MetricRegistry registry,
                                       StatementNameStrategy statementNameStrategy) {
        this.registry = registry;
        this.statementNameStrategy = statementNameStrategy;
    }

    @Override
    public void collect(long elapsedTime, StatementContext ctx) {
        String statementName = statementNameStrategy.getStatementName(ctx);
        if (statementName != null) {
            registry.timer(statementName).update(elapsedTime, TimeUnit.NANOSECONDS);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy