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.ipc;
021
022import org.apache.yetus.audience.InterfaceAudience;
023
024@InterfaceAudience.Private
025public abstract class MetricsHBaseServerSourceFactory {
026  /**
027   * The name of the metrics
028   */
029  static final String METRICS_NAME = "IPC";
030
031  /**
032   * Description
033   */
034  static final String METRICS_DESCRIPTION = "Metrics about HBase Server IPC";
035
036  /**
037   * The Suffix of the JMX Context that a MetricsHBaseServerSource will register under.
038   *
039   * JMX_CONTEXT will be created by createContextName(serverClassName) + METRICS_JMX_CONTEXT_SUFFIX
040   */
041  static final String METRICS_JMX_CONTEXT_SUFFIX = ",sub=" + METRICS_NAME;
042
043  abstract MetricsHBaseServerSource create(String serverName, MetricsHBaseServerWrapper wrapper);
044
045  /**
046   * From the name of the class that's starting up create the
047   * context that an IPC source should register itself.
048   *
049   * @param serverName The name of the class that's starting up.
050   * @return The Camel Cased context name.
051   */
052  protected static String createContextName(String serverName) {
053    if (serverName.startsWith("HMaster") || serverName.startsWith("master")) {
054      return "Master";
055    } else if (serverName.startsWith("HRegion") || serverName.startsWith("regionserver")) {
056      return "RegionServer";
057    }
058    return "IPC";
059  }
060}