Search in sources :

Example 1 with CounterImpl

use of org.wildfly.swarm.microprofile.metrics.runtime.app.CounterImpl in project wildfly-swarm by wildfly-swarm.

the class MetricsRegistryImpl method get.

private <T extends Metric> T get(Metadata metadata, MetricType type) {
    String name = metadata.getName();
    LOGGER.debugf("Get metric [name: %s, type: %s]", name, type);
    if (name == null || name.isEmpty()) {
        throw new IllegalArgumentException("Name must not be null or empty");
    }
    if (!metadataMap.containsKey(name)) {
        Metric m;
        switch(type) {
            case COUNTER:
                m = new CounterImpl();
                break;
            case GAUGE:
                throw new IllegalArgumentException("Gauge " + name + " was not registered, this should not happen");
            case METERED:
                m = new MeterImpl();
                break;
            case HISTOGRAM:
                m = new HistogramImpl(new ExponentiallyDecayingReservoir());
                break;
            case TIMER:
                m = new TimerImpl(new ExponentiallyDecayingReservoir());
                break;
            case INVALID:
            default:
                throw new IllegalStateException("Must not happen");
        }
        LOGGER.infof("Register metric [name: %s, type: %s]", name, type);
        register(metadata, m);
    } else if (!metadataMap.get(name).getTypeRaw().equals(metadata.getTypeRaw())) {
        throw new IllegalArgumentException("Type of existing previously registered metric " + name + " does not " + "match passed type");
    }
    return (T) metricMap.get(name);
}
Also used : ExponentiallyDecayingReservoir(org.wildfly.swarm.microprofile.metrics.runtime.app.ExponentiallyDecayingReservoir) MeterImpl(org.wildfly.swarm.microprofile.metrics.runtime.app.MeterImpl) Metric(org.eclipse.microprofile.metrics.Metric) HistogramImpl(org.wildfly.swarm.microprofile.metrics.runtime.app.HistogramImpl) CounterImpl(org.wildfly.swarm.microprofile.metrics.runtime.app.CounterImpl) TimerImpl(org.wildfly.swarm.microprofile.metrics.runtime.app.TimerImpl)

Aggregations

Metric (org.eclipse.microprofile.metrics.Metric)1 CounterImpl (org.wildfly.swarm.microprofile.metrics.runtime.app.CounterImpl)1 ExponentiallyDecayingReservoir (org.wildfly.swarm.microprofile.metrics.runtime.app.ExponentiallyDecayingReservoir)1 HistogramImpl (org.wildfly.swarm.microprofile.metrics.runtime.app.HistogramImpl)1 MeterImpl (org.wildfly.swarm.microprofile.metrics.runtime.app.MeterImpl)1 TimerImpl (org.wildfly.swarm.microprofile.metrics.runtime.app.TimerImpl)1