diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/backoff/ExponentialBackOffPolicy.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/backoff/ExponentialBackOffPolicy.java index 443a62218..594d2dafe 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/backoff/ExponentialBackOffPolicy.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/backoff/ExponentialBackOffPolicy.java @@ -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.
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. - * 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. + * + * 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. + * + * 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 is1
+ * Set the initial sleep interval value. Default is 100
* 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 '1.0'.
+ * Set the multiplier value. Default is '2.0'. 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 'exp(backOffContext.expSeed)'.
+ * Pause for a length of time equal to '
+ * exp(backOffContext.expSeed)'.
*/
public void backOff(BackOffContext backOffContext) throws BackOffInterruptedException {
ExponentialBackOffContext context = (ExponentialBackOffContext) backOffContext;
diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/backoff/FixedBackOffPolicy.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/backoff/FixedBackOffPolicy.java
index c65d581e1..cfdd0eb05 100644
--- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/backoff/FixedBackOffPolicy.java
+++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/backoff/FixedBackOffPolicy.java
@@ -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.
diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/policy/SimpleRetryPolicy.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/policy/SimpleRetryPolicy.java
index 4ebecef9e..e3c8af509 100644
--- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/policy/SimpleRetryPolicy.java
+++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/policy/SimpleRetryPolicy.java
@@ -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.
*
diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/policy/TimeoutRetryPolicy.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/policy/TimeoutRetryPolicy.java
index bfc7d3952..d49acb95c 100644
--- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/policy/TimeoutRetryPolicy.java
+++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/policy/TimeoutRetryPolicy.java
@@ -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