Package com.ibm.cloud.sdk.core.http
Class RetryInterceptor
- java.lang.Object
-
- com.ibm.cloud.sdk.core.http.RetryInterceptor
-
- All Implemented Interfaces:
IRetryInterceptor,okhttp3.Interceptor
public class RetryInterceptor extends java.lang.Object implements IRetryInterceptor
This class is an okhttp Interceptor implementation that will try to automatically retry failed requests, based on the type of failure that occurred. This class is configured with the following:- the maximum number of retries to attempt for a failed request
- the maximum retry interval (in seconds) to wait between retry attempts
- the
Authenticatorinstance to use to authenticate each retry attempt
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classRetryInterceptor.RetryContext
-
Constructor Summary
Constructors Constructor Description RetryInterceptor(int maxRetries, int maxRetryInterval, Authenticator authenticator)This ctor configures the RetryInterceptor instance with the max retries, retry interval and an authenticator.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description okhttp3.Responseintercept(okhttp3.Interceptor.Chain chain)The "intercept()" method is the primary method of the interceptor.
-
-
-
Constructor Detail
-
RetryInterceptor
public RetryInterceptor(int maxRetries, int maxRetryInterval, Authenticator authenticator)This ctor configures the RetryInterceptor instance with the max retries, retry interval and an authenticator.- Parameters:
maxRetries- the maximum number of retries to attempt for a failed requestmaxRetryInterval- the maximum retry interval (in seconds) to wait between retry attemptsauthenticator- theAuthenticatorinstance to use to authenticate retried requests
-
-
Method Detail
-
intercept
public okhttp3.Response intercept(okhttp3.Interceptor.Chain chain) throws java.io.IOExceptionThe "intercept()" method is the primary method of the interceptor. The chain of interceptors registered for a particular okhttp Client instance is in the form of an ordered list. When a request is invoked, each interceptor's "intercept" method is invoked and is passed the interceptor chain. The interceptor can inspect the request to determine how to proceed, and will invoke the interceptor chain's "proceed()" method to call the next interceptor in the chain. When the last interceptor invokes the chain's "proceed()" method, the request is sent over the wire and the response is returned via the return value of the proceed() method. The interceptor can then inspect the response and determine how to proceed. Ultimately the response is returned from this intercept() method and is ultimately propagated back through the chain's "proceed()" methods.- Specified by:
interceptin interfaceokhttp3.Interceptor- Throws:
java.io.IOException
-
-