LCOV - code coverage report
Current view: top level - metrics/dropwizard - CallbackMetricImpl1.java (source / functions) Hit Total Coverage
Test: _coverage_report.dat Lines: 20 22 90.9 %
Date: 2022-11-19 15:00:39 Functions: 10 11 90.9 %

          Line data    Source code
       1             : // Copyright (C) 2015 The Android Open Source Project
       2             : //
       3             : // Licensed under the Apache License, Version 2.0 (the "License");
       4             : // you may not use this file except in compliance with the License.
       5             : // You may obtain a copy of the License at
       6             : //
       7             : // http://www.apache.org/licenses/LICENSE-2.0
       8             : //
       9             : // Unless required by applicable law or agreed to in writing, software
      10             : // distributed under the License is distributed on an "AS IS" BASIS,
      11             : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      12             : // See the License for the specific language governing permissions and
      13             : // limitations under the License.
      14             : 
      15             : package com.google.gerrit.metrics.dropwizard;
      16             : 
      17             : import com.codahale.metrics.MetricRegistry;
      18             : import com.google.gerrit.metrics.CallbackMetric1;
      19             : import com.google.gerrit.metrics.Description;
      20             : import com.google.gerrit.metrics.Field;
      21             : import java.util.function.Function;
      22             : 
      23             : /** Optimized version of {@link BucketedCallback} for single dimension. */
      24             : class CallbackMetricImpl1<F1, V> extends BucketedCallback<V> {
      25             :   CallbackMetricImpl1(
      26             :       DropWizardMetricMaker metrics,
      27             :       MetricRegistry registry,
      28             :       String name,
      29             :       Class<V> valueClass,
      30             :       Description desc,
      31             :       Field<F1> field1) {
      32          16 :     super(metrics, registry, name, valueClass, desc, field1);
      33          16 :   }
      34             : 
      35             :   CallbackMetric1<F1, V> create() {
      36          16 :     return new Impl1();
      37             :   }
      38             : 
      39          16 :   private final class Impl1 extends CallbackMetric1<F1, V> implements CallbackMetricGlue {
      40             :     @Override
      41             :     public void beginSet() {
      42          16 :       doBeginSet();
      43          16 :     }
      44             : 
      45             :     @Override
      46             :     public void set(F1 field1, V value) {
      47          16 :       BucketedCallback<V>.ValueGauge cell = getOrCreate(field1);
      48          16 :       cell.value = value;
      49          16 :       cell.set = true;
      50          16 :     }
      51             : 
      52             :     @Override
      53             :     public void prune() {
      54          15 :       doPrune();
      55          15 :     }
      56             : 
      57             :     @Override
      58             :     public void endSet() {
      59          16 :       doEndSet();
      60          16 :     }
      61             : 
      62             :     @Override
      63             :     public void forceCreate(F1 field1) {
      64          16 :       getOrCreate(field1);
      65          16 :     }
      66             : 
      67             :     @Override
      68             :     public void register(Runnable t) {
      69          16 :       trigger = t;
      70          16 :     }
      71             : 
      72             :     @Override
      73             :     public void remove() {
      74           0 :       doRemove();
      75           0 :     }
      76             :   }
      77             : 
      78             :   @Override
      79             :   String name(Object field1) {
      80             :     @SuppressWarnings("unchecked")
      81          16 :     Function<Object, String> fmt = (Function<Object, String>) fields[0].formatter();
      82             : 
      83          16 :     return fmt.apply(field1).replace('/', '-');
      84             :   }
      85             : }

Generated by: LCOV version 1.16+git.20220603.dfeb750