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