@InterfaceAudience.Private public class RpcRetryingCaller<T> extends Object
RetryingCallable
. Sets into rpc client
threadlocal outstanding timeouts as so we don't persist too much.
Dynamic rather than static so can set the generic appropriately.
This object has a state. It should not be used by in parallel by different threads.
Reusing it is possible however, even between multiple threads. However, the user will
have to manage the synchronization on its side: there is no synchronization inside the class.Modifier and Type | Field and Description |
---|---|
private AtomicBoolean |
cancelled |
private RetryingCallerInterceptorContext |
context |
private long |
globalStartTime
When we started making calls.
|
private RetryingCallerInterceptor |
interceptor |
static org.apache.commons.logging.Log |
LOG |
private static int |
MIN_RPC_TIMEOUT
Start and end times for a single call.
|
private long |
pause |
private int |
retries |
private int |
rpcTimeout |
private int |
startLogErrorsCnt
How many retries are allowed before we start to log
|
Constructor and Description |
---|
RpcRetryingCaller(long pause,
int retries,
int startLogErrorsCnt) |
RpcRetryingCaller(long pause,
int retries,
RetryingCallerInterceptor interceptor,
int startLogErrorsCnt,
int rpcTimeout) |
Modifier and Type | Method and Description |
---|---|
T |
callWithoutRetries(RetryingCallable<T> callable,
int callTimeout)
Call the server once only.
|
T |
callWithRetries(RetryingCallable<T> callable,
int callTimeout)
Retries if invocation fails.
|
void |
cancel() |
private int |
getRemainingTime(int callTimeout) |
private int |
getTimeout(int callTimeout) |
private long |
singleCallDuration(long expectedSleep) |
String |
toString() |
(package private) static Throwable |
translateException(Throwable t)
Get the good or the remote exception if any, throws the DoNotRetryIOException.
|
public static final org.apache.commons.logging.Log LOG
private long globalStartTime
private static final int MIN_RPC_TIMEOUT
private final int startLogErrorsCnt
private final long pause
private final int retries
private final int rpcTimeout
private final AtomicBoolean cancelled
private final RetryingCallerInterceptor interceptor
private final RetryingCallerInterceptorContext context
public RpcRetryingCaller(long pause, int retries, int startLogErrorsCnt)
public RpcRetryingCaller(long pause, int retries, RetryingCallerInterceptor interceptor, int startLogErrorsCnt, int rpcTimeout)
private int getRemainingTime(int callTimeout)
private int getTimeout(int callTimeout)
public void cancel()
public T callWithRetries(RetryingCallable<T> callable, int callTimeout) throws IOException, RuntimeException
callTimeout
- Timeout for this callcallable
- The RetryingCallable
to run.IOException
- if a remote or network exception occursRuntimeException
- other unspecified errorprivate long singleCallDuration(long expectedSleep)
public T callWithoutRetries(RetryingCallable<T> callable, int callTimeout) throws IOException, RuntimeException
RetryingCallable
has a strange shape so we can do retrys. Use this invocation if you
want to do a single call only (A call to RetryingCallable.call(int)
will not likely
succeed).IOException
- if a remote or network exception occursRuntimeException
- other unspecified errorstatic Throwable translateException(Throwable t) throws DoNotRetryIOException
t
- the throwable to analyzeDoNotRetryIOException
- - if we find it, we throw it instead of translating.Copyright © 2007–2019 The Apache Software Foundation. All rights reserved.