001/** 002 * 003 * Licensed to the Apache Software Foundation (ASF) under one 004 * or more contributor license agreements. See the NOTICE file 005 * distributed with this work for additional information 006 * regarding copyright ownership. The ASF licenses this file 007 * to you under the Apache License, Version 2.0 (the 008 * "License"); you may not use this file except in compliance 009 * with the License. You may obtain a copy of the License at 010 * 011 * http://www.apache.org/licenses/LICENSE-2.0 012 * 013 * Unless required by applicable law or agreed to in writing, software 014 * distributed under the License is distributed on an "AS IS" BASIS, 015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 016 * See the License for the specific language governing permissions and 017 * limitations under the License. 018 */ 019 020package org.apache.hadoop.hbase.metrics; 021 022import java.util.Collection; 023import java.util.Optional; 024import java.util.Set; 025 026import org.apache.hadoop.hbase.HBaseInterfaceAudience; 027import org.apache.yetus.audience.InterfaceAudience; 028import org.apache.yetus.audience.InterfaceStability; 029 030/** 031 * MetricRegistries is collection of MetricRegistry's. MetricsRegistries implementations should do 032 * ref-counting of MetricRegistry's via create() and remove() methods. 033 */ 034@InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.COPROC) 035@InterfaceStability.Evolving 036public abstract class MetricRegistries { 037 038 private static final class LazyHolder { 039 private static final MetricRegistries GLOBAL = MetricRegistriesLoader.load(); 040 } 041 042 /** 043 * Return the global singleton instance for the MetricRegistries. 044 * @return MetricRegistries implementation. 045 */ 046 public static MetricRegistries global() { 047 return LazyHolder.GLOBAL; 048 } 049 050 /** 051 * Removes all the MetricRegisties. 052 */ 053 public abstract void clear(); 054 055 /** 056 * Create or return MetricRegistry with the given info. MetricRegistry will only be created 057 * if current reference count is 0. Otherwise ref counted is incremented, and an existing instance 058 * will be returned. 059 * @param info the info object for the MetricRegistrytry. 060 * @return created or existing MetricRegistry. 061 */ 062 public abstract MetricRegistry create(MetricRegistryInfo info); 063 064 /** 065 * Decrements the ref count of the MetricRegistry, and removes if ref count == 0. 066 * @param key the info object for the MetricRegistrytry. 067 * @return true if metric registry is removed. 068 */ 069 public abstract boolean remove(MetricRegistryInfo key); 070 071 /** 072 * Returns the MetricRegistry if found. 073 * @param info the info for the registry. 074 * @return a MetricRegistry optional. 075 */ 076 public abstract Optional<MetricRegistry> get(MetricRegistryInfo info); 077 078 /** 079 * Returns MetricRegistryInfo's for the MetricRegistry's created. 080 * @return MetricRegistryInfo's for the MetricRegistry's created. 081 */ 082 public abstract Set<MetricRegistryInfo> getMetricRegistryInfos(); 083 084 /** 085 * Returns MetricRegistry's created. 086 * @return MetricRegistry's created. 087 */ 088 public abstract Collection<MetricRegistry> getMetricRegistries(); 089}