1 /**
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 */
19
20 package org.apache.hadoop.hbase.client;
21
22 import java.io.IOException;
23
24 import org.apache.hadoop.hbase.classification.InterfaceAudience;
25
26 /**
27 * A Callable<T> that will be retried. If {@link #call(int)} invocation throws exceptions,
28 * we will call {@link #throwable(Throwable, boolean)} with whatever the exception was.
29 * @param <T>
30 */
31 @InterfaceAudience.Private
32 public interface RetryingCallable<T> {
33 /**
34 * Prepare by setting up any connections to servers, etc., ahead of {@link #call(int)} invocation.
35 * @param reload Set this to true if need to requery locations
36 * @throws IOException e
37 */
38 void prepare(final boolean reload) throws IOException;
39
40 /**
41 * Called when {@link #call(int)} throws an exception and we are going to retry; take action to
42 * make it so we succeed on next call (clear caches, do relookup of locations, etc.).
43 * @param t
44 * @param retrying True if we are in retrying mode (we are not in retrying mode when max
45 * retries == 1; we ARE in retrying mode if retries > 1 even when we are the last attempt)
46 */
47 void throwable(final Throwable t, boolean retrying);
48
49 /**
50 * Computes a result, or throws an exception if unable to do so.
51 *
52 * @param callTimeout - the time available for this call. 0 for infinite.
53 * @return computed result
54 * @throws Exception if unable to compute a result
55 */
56 T call(int callTimeout) throws Exception;
57
58 /**
59 * @return Some details from the implementation that we would like to add to a terminating
60 * exception; i.e. a fatal exception is being thrown ending retries and we might like to add
61 * more implementation-specific detail on to the exception being thrown.
62 */
63 String getExceptionMessageAdditionalDetail();
64
65 /**
66 * @param pause
67 * @param tries
68 * @return Suggestion on how much to sleep between retries
69 */
70 long sleep(final long pause, final int tries);
71 }