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