@Beta public class HttpBackOffUnsuccessfulResponseHandler extends Object implements HttpUnsuccessfulResponseHandler
Beta
BackOff
.
It is designed to work with only one HttpRequest
at a time. As a result you MUST
create a new instance of HttpBackOffUnsuccessfulResponseHandler
with a new instance of
BackOff
for each instance of HttpRequest
.
Sample usage:
request.setUnsuccessfulResponseHandler( new HttpBackOffUnsuccessfulResponseHandler(new ExponentialBackOff()));
Note: Implementation doesn't call BackOff.reset()
at all, since it expects a new BackOff
instance.
Implementation is not thread-safe
Modifier and Type | Class and Description |
---|---|
static interface |
HttpBackOffUnsuccessfulResponseHandler.BackOffRequired
|
Constructor and Description |
---|
HttpBackOffUnsuccessfulResponseHandler(BackOff backOff)
Constructs a new instance from a
BackOff . |
Modifier and Type | Method and Description |
---|---|
BackOff |
getBackOff()
Returns the back-off.
|
HttpBackOffUnsuccessfulResponseHandler.BackOffRequired |
getBackOffRequired()
Returns the
HttpBackOffUnsuccessfulResponseHandler.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 the
HttpBackOffUnsuccessfulResponseHandler.BackOffRequired instance which determines if back-off is required based on an
abnormal HTTP response. |
HttpBackOffUnsuccessfulResponseHandler |
setSleeper(Sleeper sleeper)
Sets the sleeper.
|
public final BackOff getBackOff()
public final HttpBackOffUnsuccessfulResponseHandler.BackOffRequired getBackOffRequired()
HttpBackOffUnsuccessfulResponseHandler.BackOffRequired
instance which determines if back-off is required based on
an abnormal HTTP response.public HttpBackOffUnsuccessfulResponseHandler setBackOffRequired(HttpBackOffUnsuccessfulResponseHandler.BackOffRequired backOffRequired)
HttpBackOffUnsuccessfulResponseHandler.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.
public final Sleeper getSleeper()
public HttpBackOffUnsuccessfulResponseHandler setSleeper(Sleeper 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.
public boolean handleResponse(HttpRequest request, HttpResponse response, boolean supportsRetry) throws IOException
Handles the request with BackOff
. That means that if back-off is required a call to
Sleeper.sleep(long)
will be made.
handleResponse
in interface HttpUnsuccessfulResponseHandler
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 return true
. 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).IOException
Copyright © 2011–2023 Google. All rights reserved.