From 8ab844550dd4c5516db24ba6e51127f0ec1f0f73 Mon Sep 17 00:00:00 2001 From: Michael Minella Date: Thu, 27 Sep 2012 14:31:37 -0500 Subject: [PATCH 1/2] BATCH-1706: Documented chunk and tasklet elements --- .../configuration/xml/spring-batch-2.1.xsd | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/spring-batch-core/src/main/resources/org/springframework/batch/core/configuration/xml/spring-batch-2.1.xsd b/spring-batch-core/src/main/resources/org/springframework/batch/core/configuration/xml/spring-batch-2.1.xsd index ab1874479..6deb50c1d 100644 --- a/spring-batch-core/src/main/resources/org/springframework/batch/core/configuration/xml/spring-batch-2.1.xsd +++ b/spring-batch-core/src/main/resources/org/springframework/batch/core/configuration/xml/spring-batch-2.1.xsd @@ -387,7 +387,16 @@ ref" is not required, and only needs to be specified explicitly - + + + + + + @@ -542,7 +551,15 @@ ref" is not required, and only needs to be specified explicitly - + + + + + + From 6779d49d3cc82b7ccb682e90b62793a47952975b Mon Sep 17 00:00:00 2001 From: Michael Minella Date: Fri, 28 Sep 2012 13:37:54 -0500 Subject: [PATCH 2/2] BATCH-1718: Added optimistic flag Added optimistic flag to allow configuration for optimistic or pessimistic evaluation of retry policies. --- .../retry/policy/CompositeRetryPolicy.java | 38 ++++++++++++++++--- .../policy/CompositeRetryPolicyTests.java | 14 ++++++- 2 files changed, 45 insertions(+), 7 deletions(-) diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/policy/CompositeRetryPolicy.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/policy/CompositeRetryPolicy.java index a379b38fb..183c37347 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/policy/CompositeRetryPolicy.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/policy/CompositeRetryPolicy.java @@ -29,12 +29,23 @@ import org.springframework.batch.retry.context.RetryContextSupport; * calls to them in order. * * @author Dave Syer + * @author Michael Minella * */ public class CompositeRetryPolicy implements RetryPolicy { RetryPolicy[] policies = new RetryPolicy[0]; + private boolean optimistic = false; + /** + * Setter for the optimistic flag. + * + * @param optimistic + */ + public void setOptimistic(boolean optimistic) { + this.optimistic = optimistic; + } + /** * Setter for policies. * @@ -46,20 +57,35 @@ public class CompositeRetryPolicy implements RetryPolicy { /** * Delegate to the policies that were in operation when the context was - * created. If any of them cannot retry then return false, oetherwise return - * true. + * created. By default, if any of them cannot retry then return false, otherwise return + * true. If the optimistic flag has been set to true and any of them can retry + * return true, otherwise return false. * * @see org.springframework.batch.retry.RetryPolicy#canRetry(org.springframework.batch.retry.RetryContext) */ public boolean canRetry(RetryContext context) { RetryContext[] contexts = ((CompositeRetryContext) context).contexts; RetryPolicy[] policies = ((CompositeRetryContext) context).policies; - for (int i = 0; i < contexts.length; i++) { - if (!policies[i].canRetry(contexts[i])) { - return false; + + boolean retryable = true; + + if(optimistic) { + retryable = false; + for (int i = 0; i < contexts.length; i++) { + if (policies[i].canRetry(contexts[i])) { + retryable = true; + } } } - return true; + else { + for (int i = 0; i < contexts.length; i++) { + if (!policies[i].canRetry(contexts[i])) { + retryable = false; + } + } + } + + return retryable; } /** diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/policy/CompositeRetryPolicyTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/policy/CompositeRetryPolicyTests.java index 99e9d4afd..0f146139e 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/policy/CompositeRetryPolicyTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/policy/CompositeRetryPolicyTests.java @@ -134,5 +134,17 @@ public class CompositeRetryPolicyTests extends TestCase { assertNotSame(child, context); assertSame(context, child.getParent()); } - + + public void testOptimistic() throws Exception { + CompositeRetryPolicy policy = new CompositeRetryPolicy(); + policy.setOptimistic(true); + policy.setPolicies(new RetryPolicy[] { new MockRetryPolicySupport() { + public boolean canRetry(RetryContext context) { + return false; + } + }, new MockRetryPolicySupport() }); + RetryContext context = policy.open(null); + assertNotNull(context); + assertTrue(policy.canRetry(context)); + } }