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

com.ringcentral.platform.metrics.stub.StubCounter Maven / Gradle / Ivy

The newest version!
package com.ringcentral.platform.metrics.stub;

import com.ringcentral.platform.metrics.MetricRegistry;
import com.ringcentral.platform.metrics.counter.*;
import com.ringcentral.platform.metrics.counter.configs.*;
import com.ringcentral.platform.metrics.labels.LabelValue;
import com.ringcentral.platform.metrics.measurables.Measurable;
import com.ringcentral.platform.metrics.names.MetricName;
import com.ringcentral.platform.metrics.utils.TimeMsProvider;

import java.util.*;
import java.util.concurrent.ScheduledExecutorService;

import static java.util.Collections.emptyMap;

public class StubCounter extends AbstractCounter implements Counter {

    static final MeasurableValueProvidersProvider stubMeasurableValueProvidersProviderInstance =
        (ic, sc, c, m) -> emptyMap();

    static final MeterImplUpdater stubMeterImplUpdaterInstance = (meterImpl, value) -> {};
    static final Object stubCounterImplInstance = new Object();

    static final MeterImplMaker stubCounterImplMaker =
        (ic, sc, c, m, e, r) -> stubCounterImplInstance;

    public StubCounter(
        MetricName name,
        CounterConfig config,
        TimeMsProvider timeMsProvider,
        ScheduledExecutorService executor,
        MetricRegistry registry) {

        super(
            name,
            config,
            stubMeasurableValueProvidersProviderInstance,
            stubCounterImplMaker,
            stubMeterImplUpdaterInstance,
            new InstanceMaker<>() {

                @Override
                public AbstractMeterInstance makeInstance(
                    MetricName name,
                    List labelValues,
                    boolean totalInstance,
                    boolean labeledMetricTotalInstance,
                    boolean levelInstance,
                    Map> measurableValueProviders,
                    Object meterImpl) {

                    return new StubMeterInstance(
                        name,
                        labelValues,
                        totalInstance,
                        labeledMetricTotalInstance,
                        levelInstance,
                        measurableValueProviders,
                        meterImpl);
                }

                @Override
                public AbstractExpirableMeterInstance makeExpirableInstance(
                    MetricName name,
                    List labelValues,
                    boolean totalInstance,
                    boolean labeledMetricTotalInstance,
                    boolean levelInstance,
                    Map> measurableValueProviders,
                    Object meterImpl,
                    long creationTimeMs) {

                    return new StubExpirableMeterInstance(
                        name,
                        labelValues,
                        totalInstance,
                        labeledMetricTotalInstance,
                        levelInstance,
                        measurableValueProviders,
                        meterImpl,
                        creationTimeMs);
                }
            },
            timeMsProvider,
            executor,
            registry);
    }
}