• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2018, OpenCensus Authors
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package io.opencensus.metrics;
18 
19 import io.opencensus.common.ExperimentalApi;
20 import io.opencensus.metrics.export.ExportComponent;
21 
22 /**
23  * Class that holds the implementation instance for {@link ExportComponent}.
24  *
25  * @since 0.17
26  */
27 @ExperimentalApi
28 public abstract class MetricsComponent {
29 
30   /**
31    * Returns the {@link ExportComponent} with the provided implementation. If no implementation is
32    * provided then no-op implementations will be used.
33    *
34    * @return the {@link ExportComponent} implementation.
35    * @since 0.17
36    */
getExportComponent()37   public abstract ExportComponent getExportComponent();
38 
39   /**
40    * Returns the {@link MetricRegistry} with the provided implementation.
41    *
42    * @return the {@link MetricRegistry} implementation.
43    * @since 0.17
44    */
getMetricRegistry()45   public abstract MetricRegistry getMetricRegistry();
46 
47   /**
48    * Returns an instance that contains no-op implementations for all the instances.
49    *
50    * @return an instance that contains no-op implementations for all the instances.
51    */
newNoopMetricsComponent()52   static MetricsComponent newNoopMetricsComponent() {
53     return new NoopMetricsComponent();
54   }
55 
56   private static final class NoopMetricsComponent extends MetricsComponent {
57     private static final ExportComponent EXPORT_COMPONENT =
58         ExportComponent.newNoopExportComponent();
59     private static final MetricRegistry METRIC_REGISTRY = MetricRegistry.newNoopMetricRegistry();
60 
61     @Override
getExportComponent()62     public ExportComponent getExportComponent() {
63       return EXPORT_COMPONENT;
64     }
65 
66     @Override
getMetricRegistry()67     public MetricRegistry getMetricRegistry() {
68       return METRIC_REGISTRY;
69     }
70   }
71 }
72