diff --git a/pom.xml b/pom.xml index b4ed558..dcd916a 100644 --- a/pom.xml +++ b/pom.xml @@ -209,8 +209,8 @@ org.apache.maven.plugins maven-compiler-plugin - 1.7 - 1.7 + 1.6 + 1.6 diff --git a/src/main/java/org/springframework/retry/annotation/AnnotationAwareRetryOperationsInterceptor.java b/src/main/java/org/springframework/retry/annotation/AnnotationAwareRetryOperationsInterceptor.java index 613c0e7..3758a49 100644 --- a/src/main/java/org/springframework/retry/annotation/AnnotationAwareRetryOperationsInterceptor.java +++ b/src/main/java/org/springframework/retry/annotation/AnnotationAwareRetryOperationsInterceptor.java @@ -23,6 +23,7 @@ import java.util.concurrent.atomic.AtomicBoolean; import org.aopalliance.intercept.MethodInterceptor; import org.aopalliance.intercept.MethodInvocation; +import org.springframework.aop.IntroductionInterceptor; import org.springframework.core.annotation.AnnotationUtils; import org.springframework.retry.RetryPolicy; import org.springframework.retry.backoff.BackOffPolicy; @@ -44,14 +45,14 @@ import org.springframework.util.ReflectionUtils; import org.springframework.util.ReflectionUtils.MethodCallback; /** - * Wrapper interceptor that interprets the retry metadata on the method it is invoking and + * WrappeMethodInterceptorr interceptor that interprets the retry metadata on the method it is invoking and * delegates to an appropriate RetryOperationsInterceptor. * * @author Dave Syer * @since 2.0 * */ -public class AnnotationAwareRetryOperationsInterceptor implements MethodInterceptor { +public class AnnotationAwareRetryOperationsInterceptor implements IntroductionInterceptor { private Map delegates = new HashMap(); @@ -99,6 +100,11 @@ public class AnnotationAwareRetryOperationsInterceptor implements MethodIntercep return delegate.invoke(invocation); } + @Override + public boolean implementsInterface(Class intf) { + return Retryable.class.isAssignableFrom(intf); + } + private MethodInterceptor getDelegate(Object target, Method method) { if (!delegates.containsKey(method)) { synchronized (delegates) { diff --git a/src/main/java/org/springframework/retry/interceptor/RetryOperationsInterceptor.java b/src/main/java/org/springframework/retry/interceptor/RetryOperationsInterceptor.java index 3c20868..cf0db0f 100644 --- a/src/main/java/org/springframework/retry/interceptor/RetryOperationsInterceptor.java +++ b/src/main/java/org/springframework/retry/interceptor/RetryOperationsInterceptor.java @@ -17,7 +17,6 @@ import java.util.Arrays; import org.aopalliance.intercept.MethodInterceptor; import org.aopalliance.intercept.MethodInvocation; -import org.springframework.aop.IntroductionInterceptor; import org.springframework.aop.ProxyMethodInvocation; import org.springframework.retry.RecoveryCallback; import org.springframework.retry.RetryCallback; @@ -42,7 +41,7 @@ import org.springframework.util.Assert; * @author Rob Harrop * @author Dave Syer */ -public class RetryOperationsInterceptor implements IntroductionInterceptor { +public class RetryOperationsInterceptor implements MethodInterceptor { private RetryOperations retryOperations = new RetryTemplate(); private MethodInvocationRecoverer recoverer; @@ -56,11 +55,6 @@ public class RetryOperationsInterceptor implements IntroductionInterceptor { this.recoverer = recoverer; } - @Override - public boolean implementsInterface(Class intf) { - return Retryable.class.isAssignableFrom(intf); - } - public Object invoke(final MethodInvocation invocation) throws Throwable { RetryCallback retryCallback = new RetryCallback() { diff --git a/src/main/java/org/springframework/retry/interceptor/StatefulRetryOperationsInterceptor.java b/src/main/java/org/springframework/retry/interceptor/StatefulRetryOperationsInterceptor.java index 6a20d37..50754f8 100644 --- a/src/main/java/org/springframework/retry/interceptor/StatefulRetryOperationsInterceptor.java +++ b/src/main/java/org/springframework/retry/interceptor/StatefulRetryOperationsInterceptor.java @@ -22,7 +22,6 @@ import org.aopalliance.intercept.MethodInterceptor; import org.aopalliance.intercept.MethodInvocation; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.springframework.aop.IntroductionInterceptor; import org.springframework.retry.RecoveryCallback; import org.springframework.retry.RetryCallback; import org.springframework.retry.RetryContext; @@ -52,7 +51,7 @@ import org.springframework.util.ObjectUtils; * * @author Dave Syer */ -public class StatefulRetryOperationsInterceptor implements IntroductionInterceptor { +public class StatefulRetryOperationsInterceptor implements MethodInterceptor { private transient Log logger = LogFactory.getLog(getClass()); @@ -106,11 +105,6 @@ public class StatefulRetryOperationsInterceptor implements IntroductionIntercept this.newMethodArgumentsIdentifier = newMethodArgumentsIdentifier; } - @Override - public boolean implementsInterface(Class intf) { - return Retryable.class.isAssignableFrom(intf); - } - /** * Wrap the method invocation in a stateful retry with the policy and other helpers * provided. If there is a failure the exception will generally be re-thrown. The only diff --git a/src/test/java/org/springframework/retry/annotation/EnableRetryWithBackoffTests.java b/src/test/java/org/springframework/retry/annotation/EnableRetryWithBackoffTests.java index 0f19b82..84396c0 100644 --- a/src/test/java/org/springframework/retry/annotation/EnableRetryWithBackoffTests.java +++ b/src/test/java/org/springframework/retry/annotation/EnableRetryWithBackoffTests.java @@ -28,9 +28,6 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.EnableAspectJAutoProxy; -import org.springframework.retry.annotation.Backoff; -import org.springframework.retry.annotation.EnableRetry; -import org.springframework.retry.annotation.Retryable; import org.springframework.retry.backoff.Sleeper; /** @@ -45,7 +42,8 @@ public class EnableRetryWithBackoffTests { TestConfiguration.class); Service service = context.getBean(Service.class); service.service(); - assertEquals("[1000, 1000]", context.getBean(TestConfiguration.class).periods.toString()); + assertEquals("[1000, 1000]", context.getBean(PeriodSleeper.class) + .getPeriods().toString()); assertEquals(3, service.getCount()); context.close(); } @@ -56,8 +54,8 @@ public class EnableRetryWithBackoffTests { TestConfiguration.class); RandomService service = context.getBean(RandomService.class); service.service(); - List periods = context.getBean(TestConfiguration.class).periods; - assertTrue("Wrong periods: " + periods, periods.get(0)>1000); + List periods = context.getBean(PeriodSleeper.class).getPeriods(); + assertTrue("Wrong periods: " + periods, periods.get(0) > 1000); assertEquals(3, service.getCount()); context.close(); } @@ -69,7 +67,8 @@ public class EnableRetryWithBackoffTests { ExponentialService service = context.getBean(ExponentialService.class); service.service(); assertEquals(3, service.getCount()); - assertEquals("[1000, 1100]", context.getBean(TestConfiguration.class).periods.toString()); + assertEquals("[1000, 1100]", context.getBean(PeriodSleeper.class) + .getPeriods().toString()); context.close(); } @@ -81,10 +80,12 @@ public class EnableRetryWithBackoffTests { .getBean(ExponentialRandomService.class); service.service(1); assertEquals(3, service.getCount()); - List periods = context.getBean(TestConfiguration.class).periods; - assertNotEquals("[1000, 1100]", context.getBean(TestConfiguration.class).periods.toString()); - assertTrue("Wrong periods: " + periods, periods.get(0)>1000); - assertTrue("Wrong periods: " + periods, periods.get(1)>1100 && periods.get(1)<1210); + List periods = context.getBean(PeriodSleeper.class).getPeriods(); + assertNotEquals("[1000, 1100]", context.getBean(PeriodSleeper.class) + .getPeriods().toString()); + assertTrue("Wrong periods: " + periods, periods.get(0) > 1000); + assertTrue("Wrong periods: " + periods, periods.get(1) > 1100 + && periods.get(1) < 1210); context.close(); } @@ -92,17 +93,10 @@ public class EnableRetryWithBackoffTests { @EnableRetry @EnableAspectJAutoProxy(proxyTargetClass = true) protected static class TestConfiguration { - - private List periods = new ArrayList(); - + @Bean - public Sleeper sleper() { - return new Sleeper() { - @Override - public void sleep(long period) throws InterruptedException { - periods.add(period); - } - }; + public PeriodSleeper sleper() { + return new PeriodSleeper(); } @Bean @@ -127,6 +121,21 @@ public class EnableRetryWithBackoffTests { } + protected static class PeriodSleeper implements Sleeper { + + private List periods = new ArrayList(); + + @Override + public void sleep(long period) throws InterruptedException { + periods.add(period); + } + + private List getPeriods() { + return periods; + } + + } + protected static class Service { private int count = 0; @@ -182,7 +191,7 @@ public class EnableRetryWithBackoffTests { private int count = 0; - @Retryable(backoff = @Backoff(delay = 1000, maxDelay = 2000, multiplier = 1.1, random=true)) + @Retryable(backoff = @Backoff(delay = 1000, maxDelay = 2000, multiplier = 1.1, random = true)) public void service(int value) { if (count++ < 2) { throw new RuntimeException("Planned");