1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.hadoop.hbase.client;
20
21 import java.lang.reflect.Constructor;
22
23 import org.apache.commons.logging.Log;
24 import org.apache.commons.logging.LogFactory;
25 import org.apache.hadoop.conf.Configuration;
26 import org.apache.hadoop.hbase.HConstants;
27 import org.apache.hadoop.hbase.classification.InterfaceAudience;
28
29
30
31
32
33
34
35
36 @InterfaceAudience.Private
37 class RetryingCallerInterceptorFactory {
38 private static final Log LOG = LogFactory
39 .getLog(RetryingCallerInterceptorFactory.class);
40 private Configuration conf;
41 private final boolean failFast;
42 public static final RetryingCallerInterceptor NO_OP_INTERCEPTOR =
43 new NoOpRetryableCallerInterceptor(null);
44
45 public RetryingCallerInterceptorFactory(Configuration conf) {
46 this.conf = conf;
47 failFast = conf.getBoolean(HConstants.HBASE_CLIENT_FAST_FAIL_MODE_ENABLED,
48 HConstants.HBASE_CLIENT_ENABLE_FAST_FAIL_MODE_DEFAULT);
49 }
50
51
52
53
54
55
56
57
58
59
60
61
62 @edu.umd.cs.findbugs.annotations.SuppressWarnings(value="REC_CATCH_EXCEPTION",
63 justification="Convert thrown exception to unchecked")
64 public RetryingCallerInterceptor build() {
65 RetryingCallerInterceptor ret = NO_OP_INTERCEPTOR;
66 if (failFast) {
67 try {
68 Class<?> c = conf.getClass(
69 HConstants.HBASE_CLIENT_FAST_FAIL_INTERCEPTOR_IMPL,
70 PreemptiveFastFailInterceptor.class);
71 Constructor<?> constructor = c
72 .getDeclaredConstructor(Configuration.class);
73 constructor.setAccessible(true);
74 ret = (RetryingCallerInterceptor) constructor.newInstance(conf);
75 } catch (Exception e) {
76 ret = new PreemptiveFastFailInterceptor(conf);
77 }
78 }
79 LOG.trace("Using " + ret.toString() + " for intercepting the RpcRetryingCaller");
80 return ret;
81 }
82 }