org.jclouds.http.handlers
Class BackoffLimitedRetryHandler
java.lang.Object
org.jclouds.http.handlers.BackoffLimitedRetryHandler
- All Implemented Interfaces:
- HttpRetryHandler, IOExceptionRetryHandler
- Direct Known Subclasses:
- InvalidateSessionAndRetryOn401AndLogoutOnClose
@Singleton
public class BackoffLimitedRetryHandler
- extends Object
- implements HttpRetryHandler, IOExceptionRetryHandler
Allow replayable request to be retried a limited number of times, and impose an exponential
back-off delay before returning.
The back-off delay grows rapidly according to the formula
50 * (HttpCommand.getFailureCount()
^ 2)
. For example:
Number of Attempts |
Delay in milliseconds |
1 |
50 |
2 |
200 |
3 |
450 |
4 |
800 |
5 |
1250 |
This implementation has two side-effects. It increments the command's failure count with
HttpCommand.incrementFailureCount()
, because this failure count value is used
to determine how many times the command has already been tried. It also closes the response's
content input stream to ensure connections are cleaned up.
- Author:
- James Murty
Method Summary |
void |
imposeBackoffExponentialDelay(int failureCount,
String commandDescription)
|
void |
imposeBackoffExponentialDelay(long period,
int pow,
int failureCount,
int max,
String commandDescription)
|
void |
imposeBackoffExponentialDelay(long period,
long maxPeriod,
int pow,
int failureCount,
int max,
String commandDescription)
|
boolean |
shouldRetryRequest(HttpCommand command,
HttpResponse response)
Return true if the command should be retried. |
boolean |
shouldRetryRequest(HttpCommand command,
IOException error)
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
INSTANCE
public static BackoffLimitedRetryHandler INSTANCE
logger
protected Logger logger
BackoffLimitedRetryHandler
public BackoffLimitedRetryHandler()
shouldRetryRequest
public boolean shouldRetryRequest(HttpCommand command,
IOException error)
- Specified by:
shouldRetryRequest
in interface IOExceptionRetryHandler
shouldRetryRequest
public boolean shouldRetryRequest(HttpCommand command,
HttpResponse response)
- Description copied from interface:
HttpRetryHandler
- Return true if the command should be retried. This method should only be invoked when the
response has failed with a HTTP 5xx error indicating a server-side error.
- Specified by:
shouldRetryRequest
in interface HttpRetryHandler
imposeBackoffExponentialDelay
public void imposeBackoffExponentialDelay(int failureCount,
String commandDescription)
imposeBackoffExponentialDelay
public void imposeBackoffExponentialDelay(long period,
int pow,
int failureCount,
int max,
String commandDescription)
imposeBackoffExponentialDelay
public void imposeBackoffExponentialDelay(long period,
long maxPeriod,
int pow,
int failureCount,
int max,
String commandDescription)
Copyright © 2009-2012 jclouds. All Rights Reserved.