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 org.apache.commons.lang3.builder.HashCodeBuilder;
021import org.apache.yetus.audience.InterfaceAudience;
022
023/**
024 * HBase Metrics are grouped in different MetricRegistry'ies. All metrics that correspond to a
025 * subcomponent (like RPC, GC, WAL) are managed in a single MetricRegistry. This class holds the
026 * name and description and JMX related context names for such group of metrics.
027 */
028@InterfaceAudience.Private
029public class MetricRegistryInfo {
030
031  protected final String metricsName;
032  protected final String metricsDescription;
033  protected final String metricsContext;
034  protected final String metricsJmxContext;
035  protected final boolean existingSource;
036
037  public MetricRegistryInfo(String metricsName, String metricsDescription, String metricsJmxContext,
038    String metricsContext, boolean existingSource) {
039    this.metricsName = metricsName;
040    this.metricsDescription = metricsDescription;
041    this.metricsContext = metricsContext;
042    this.metricsJmxContext = metricsJmxContext;
043    this.existingSource = existingSource;
044  }
045
046  /**
047   * Get the metrics context. For hadoop metrics2 system this is usually an all lowercased string.
048   * eg. regionserver, master, thriftserver
049   * @return The string context used to register this source to hadoop's metrics2 system.
050   */
051  public String getMetricsContext() {
052    return metricsContext;
053  }
054
055  /**
056   * Get the description of what this source exposes.
057   */
058  public String getMetricsDescription() {
059    return metricsDescription;
060  }
061
062  /**
063   * Get the name of the context in JMX that this source will be exposed through. This is in
064   * ObjectName format. With the default context being Hadoop -> HBase
065   */
066  public String getMetricsJmxContext() {
067    return metricsJmxContext;
068  }
069
070  /**
071   * Get the name of the metrics that are being exported by this source. Eg. IPC, GC, WAL
072   */
073  public String getMetricsName() {
074    return metricsName;
075  }
076
077  /**
078   * Returns whether or not this MetricRegistry is for an existing BaseSource
079   * @return true if this MetricRegistry is for an existing BaseSource.
080   */
081  public boolean isExistingSource() {
082    return existingSource;
083  }
084
085  @Override
086  public boolean equals(Object obj) {
087    if (obj instanceof MetricRegistryInfo) {
088      return this.hashCode() == obj.hashCode();
089    } else {
090      return false;
091    }
092  }
093
094  @Override
095  public int hashCode() {
096    return new HashCodeBuilder().append(metricsName).append(metricsDescription)
097      .append(metricsContext).append(metricsJmxContext).toHashCode();
098  }
099}