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.client.backoff; 019 020import org.apache.hadoop.conf.Configuration; 021import org.apache.hadoop.hbase.ServerName; 022import org.apache.yetus.audience.InterfaceAudience; 023import org.apache.yetus.audience.InterfaceStability; 024import org.slf4j.Logger; 025import org.slf4j.LoggerFactory; 026import org.apache.hadoop.hbase.util.ReflectionUtils; 027 028@InterfaceAudience.Private 029@InterfaceStability.Evolving 030public final class ClientBackoffPolicyFactory { 031 032 private static final Logger LOG = LoggerFactory.getLogger(ClientBackoffPolicyFactory.class); 033 034 private ClientBackoffPolicyFactory() { 035 } 036 037 public static ClientBackoffPolicy create(Configuration conf) { 038 // create the backoff policy 039 String className = 040 conf.get(ClientBackoffPolicy.BACKOFF_POLICY_CLASS, NoBackoffPolicy.class 041 .getName()); 042 return ReflectionUtils.instantiateWithCustomCtor(className, 043 new Class<?>[] { Configuration.class }, new Object[] { conf }); 044 } 045 046 /** 047 * Default backoff policy that doesn't create any backoff for the client, regardless of load 048 */ 049 public static class NoBackoffPolicy implements ClientBackoffPolicy { 050 public NoBackoffPolicy(Configuration conf){ 051 // necessary to meet contract 052 } 053 054 @Override 055 public long getBackoffTime(ServerName serverName, byte[] region, ServerStatistics stats) { 056 return 0; 057 } 058 } 059}