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 * A Callable<T> that will be retried. If {@link #call(int)} invocation throws exceptions, we 025 * will call {@link #throwable(Throwable, boolean)} with whatever the exception was. 026 * @param <T> result class from executing <tt>this</tt> 027 */ 028@InterfaceAudience.Private 029public interface RetryingCallable<T> { 030 /** 031 * Prepare by setting up any connections to servers, etc., ahead of call invocation. TODO: We call 032 * prepare before EVERY call. Seems wrong. FIX!!!! 033 * @param reload Set this to true if need to requery locations 034 * @throws IOException e 035 */ 036 void prepare(final boolean reload) throws IOException; 037 038 /** 039 * Called when call throws an exception and we are going to retry; take action to make it so we 040 * succeed on next call (clear caches, do relookup of locations, etc.). 041 * @param t throwable which was thrown 042 * @param retrying True if we are in retrying mode (we are not in retrying mode when max retries 043 * == 1; we ARE in retrying mode if retries > 1 even when we are the last 044 * attempt) 045 */ 046 void throwable(final Throwable t, boolean retrying); 047 048 /** 049 * Returns Some details from the implementation that we would like to add to a terminating 050 * exception; i.e. a fatal exception is being thrown ending retries and we might like to add more 051 * implementation-specific detail on to the exception being thrown. 052 */ 053 String getExceptionMessageAdditionalDetail(); 054 055 /** 056 * Sleep and retry. 057 * @param pause time to pause 058 * @param tries amount of tries until till sleep 059 * @return Suggestion on how much to sleep between retries 060 */ 061 long sleep(final long pause, final int tries); 062 063 /** 064 * Computes a result, or throws an exception if unable to do so. 065 * @param callTimeout - the time available for this call. 0 for infinite. 066 * @return computed result 067 * @throws Exception if unable to compute a result 068 */ 069 T call(int callTimeout) throws Exception; 070}