RESOLVED - issue BATCH-1487: Adding getters to retry beans

This commit is contained in:
dsyer
2010-01-19 09:07:54 +00:00
parent 82947d6401
commit fc09b8c33f
4 changed files with 75 additions and 14 deletions

View File

@@ -21,13 +21,17 @@ import org.springframework.util.ClassUtils;
/**
* Implementation of {@link BackOffPolicy} that increases the back off period
* for each retry attempt in a given set using the
* {@link Math#exp(double) exponential} function. <p/> This implementation is
* thread-safe and suitable for concurrent access. Modifications to the
* configuration do not affect any retry sets that are already in progress. <p/>
* The {@link #setInitialInterval(long)} property controls the initial value passed to
* {@link Math#exp(double)} and the {@link #setMultiplier(double)} property controls by
* how much this value is increased for each subsequent attempt.
* for each retry attempt in a given set using the {@link Math#exp(double)
* exponential} function.
* <p/>
* This implementation is thread-safe and suitable for concurrent access.
* Modifications to the configuration do not affect any retry sets that are
* already in progress.
* <p/>
* The {@link #setInitialInterval(long)} property controls the initial value
* passed to {@link Math#exp(double)} and the {@link #setMultiplier(double)}
* property controls by how much this value is increased for each subsequent
* attempt.
*
* @author Rob Harrop
* @author Dave Syer
@@ -77,7 +81,7 @@ public class ExponentialBackOffPolicy implements BackOffPolicy {
}
/**
* Set the initial sleep interval value. Default is <code>1</code>
* Set the initial sleep interval value. Default is <code>100</code>
* millisecond. Cannot be set to a value less than one.
*/
public void setInitialInterval(long initialInterval) {
@@ -85,7 +89,9 @@ public class ExponentialBackOffPolicy implements BackOffPolicy {
}
/**
* Set the multiplier value. Default is '<code>1.0</code>'.
* Set the multiplier value. Default is '<code>2.0</code>'. Hint: do not use
* values much in excess of 1.0 (or the backoff will get very long very
* fast).
*/
public void setMultiplier(double multiplier) {
this.multiplier = (multiplier > 1.0 ? multiplier : 1.0);
@@ -94,7 +100,8 @@ public class ExponentialBackOffPolicy implements BackOffPolicy {
/**
* Setter for maximum back off period. Default is 30000 (30 seconds). the
* value will be reset to 1 if this method is called with a value less than
* 1.
* 1. Set this to avoid infinite waits if backing off a large number of
* times (or if the multiplier is set too high).
*
* @param maxInterval in milliseconds.
*/
@@ -103,15 +110,43 @@ public class ExponentialBackOffPolicy implements BackOffPolicy {
}
/**
* Returns a new instance of {@link BackOffContext} configured
* with the 'expSeed' and 'increment' values.
* The initial period to sleep on the first backoff.
* @return the initial interval
*/
public long getInitialInterval() {
return initialInterval;
}
/**
* The maximum interval to sleep for. Defaults to 30 seconds.
*
* @return the maximum interval.
*/
public long getMaxInterval() {
return maxInterval;
}
/**
* The multiplier to use to generate the next backoff interval from the
* last.
*
* @return the multiplier in use
*/
public double getMultiplier() {
return multiplier;
}
/**
* Returns a new instance of {@link BackOffContext} configured with the
* 'expSeed' and 'increment' values.
*/
public BackOffContext start(RetryContext context) {
return new ExponentialBackOffContext(this.initialInterval, this.multiplier, this.maxInterval);
}
/**
* Pause for a length of time equal to '<code>exp(backOffContext.expSeed)</code>'.
* Pause for a length of time equal to '
* <code>exp(backOffContext.expSeed)</code>'.
*/
public void backOff(BackOffContext backOffContext) throws BackOffInterruptedException {
ExponentialBackOffContext context = (ExponentialBackOffContext) backOffContext;

View File

@@ -58,6 +58,14 @@ public class FixedBackOffPolicy extends StatelessBackOffPolicy {
this.backOffPeriod = (backOffPeriod > 0 ? backOffPeriod : 1);
}
/**
* The backoff period in milliseconds.
* @return the backoff period
*/
public long getBackOffPeriod() {
return backOffPeriod;
}
/**
* Pause for the {@link #setBackOffPeriod(long)}.
* @throws BackOffInterruptedException if interrupted during sleep.

View File

@@ -84,6 +84,15 @@ public class SimpleRetryPolicy implements RetryPolicy {
this.maxAttempts = retryAttempts;
}
/**
* The maximum number of retry attempts before failure.
*
* @return the maximum number of attempts
*/
public int getMaxAttempts() {
return maxAttempts;
}
/**
* Test for retryable operation based on the status.
*

View File

@@ -37,12 +37,21 @@ public class TimeoutRetryPolicy implements RetryPolicy {
private long timeout = DEFAULT_TIMEOUT;
/**
* Setter for timeout. Default is {@link #DEFAULT_TIMEOUT}.
* Setter for timeout in milliseconds. Default is {@link #DEFAULT_TIMEOUT}.
* @param timeout
*/
public void setTimeout(long timeout) {
this.timeout = timeout;
}
/**
* The value of the timeout.
*
* @return the timeout in milliseconds
*/
public long getTimeout() {
return timeout;
}
/**
* Only permits a retry if the timeout has not expired. Does not check the