This project has retired. For details please refer to its Attic page.
NoOpMetricsRegistry xref
View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  package org.apache.giraph.metrics;
20  
21  import com.google.common.collect.Maps;
22  import com.yammer.metrics.core.Counter;
23  import com.yammer.metrics.core.NoOpCounter;
24  import com.yammer.metrics.core.NoOpGuage;
25  import com.yammer.metrics.core.NoOpHistogram;
26  import com.yammer.metrics.core.NoOpMeter;
27  import com.yammer.metrics.core.NoOpTimer;
28  import com.yammer.metrics.core.Gauge;
29  import com.yammer.metrics.core.Histogram;
30  import com.yammer.metrics.core.Meter;
31  import com.yammer.metrics.core.Metric;
32  import com.yammer.metrics.core.MetricName;
33  import com.yammer.metrics.core.MetricPredicate;
34  import com.yammer.metrics.core.MetricsRegistry;
35  import com.yammer.metrics.core.MetricsRegistryListener;
36  import com.yammer.metrics.core.Timer;
37  
38  import java.util.Map;
39  import java.util.SortedMap;
40  import java.util.concurrent.ConcurrentMap;
41  import java.util.concurrent.ScheduledExecutorService;
42  import java.util.concurrent.TimeUnit;
43  
44  /**
45   * An empty MetricsRegistry, used to easily turn off all metrics without
46   * affecting client code.
47   */
48  public class NoOpMetricsRegistry extends MetricsRegistry {
49    @Override
50    public <T> Gauge<T> newGauge(Class<?> klass, String name, Gauge<T> metric) {
51      return NoOpGuage.INSTANCE;
52    }
53  
54    @Override
55    public <T> Gauge<T> newGauge(Class<?> klass, String name, String scope,
56                                 Gauge<T> metric) {
57      return NoOpGuage.INSTANCE;
58    }
59  
60    @Override
61    public <T> Gauge<T> newGauge(MetricName metricName, Gauge<T> metric) {
62      return NoOpGuage.INSTANCE;
63    }
64  
65    @Override
66    public Counter newCounter(Class<?> klass, String name) {
67      return NoOpCounter.INSTANCE;
68    }
69  
70    @Override
71    public Counter newCounter(Class<?> klass, String name, String scope) {
72      return NoOpCounter.INSTANCE;
73    }
74  
75    @Override
76    public Counter newCounter(MetricName metricName) {
77      return NoOpCounter.INSTANCE;
78    }
79  
80    @Override
81    public Histogram newHistogram(Class<?> klass, String name, boolean biased) {
82      return NoOpHistogram.INSTANCE;
83    }
84  
85    @Override
86    public Histogram newHistogram(Class<?> klass, String name, String scope,
87                                  boolean biased) {
88      return NoOpHistogram.INSTANCE;
89    }
90  
91    @Override
92    public Histogram newHistogram(Class<?> klass, String name) {
93      return NoOpHistogram.INSTANCE;
94    }
95  
96    @Override
97    public Histogram newHistogram(Class<?> klass, String name, String scope) {
98      return NoOpHistogram.INSTANCE;
99    }
100 
101   @Override
102   public Histogram newHistogram(MetricName metricName, boolean biased) {
103     return NoOpHistogram.INSTANCE;
104   }
105 
106   @Override
107   public Meter newMeter(Class<?> klass, String name, String eventType,
108                         TimeUnit unit) {
109     return NoOpMeter.INSTANCE;
110   }
111 
112   @Override
113   public Meter newMeter(
114     Class<?> klass, String name, String scope, String eventType, TimeUnit unit
115   ) {
116     return NoOpMeter.INSTANCE;
117   }
118 
119   @Override
120   public Meter newMeter(MetricName metricName, String eventType,
121                         TimeUnit unit) {
122     return NoOpMeter.INSTANCE;
123   }
124 
125   @Override
126   public Timer newTimer(Class<?> klass, String name) {
127     return NoOpTimer.INSTANCE;
128   }
129 
130   @Override
131   public Timer newTimer(Class<?> klass, String name, TimeUnit durationUnit,
132                         TimeUnit rateUnit) {
133     return NoOpTimer.INSTANCE;
134   }
135 
136   @Override
137   public Timer newTimer(Class<?> klass, String name, String scope) {
138     return NoOpTimer.INSTANCE;
139   }
140 
141   @Override
142   public Timer newTimer(Class<?> klass, String name, String scope,
143                         TimeUnit durationUnit, TimeUnit rateUnit
144   ) {
145     return NoOpTimer.INSTANCE;
146   }
147 
148   @Override
149   public Timer newTimer(MetricName metricName, TimeUnit durationUnit,
150                         TimeUnit rateUnit) {
151     return NoOpTimer.INSTANCE;
152   }
153 
154   @Override
155   public Map<MetricName, Metric> allMetrics() {
156     return Maps.newHashMap();
157   }
158 
159   @Override
160   public SortedMap<String, SortedMap<MetricName, Metric>> groupedMetrics() {
161     return Maps.newTreeMap();
162   }
163 
164   @Override
165   public SortedMap<String, SortedMap<MetricName, Metric>>
166   groupedMetrics(MetricPredicate predicate) {
167     return Maps.newTreeMap();
168   }
169 
170   @Override
171   public void shutdown() { }
172 
173   @Override
174   public ScheduledExecutorService newScheduledThreadPool(int poolSize,
175                                                          String name) {
176     return null;
177   }
178 
179   @Override
180   public void removeMetric(Class<?> klass, String name) { }
181 
182   @Override
183   public void removeMetric(Class<?> klass, String name, String scope) { }
184 
185   @Override
186   public void removeMetric(MetricName name) { }
187 
188   @Override
189   public void addListener(MetricsRegistryListener listener) { }
190 
191   @Override
192   public void removeListener(MetricsRegistryListener listener) { }
193 
194   @Override
195   protected ConcurrentMap<MetricName, Metric> newMetricsMap() {
196     return Maps.newConcurrentMap();
197   }
198 }