001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package org.apache.hadoop.hbase.client;
019
020import java.io.IOException;
021import org.apache.yetus.audience.InterfaceAudience;
022
023/**
024 * This class is designed to fit into the RetryingCaller class which forms the central piece of
025 * intelligence for the client side retries for most calls. One can extend this class and intercept
026 * the RetryingCaller and add additional logic into the execution of a simple HTable operations like
027 * get, delete etc. Concrete implementations of this calls are supposed to the thread safe. The
028 * object is used across threads to identify the fast failing threads. For a concrete use case see
029 * {@link PreemptiveFastFailInterceptor} Example use case : try { interceptor.intercept doAction() }
030 * catch (Exception e) { interceptor.handleFailure } finally { interceptor.updateFaulireInfo } The
031 * {@link RetryingCallerInterceptor} also acts as a factory for getting a new
032 * {@link RetryingCallerInterceptorContext}.
033 */
034
035@InterfaceAudience.Private
036abstract class RetryingCallerInterceptor {
037
038  protected RetryingCallerInterceptor() {
039    // Empty constructor protected for NoOpRetryableCallerInterceptor
040  }
041
042  /**
043   * This returns the context object for the current call.
044   * @return context : the context that needs to be used during this call.
045   */
046  public abstract RetryingCallerInterceptorContext createEmptyContext();
047
048  /**
049   * Call this function in case we caught a failure during retries. : The context object that we
050   * obtained previously. : The exception that we caught in this particular try
051   */
052  public abstract void handleFailure(RetryingCallerInterceptorContext context, Throwable t)
053    throws IOException;
054
055  /**
056   * Call this function alongside the actual call done on the callable.
057   */
058  public abstract void intercept(
059    RetryingCallerInterceptorContext abstractRetryingCallerInterceptorContext) throws IOException;
060
061  /**
062   * Call this function to update at the end of the retry. This is not necessary to happen.
063   */
064  public abstract void updateFailureInfo(RetryingCallerInterceptorContext context);
065
066  @Override
067  public abstract String toString();
068}