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 */
018
019package org.apache.hadoop.hbase.master.balancer;
020
021import org.apache.hadoop.hbase.CompatibilitySingletonFactory;
022import org.apache.yetus.audience.InterfaceAudience;
023
024/**
025 * This metrics balancer uses extended source for stochastic load balancer
026 * to report its related metrics to JMX. For details, refer to HBASE-13965
027 */
028@InterfaceAudience.Private
029public class MetricsStochasticBalancer extends MetricsBalancer {
030  /**
031   * Use the stochastic source instead of the default source.
032   */
033  private MetricsStochasticBalancerSource stochasticSource = null;
034
035  public MetricsStochasticBalancer() {
036    initSource();
037  }
038
039  /**
040   * This function overrides the initSource in the MetricsBalancer, use
041   * MetricsStochasticBalancerSource instead of the MetricsBalancerSource.
042   */
043  @Override
044  protected void initSource() {
045    stochasticSource =
046        CompatibilitySingletonFactory.getInstance(MetricsStochasticBalancerSource.class);
047  }
048
049  @Override
050  public void balanceCluster(long time) {
051    stochasticSource.updateBalanceCluster(time);
052  }
053
054  @Override
055  public void incrMiscInvocations() {
056    stochasticSource.incrMiscInvocations();
057  }
058
059  /**
060   * Updates the balancer status tag reported to JMX
061   */
062  @Override
063  public void balancerStatus(boolean status) {
064    stochasticSource.updateBalancerStatus(status);
065  }
066
067  /**
068   * Updates the number of metrics reported to JMX
069   */
070  public void updateMetricsSize(int size) {
071    stochasticSource.updateMetricsSize(size);
072  }
073
074  /**
075   * Reports stochastic load balancer costs to JMX
076   */
077  public void updateStochasticCost(String tableName, String costFunctionName,
078      String costFunctionDesc, Double value) {
079    stochasticSource.updateStochasticCost(tableName, costFunctionName, costFunctionDesc, value);
080  }
081}