View Javadoc

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  import java.util.concurrent.Callable;
24  
25  import org.apache.hadoop.classification.InterfaceAudience;
26  import org.apache.hadoop.classification.InterfaceStability;
27  
28  /**
29   * A Callable<T> that will be retried.  If {@link #call()} invocation throws exceptions,
30   * we will call {@link #throwable(Throwable, boolean)} with whatever the exception was.
31   * @param <T>
32   */
33  @InterfaceAudience.Public
34  @InterfaceStability.Stable
35  public interface RetryingCallable<T> extends Callable<T> {
36    /**
37     * Prepare by setting up any connections to servers, etc., ahead of {@link #call()} invocation.
38     * @param reload Set this to true if need to requery locations (usually set on second invocation
39     * to {@link #call()} or whatever
40     * @throws IOException e
41     */
42    void prepare(final boolean reload) throws IOException;
43  
44    /**
45     * Called when {@link #call()} throws an exception and we are going to retry; take action to
46     * make it so we succeed on next call (clear caches, do relookup of locations, etc.).
47     * @param t
48     * @param retrying True if we are in retrying mode (we are not in retrying mode when max
49     * retries == 1; we ARE in retrying mode if retries > 1 even when we are the last attempt)
50     */
51    void throwable(final Throwable t, boolean retrying);
52  
53    /**
54     * @return Some details from the implementation that we would like to add to a terminating
55     * exception; i.e. a fatal exception is being thrown ending retries and we might like to add
56     * more implementation-specific detail on to the exception being thrown.
57     */
58    String getExceptionMessageAdditionalDetail();
59  
60    /**
61     * @param pause
62     * @param tries
63     * @return Suggestion on how much to sleep between retries
64     */
65    long sleep(final long pause, final int tries);
66  }