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