Class HttpBackOffUnsuccessfulResponseHandler
- java.lang.Object
-
- com.google.api.client.http.HttpBackOffUnsuccessfulResponseHandler
-
- All Implemented Interfaces:
HttpUnsuccessfulResponseHandler
@Beta public class HttpBackOffUnsuccessfulResponseHandler extends java.lang.Object implements HttpUnsuccessfulResponseHandler
Beta
Back-off handler which handles an abnormal HTTP response withBackOff.It is designed to work with only one
HttpRequestat a time. As a result you MUST create a new instance ofHttpBackOffUnsuccessfulResponseHandlerwith a new instance ofBackOfffor each instance ofHttpRequest.Sample usage:
request.setUnsuccessfulResponseHandler( new HttpBackOffUnsuccessfulResponseHandler(new ExponentialBackOff()));
Note: Implementation doesn't call
BackOff.reset()at all, since it expects a newBackOffinstance.Implementation is not thread-safe
- Since:
- 1.15
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceHttpBackOffUnsuccessfulResponseHandler.BackOffRequired
-
Field Summary
Fields Modifier and Type Field Description private BackOffbackOffBack-off policy.private HttpBackOffUnsuccessfulResponseHandler.BackOffRequiredbackOffRequiredDefines if back-off is required based on an abnormal HTTP response.private SleepersleeperSleeper.
-
Constructor Summary
Constructors Constructor Description HttpBackOffUnsuccessfulResponseHandler(BackOff backOff)Constructs a new instance from aBackOff.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description BackOffgetBackOff()Returns the back-off.HttpBackOffUnsuccessfulResponseHandler.BackOffRequiredgetBackOffRequired()Returns theHttpBackOffUnsuccessfulResponseHandler.BackOffRequiredinstance which determines if back-off is required based on an abnormal HTTP response.SleepergetSleeper()Returns the sleeper.booleanhandleResponse(HttpRequest request, HttpResponse response, boolean supportsRetry)Handler that will be invoked when an abnormal response is received.HttpBackOffUnsuccessfulResponseHandlersetBackOffRequired(HttpBackOffUnsuccessfulResponseHandler.BackOffRequired backOffRequired)Sets theHttpBackOffUnsuccessfulResponseHandler.BackOffRequiredinstance which determines if back-off is required based on an abnormal HTTP response.HttpBackOffUnsuccessfulResponseHandlersetSleeper(Sleeper sleeper)Sets the sleeper.
-
-
-
Field Detail
-
backOff
private final BackOff backOff
Back-off policy.
-
backOffRequired
private HttpBackOffUnsuccessfulResponseHandler.BackOffRequired backOffRequired
Defines if back-off is required based on an abnormal HTTP response.
-
sleeper
private Sleeper sleeper
Sleeper.
-
-
Method Detail
-
getBackOff
public final BackOff getBackOff()
Returns the back-off.
-
getBackOffRequired
public final HttpBackOffUnsuccessfulResponseHandler.BackOffRequired getBackOffRequired()
Returns theHttpBackOffUnsuccessfulResponseHandler.BackOffRequiredinstance which determines if back-off is required based on an abnormal HTTP response.
-
setBackOffRequired
public HttpBackOffUnsuccessfulResponseHandler setBackOffRequired(HttpBackOffUnsuccessfulResponseHandler.BackOffRequired backOffRequired)
Sets theHttpBackOffUnsuccessfulResponseHandler.BackOffRequiredinstance which determines if back-off is required based on an abnormal HTTP response.The default value is
HttpBackOffUnsuccessfulResponseHandler.BackOffRequired.ON_SERVER_ERROR.Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.
-
getSleeper
public final Sleeper getSleeper()
Returns the sleeper.
-
setSleeper
public HttpBackOffUnsuccessfulResponseHandler setSleeper(Sleeper sleeper)
Sets the sleeper.The default value is
Sleeper.DEFAULT.Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.
-
handleResponse
public boolean handleResponse(HttpRequest request, HttpResponse response, boolean supportsRetry) throws java.io.IOException
Handler that will be invoked when an abnormal response is received. There are a few simple rules that one must follow:- If you modify the request object or modify its execute interceptors in a way that should resolve the error, you must return true to issue a retry.
- Do not read from the content stream, this will prevent the eventual end user from having access to it.
Handles the request with
BackOff. That means that if back-off is required a call toSleeper.sleep(long)will be made.- Specified by:
handleResponsein interfaceHttpUnsuccessfulResponseHandler- Parameters:
request- Request object that can be read from for context or modified before retryresponse- Response to processsupportsRetry- Whether there will actually be a retry if this handler returntrue. Some handlers may want to have an effect only when there will actually be a retry after they handle their event (e.g. a handler that implements exponential backoff).- Returns:
- Whether or not this handler has made a change that will require the request to be re-sent.
- Throws:
java.io.IOException
-
-