From c2ea3501854599ea62990ecfdd8f47aad2d2feab Mon Sep 17 00:00:00 2001 From: dsyer Date: Fri, 28 Sep 2007 09:04:27 +0000 Subject: [PATCH] Javadocs --- .../aop/RepeatOperationsInterceptor.java | 43 ++++++++++++------- .../retry/aop/RetryOperationsInterceptor.java | 16 ++++--- 2 files changed, 39 insertions(+), 20 deletions(-) diff --git a/infrastructure/src/main/java/org/springframework/batch/repeat/aop/RepeatOperationsInterceptor.java b/infrastructure/src/main/java/org/springframework/batch/repeat/aop/RepeatOperationsInterceptor.java index 160d4b54a..247310e15 100644 --- a/infrastructure/src/main/java/org/springframework/batch/repeat/aop/RepeatOperationsInterceptor.java +++ b/infrastructure/src/main/java/org/springframework/batch/repeat/aop/RepeatOperationsInterceptor.java @@ -28,21 +28,32 @@ import org.springframework.batch.repeat.support.RepeatTemplate; import org.springframework.util.Assert; /** + * A {@link MethodInterceptor} that can be used to automatically repeat calls to + * a method on a service. The injected {@link RepeatOperations} is used to + * control the completion of the loop. By default it will repeat until the + * target method returns null. Be careful when injecting a bespoke + * {@link RepeatOperations} that the loop will actually terminate, because the + * default policy for a vanilla {@link RepeatTemplate} will never complete if + * the return type of the target method is void (the value returned is always + * not-null, representing the {@link Void#TYPE}). + * * @author Dave Syer * @since 2.1 */ public class RepeatOperationsInterceptor implements MethodInterceptor { - private RepeatOperations batchTempate = new RepeatTemplate(); + private RepeatOperations repeatOperations = new RepeatTemplate(); /** * Setter for the {@link RepeatOperations}. + * * @param batchTempate - * @throws IllegalArgumentException if the argument is null. + * @throws IllegalArgumentException + * if the argument is null. */ public void setRepeatOperations(RepeatOperations batchTempate) { - Assert.notNull(batchTempate, "'batchTemplate' cannot be null."); - this.batchTempate = batchTempate; + Assert.notNull(batchTempate, "'repeatOperations' cannot be null."); + this.repeatOperations = batchTempate; } /** @@ -53,9 +64,10 @@ public class RepeatOperationsInterceptor implements MethodInterceptor { */ public Object invoke(final MethodInvocation invocation) throws Throwable { - batchTempate.iterate(new RepeatCallback() { + repeatOperations.iterate(new RepeatCallback() { - public ExitStatus doInIteration(RepeatContext context) throws Exception { + public ExitStatus doInIteration(RepeatContext context) + throws Exception { try { MethodInvocation clone = invocation; @@ -63,28 +75,29 @@ public class RepeatOperationsInterceptor implements MethodInterceptor { clone = ((ReflectiveMethodInvocation) invocation) .invocableClone(); } else { - throw new IllegalStateException("MethodInvocation of the wrong type detected - this should not happen with Spring AOP, so please raise an issue if you see this exception"); + throw new IllegalStateException( + "MethodInvocation of the wrong type detected - this should not happen with Spring AOP, so please raise an issue if you see this exception"); } - + // N.B. discards return value if there is one - if (clone.getMethod().getGenericReturnType().equals(Void.TYPE)) { + if (clone.getMethod().getGenericReturnType().equals( + Void.TYPE)) { clone.proceed(); return ExitStatus.CONTINUABLE; } return new ExitStatus(clone.proceed() != null); - } - catch (Throwable e) { + } catch (Throwable e) { if (e instanceof Exception) { throw (Exception) e; - } - else { - throw new RepeatException("Unexpected error in batch interceptor", e); + } else { + throw new RepeatException( + "Unexpected error in batch interceptor", e); } } } }); - + return null; } diff --git a/infrastructure/src/main/java/org/springframework/batch/retry/aop/RetryOperationsInterceptor.java b/infrastructure/src/main/java/org/springframework/batch/retry/aop/RetryOperationsInterceptor.java index 7d416586e..864fca155 100644 --- a/infrastructure/src/main/java/org/springframework/batch/retry/aop/RetryOperationsInterceptor.java +++ b/infrastructure/src/main/java/org/springframework/batch/retry/aop/RetryOperationsInterceptor.java @@ -26,22 +26,27 @@ import org.springframework.batch.retry.support.RetryTemplate; import org.springframework.util.Assert; /** + * A {@link MethodInterceptor} that can be used to automatically retry calls to + * a method on a service if it fails. The injected {@link RetryOperations} is + * used to control the number of retries. By default it will retry a fixed + * number of times, according to the defaults in {@link RetryTemplate}. + * * @author Rob Harrop * @author Dave Syer * @since 2.1 */ public class RetryOperationsInterceptor implements MethodInterceptor { - private RetryOperations retryTemplate = new RetryTemplate(); + private RetryOperations retryOperations = new RetryTemplate(); public void setRetryTemplate(RetryOperations retryTemplate) { - Assert.notNull(retryTemplate, "'retryTemplate' cannot be null."); - this.retryTemplate = retryTemplate; + Assert.notNull(retryTemplate, "'retryOperations' cannot be null."); + this.retryOperations = retryTemplate; } public Object invoke(final MethodInvocation invocation) throws Throwable { // TODO: use the method name to initialise a statistics context - return this.retryTemplate.execute(new RetryCallback() { + return this.retryOperations.execute(new RetryCallback() { public Object doWithRetry(RetryContext context) throws Throwable { @@ -57,7 +62,8 @@ public class RetryOperationsInterceptor implements MethodInterceptor { clone = ((ReflectiveMethodInvocation) invocation) .invocableClone(); } else { - throw new IllegalStateException("MethodInvocation of the wrong type detected - this should not happen with Spring AOP, so please raise an issue if you see this exception"); + throw new IllegalStateException( + "MethodInvocation of the wrong type detected - this should not happen with Spring AOP, so please raise an issue if you see this exception"); } return clone.proceed();