Class HttpBackOffUnsuccessfulResponseHandler
- java.lang.Object
-
- com.google.api.client.http.HttpBackOffUnsuccessfulResponseHandler
-
- All Implemented Interfaces:
HttpUnsuccessfulResponseHandler
@Beta public class HttpBackOffUnsuccessfulResponseHandler extends Object implements HttpUnsuccessfulResponseHandler
Beta
Back-off handler which handles an abnormal HTTP response withBackOff
.It is designed to work with only one
HttpRequest
at a time. As a result you MUST create a new instance ofHttpBackOffUnsuccessfulResponseHandler
with a new instance ofBackOff
for each instance ofHttpRequest
.Sample usage:
request.setUnsuccessfulResponseHandler( new HttpBackOffUnsuccessfulResponseHandler(new ExponentialBackOff()));
Note: Implementation doesn't call
BackOff.reset()
at all, since it expects a newBackOff
instance.Implementation is not thread-safe
- Since:
- 1.15
- Author:
- Eyal Peled
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
HttpBackOffUnsuccessfulResponseHandler.BackOffRequired
-
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 BackOff
getBackOff()
Returns the back-off.HttpBackOffUnsuccessfulResponseHandler.BackOffRequired
getBackOffRequired()
Returns theHttpBackOffUnsuccessfulResponseHandler.BackOffRequired
instance which determines if back-off is required based on an abnormal HTTP response.Sleeper
getSleeper()
Returns the sleeper.boolean
handleResponse(HttpRequest request, HttpResponse response, boolean supportsRetry)
Handler that will be invoked when an abnormal response is received.HttpBackOffUnsuccessfulResponseHandler
setBackOffRequired(HttpBackOffUnsuccessfulResponseHandler.BackOffRequired backOffRequired)
Sets theHttpBackOffUnsuccessfulResponseHandler.BackOffRequired
instance which determines if back-off is required based on an abnormal HTTP response.HttpBackOffUnsuccessfulResponseHandler
setSleeper(Sleeper sleeper)
Sets the sleeper.
-
-
-
Method Detail
-
getBackOff
public final BackOff getBackOff()
Returns the back-off.
-
getBackOffRequired
public final HttpBackOffUnsuccessfulResponseHandler.BackOffRequired getBackOffRequired()
Returns theHttpBackOffUnsuccessfulResponseHandler.BackOffRequired
instance which determines if back-off is required based on an abnormal HTTP response.
-
setBackOffRequired
public HttpBackOffUnsuccessfulResponseHandler setBackOffRequired(HttpBackOffUnsuccessfulResponseHandler.BackOffRequired backOffRequired)
Sets theHttpBackOffUnsuccessfulResponseHandler.BackOffRequired
instance 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 final boolean handleResponse(HttpRequest request, HttpResponse response, boolean supportsRetry) throws 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:
handleResponse
in 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:
IOException
-
-