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 package org.apache.hadoop.hbase.client;
19
20 import java.io.IOException;
21
22 import org.apache.hadoop.hbase.classification.InterfaceAudience;
23
24 /**
25 * This class is designed to fit into the RetryingCaller class which forms the
26 * central piece of intelligence for the client side retries for most calls.
27 *
28 * One can extend this class and intercept the RetryingCaller and add additional
29 * logic into the execution of a simple HTable operations like get, delete etc.
30 *
31 * Concrete implementations of this calls are supposed to the thread safe. The
32 * object is used across threads to identify the fast failing threads.
33 *
34 * For a concrete use case see {@link PreemptiveFastFailInterceptor}
35 *
36 * Example use case :
37 * try {
38 * interceptor.intercept
39 * doAction()
40 * } catch (Exception e) {
41 * interceptor.handleFailure
42 * } finally {
43 * interceptor.updateFaulireInfo
44 * }
45 *
46 * The {@link RetryingCallerInterceptor} also acts as a factory
47 * for getting a new {@link RetryingCallerInterceptorContext}.
48 *
49 */
50
51 @InterfaceAudience.Private
52 abstract class RetryingCallerInterceptor {
53
54 protected RetryingCallerInterceptor() {
55 // Empty constructor protected for NoOpRetryableCallerInterceptor
56 }
57
58 /**
59 * This returns the context object for the current call.
60 *
61 * @return context : the context that needs to be used during this call.
62 */
63 public abstract RetryingCallerInterceptorContext createEmptyContext();
64
65 /**
66 * Call this function in case we caught a failure during retries.
67 *
68 * @param context
69 * : The context object that we obtained previously.
70 * @param t
71 * : The exception that we caught in this particular try
72 * @throws IOException
73 */
74 public abstract void handleFailure(RetryingCallerInterceptorContext context,
75 Throwable t) throws IOException;
76
77 /**
78 * Call this function alongside the actual call done on the callable.
79 *
80 * @param abstractRetryingCallerInterceptorContext
81 * @throws PreemptiveFastFailException
82 */
83 public abstract void intercept(
84 RetryingCallerInterceptorContext abstractRetryingCallerInterceptorContext)
85 throws IOException;
86
87 /**
88 * Call this function to update at the end of the retry. This is not necessary
89 * to happen.
90 *
91 * @param context
92 */
93 public abstract void updateFailureInfo(
94 RetryingCallerInterceptorContext context);
95
96 @Override
97 public abstract String toString();
98 }