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.regionserver; 019 020import org.apache.hadoop.hbase.io.MetricsIOSource; 021import org.apache.hadoop.hbase.io.MetricsIOSourceImpl; 022import org.apache.hadoop.hbase.io.MetricsIOWrapper; 023import org.apache.yetus.audience.InterfaceAudience; 024 025/** 026 * Factory to create MetricsRegionServerSource when given a MetricsRegionServerWrapper 027 */ 028@InterfaceAudience.Private 029public class MetricsRegionServerSourceFactoryImpl implements MetricsRegionServerSourceFactory { 030 public static enum FactoryStorage { 031 INSTANCE; 032 private Object aggLock = new Object(); 033 private MetricsRegionAggregateSourceImpl regionAggImpl; 034 private MetricsUserAggregateSourceImpl userAggImpl; 035 private MetricsTableAggregateSourceImpl tblAggImpl; 036 private MetricsHeapMemoryManagerSourceImpl heapMemMngImpl; 037 } 038 039 private synchronized MetricsRegionAggregateSourceImpl getRegionAggregate() { 040 synchronized (FactoryStorage.INSTANCE.aggLock) { 041 if (FactoryStorage.INSTANCE.regionAggImpl == null) { 042 FactoryStorage.INSTANCE.regionAggImpl = new MetricsRegionAggregateSourceImpl(); 043 } 044 return FactoryStorage.INSTANCE.regionAggImpl; 045 } 046 } 047 048 public synchronized MetricsUserAggregateSourceImpl getUserAggregate() { 049 synchronized (FactoryStorage.INSTANCE.aggLock) { 050 if (FactoryStorage.INSTANCE.userAggImpl == null) { 051 FactoryStorage.INSTANCE.userAggImpl = new MetricsUserAggregateSourceImpl(); 052 } 053 return FactoryStorage.INSTANCE.userAggImpl; 054 } 055 } 056 057 @Override 058 public synchronized MetricsTableAggregateSourceImpl getTableAggregate() { 059 synchronized (FactoryStorage.INSTANCE.aggLock) { 060 if (FactoryStorage.INSTANCE.tblAggImpl == null) { 061 FactoryStorage.INSTANCE.tblAggImpl = new MetricsTableAggregateSourceImpl(); 062 } 063 return FactoryStorage.INSTANCE.tblAggImpl; 064 } 065 } 066 067 @Override 068 public synchronized MetricsHeapMemoryManagerSource getHeapMemoryManager() { 069 synchronized (FactoryStorage.INSTANCE.aggLock) { 070 if (FactoryStorage.INSTANCE.heapMemMngImpl == null) { 071 FactoryStorage.INSTANCE.heapMemMngImpl = new MetricsHeapMemoryManagerSourceImpl(); 072 } 073 return FactoryStorage.INSTANCE.heapMemMngImpl; 074 } 075 } 076 077 @Override 078 public synchronized MetricsRegionServerSource createServer( 079 MetricsRegionServerWrapper regionServerWrapper) { 080 return new MetricsRegionServerSourceImpl(regionServerWrapper); 081 } 082 083 @Override 084 public MetricsRegionSource createRegion(MetricsRegionWrapper wrapper) { 085 return new MetricsRegionSourceImpl(wrapper, getRegionAggregate()); 086 } 087 088 @Override 089 public MetricsTableSource createTable(String table, MetricsTableWrapperAggregate wrapper) { 090 return new MetricsTableSourceImpl(table, getTableAggregate(), wrapper); 091 } 092 093 public MetricsIOSource createIO(MetricsIOWrapper wrapper) { 094 return new MetricsIOSourceImpl(wrapper); 095 } 096 097 @Override 098 public org.apache.hadoop.hbase.regionserver.MetricsUserSource createUser(String shortUserName) { 099 return new org.apache.hadoop.hbase.regionserver.MetricsUserSourceImpl(shortUserName, 100 getUserAggregate()); 101 } 102}