View Javadoc

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 org.apache.hadoop.hbase.classification.InterfaceAudience;
21  
22  /**
23   * The context object used in the {@link RpcRetryingCaller} to enable
24   * {@link RetryingCallerInterceptor} to intercept calls.
25   * {@link RetryingCallerInterceptorContext} is the piece of information unique
26   * to a retrying call that transfers information from the call into the
27   * {@link RetryingCallerInterceptor} so that {@link RetryingCallerInterceptor}
28   * can take appropriate action according to the specific logic
29   *
30   */
31  @InterfaceAudience.Private
32  abstract class RetryingCallerInterceptorContext {
33    protected RetryingCallerInterceptorContext() {
34    }
35  
36    /**
37     * This function clears the internal state of the context object.
38     */
39    public abstract void clear();
40  
41    /**
42     * This prepares the context object by populating it with information specific
43     * to the implementation of the {@link RetryingCallerInterceptor} along with
44     * which this will be used.
45     * 
46     * @param callable
47     *          : The {@link RetryingCallable} that contains the information about
48     *          the call that is being made.
49     * @return A new {@link RetryingCallerInterceptorContext} object that can be
50     *         used for use in the current retrying call
51     */
52    public abstract RetryingCallerInterceptorContext prepare(
53        RetryingCallable<?> callable);
54  
55    /**
56     * Telescopic extension that takes which of the many retries we are currently
57     * in.
58     * 
59     * @param callable
60     *          : The {@link RetryingCallable} that contains the information about
61     *          the call that is being made.
62     * @param tries
63     *          : The retry number that we are currently in.
64     * @return A new context object that can be used for use in the current
65     *         retrying call
66     */
67    public abstract RetryingCallerInterceptorContext prepare(
68        RetryingCallable<?> callable, int tries);
69  }