1 /**
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 */
19
20 package org.apache.hadoop.hbase.metrics;
21
22 import java.util.Collection;
23 import java.util.Set;
24
25 import org.apache.hadoop.hbase.HBaseInterfaceAudience;
26 import org.apache.hadoop.hbase.classification.InterfaceAudience;
27 import org.apache.hadoop.hbase.classification.InterfaceStability;
28
29 import com.google.common.base.Optional;
30
31 /**
32 * MetricRegistries is collection of MetricRegistry's. MetricsRegistries implementations should do
33 * ref-counting of MetricRegistry's via create() and remove() methods.
34 */
35 @InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.COPROC)
36 @InterfaceStability.Evolving
37 public abstract class MetricRegistries {
38
39 private static final class LazyHolder {
40 private static final MetricRegistries GLOBAL = MetricRegistriesLoader.load();
41 }
42
43 /**
44 * Return the global singleton instance for the MetricRegistries.
45 * @return MetricRegistries implementation.
46 */
47 public static MetricRegistries global() {
48 return LazyHolder.GLOBAL;
49 }
50
51 /**
52 * Removes all the MetricRegisties.
53 */
54 public abstract void clear();
55
56 /**
57 * Create or return MetricRegistry with the given info. MetricRegistry will only be created
58 * if current reference count is 0. Otherwise ref counted is incremented, and an existing instance
59 * will be returned.
60 * @param info the info object for the MetricRegistrytry.
61 * @return created or existing MetricRegistry.
62 */
63 public abstract MetricRegistry create(MetricRegistryInfo info);
64
65 /**
66 * Decrements the ref count of the MetricRegistry, and removes if ref count == 0.
67 * @param key the info object for the MetricRegistrytry.
68 * @return true if metric registry is removed.
69 */
70 public abstract boolean remove(MetricRegistryInfo key);
71
72 /**
73 * Returns the MetricRegistry if found.
74 * @param info the info for the registry.
75 * @return a MetricRegistry optional.
76 */
77 public abstract Optional<MetricRegistry> get(MetricRegistryInfo info);
78
79 /**
80 * Returns MetricRegistryInfo's for the MetricRegistry's created.
81 * @return MetricRegistryInfo's for the MetricRegistry's created.
82 */
83 public abstract Set<MetricRegistryInfo> getMetricRegistryInfos();
84
85 /**
86 * Returns MetricRegistry's created.
87 * @return MetricRegistry's created.
88 */
89 public abstract Collection<MetricRegistry> getMetricRegistries();
90 }