Class HttpBackOffUnsuccessfulResponseHandler
- All Implemented Interfaces:
HttpUnsuccessfulResponseHandler
Beta Back-off handler which handles an abnormal HTTP response with
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
- Since:
- 1.15
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal BackOffReturns the back-off.Returns theHttpBackOffUnsuccessfulResponseHandler.BackOffRequiredinstance which determines if back-off is required based on an abnormal HTTP response.final SleeperReturns the sleeper.booleanhandleResponse(HttpRequest request, HttpResponse response, boolean supportsRetry) Handler that will be invoked when an abnormal response is received.setBackOffRequired(HttpBackOffUnsuccessfulResponseHandler.BackOffRequired backOffRequired) Sets theHttpBackOffUnsuccessfulResponseHandler.BackOffRequiredinstance which determines if back-off is required based on an abnormal HTTP response.setSleeper(Sleeper sleeper) Sets the sleeper.
-
Field Details
-
backOff
Back-off policy. -
backOffRequired
Defines if back-off is required based on an abnormal HTTP response. -
sleeper
Sleeper.
-
-
Constructor Details
-
HttpBackOffUnsuccessfulResponseHandler
-
-
Method Details
-
getBackOff
Returns the back-off. -
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
Returns the sleeper. -
setSleeper
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 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:
IOException
-