1 /** 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 19 package org.apache.hadoop.hbase.master.balancer; 20 21 import org.apache.hadoop.hbase.CompatibilitySingletonFactory; 22 23 /** 24 * This metrics balancer uses extended source for stochastic load balancer 25 * to report its related metrics to JMX. For details, refer to HBASE-13965 26 */ 27 public class MetricsStochasticBalancer extends MetricsBalancer { 28 /** 29 * Use the stochastic source instead of the default source. 30 */ 31 private MetricsStochasticBalancerSource stochasticSource = null; 32 33 public MetricsStochasticBalancer() { 34 initSource(); 35 } 36 37 /** 38 * This function overrides the initSource in the MetricsBalancer, use 39 * MetricsStochasticBalancerSource instead of the MetricsBalancerSource. 40 */ 41 @Override 42 protected void initSource() { 43 stochasticSource = 44 CompatibilitySingletonFactory.getInstance(MetricsStochasticBalancerSource.class); 45 } 46 47 @Override 48 public void balanceCluster(long time) { 49 stochasticSource.updateBalanceCluster(time); 50 } 51 52 @Override 53 public void incrMiscInvocations() { 54 stochasticSource.incrMiscInvocations(); 55 } 56 57 /** 58 * Updates the number of metrics reported to JMX 59 */ 60 public void updateMetricsSize(int size) { 61 stochasticSource.updateMetricsSize(size); 62 } 63 64 /** 65 * Reports stochastic load balancer costs to JMX 66 */ 67 public void updateStochasticCost(String tableName, String costFunctionName, 68 String costFunctionDesc, Double value) { 69 stochasticSource.updateStochasticCost(tableName, costFunctionName, costFunctionDesc, value); 70 } 71 }