Class HttpBackOffUnsuccessfulResponseHandler (1.44.2)

public class HttpBackOffUnsuccessfulResponseHandler implements 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

Inheritance

java.lang.Object > HttpBackOffUnsuccessfulResponseHandler

Constructors

HttpBackOffUnsuccessfulResponseHandler(BackOff backOff)

public HttpBackOffUnsuccessfulResponseHandler(BackOff backOff)

Constructs a new instance from a BackOff.

Parameter
Name Description
backOff BackOff

back-off policy

Methods

getBackOff()

public final BackOff getBackOff()

Returns the back-off.

Returns
Type Description
BackOff

getBackOffRequired()

public final HttpBackOffUnsuccessfulResponseHandler.BackOffRequired getBackOffRequired()

Returns the BackOffRequired instance which determines if back-off is required based on an abnormal HTTP response.

Returns
Type Description
HttpBackOffUnsuccessfulResponseHandler.BackOffRequired

getSleeper()

public final Sleeper getSleeper()

Returns the sleeper.

Returns
Type Description
Sleeper

handleResponse(HttpRequest request, HttpResponse response, boolean supportsRetry)

public boolean handleResponse(HttpRequest request, HttpResponse response, boolean supportsRetry)

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 to Sleeper#sleep(long) will be made.

Parameters
Name Description
request HttpRequest
response HttpResponse
supportsRetry boolean
Returns
Type Description
boolean
Exceptions
Type Description
IOException

setBackOffRequired(HttpBackOffUnsuccessfulResponseHandler.BackOffRequired backOffRequired)

public HttpBackOffUnsuccessfulResponseHandler setBackOffRequired(HttpBackOffUnsuccessfulResponseHandler.BackOffRequired backOffRequired)

Sets the BackOffRequired instance which determines if back-off is required based on an abnormal HTTP response.

The default value is BackOffRequired#ON_SERVER_ERROR.

Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.

Parameter
Name Description
backOffRequired HttpBackOffUnsuccessfulResponseHandler.BackOffRequired
Returns
Type Description
HttpBackOffUnsuccessfulResponseHandler

setSleeper(Sleeper sleeper)

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.

Parameter
Name Description
sleeper Sleeper
Returns
Type Description
HttpBackOffUnsuccessfulResponseHandler