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 aggImpl;
034    private MetricsTableAggregateSourceImpl tblAggImpl;
035    private MetricsHeapMemoryManagerSourceImpl heapMemMngImpl;
036  }
037
038  private synchronized MetricsRegionAggregateSourceImpl getAggregate() {
039    synchronized (FactoryStorage.INSTANCE.aggLock) {
040      if (FactoryStorage.INSTANCE.aggImpl == null) {
041        FactoryStorage.INSTANCE.aggImpl = new MetricsRegionAggregateSourceImpl();
042      }
043      return FactoryStorage.INSTANCE.aggImpl;
044    }
045  }
046
047  @Override
048  public synchronized MetricsTableAggregateSourceImpl getTableAggregate() {
049    synchronized (FactoryStorage.INSTANCE.aggLock) {
050      if (FactoryStorage.INSTANCE.tblAggImpl == null) {
051        FactoryStorage.INSTANCE.tblAggImpl = new MetricsTableAggregateSourceImpl();
052      }
053      return FactoryStorage.INSTANCE.tblAggImpl;
054    }
055  }
056
057  @Override
058  public synchronized MetricsHeapMemoryManagerSource getHeapMemoryManager() {
059    synchronized (FactoryStorage.INSTANCE.aggLock) {
060      if (FactoryStorage.INSTANCE.heapMemMngImpl == null) {
061        FactoryStorage.INSTANCE.heapMemMngImpl = new MetricsHeapMemoryManagerSourceImpl();
062      }
063      return FactoryStorage.INSTANCE.heapMemMngImpl;
064    }
065  }
066
067  @Override
068  public synchronized MetricsRegionServerSource createServer(
069      MetricsRegionServerWrapper regionServerWrapper) {
070    return new MetricsRegionServerSourceImpl(regionServerWrapper);
071  }
072
073  @Override
074  public MetricsRegionSource createRegion(MetricsRegionWrapper wrapper) {
075    return new MetricsRegionSourceImpl(wrapper, getAggregate());
076  }
077
078  @Override
079  public MetricsTableSource createTable(String table, MetricsTableWrapperAggregate wrapper) {
080    return new MetricsTableSourceImpl(table, getTableAggregate(), wrapper);
081  }
082
083  public MetricsIOSource createIO(MetricsIOWrapper wrapper) {
084    return new MetricsIOSourceImpl(wrapper);
085  }
086}