diff --git a/README.md b/README.md index 7354b1a..bcc5253 100644 --- a/README.md +++ b/README.md @@ -218,13 +218,10 @@ Note that when there is more than one listener, they are in a list, so there is ### Listeners for reflective method invocations -When dealing with methods annotated with `@Retryable` or with Spring AOP intercepted methods, -spring-retry provides the possibility to inspect in detail the method invocation within the -`RetryListener` implementation. Such a scenario could be particularly useful when there is a need -to monitor how often a certain method call has been retried and expose it with detailed tagging -information (e.g. : class name, method name, or even parameter values in some exotic cases). +When dealing with methods annotated with `@Retryable` or with Spring AOP intercepted methods, spring-retry provides the possibility to inspect in detail the method invocation within the `RetryListener` implementation. + +Such a scenario could be particularly useful when there is a need to monitor how often a certain method call has been retried and expose it with detailed tagging information (e.g. : class name, method name, or even parameter values in some exotic cases). -All that needs to be done is checking whe ```java diff --git a/src/main/java/org/springframework/retry/interceptor/MethodInvocationRetryCallback.java b/src/main/java/org/springframework/retry/interceptor/MethodInvocationRetryCallback.java index 42b0ae4..888357c 100644 --- a/src/main/java/org/springframework/retry/interceptor/MethodInvocationRetryCallback.java +++ b/src/main/java/org/springframework/retry/interceptor/MethodInvocationRetryCallback.java @@ -1,3 +1,19 @@ +/* + * Copyright 2006-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.springframework.retry.interceptor; import org.aopalliance.intercept.MethodInvocation; @@ -6,18 +22,19 @@ import org.springframework.retry.RetryOperations; import org.springframework.util.StringUtils; /** - * Callback class for a Spring AOP reflective `MethodInvocation` that can be retried using a {@link - * RetryOperations}. + * Callback class for a Spring AOP reflective `MethodInvocation` that can be retried using + * a {@link RetryOperations}. * * In a concrete {@link org.springframework.retry.RetryListener} implementation, the - * `MethodInvocation` can be analysed for providing insights on the method called as well as its - * parameter values which could then be used for monitoring purposes. + * `MethodInvocation` can be analysed for providing insights on the method called as well + * as its parameter values which could then be used for monitoring purposes. * * @param the type of object returned by the callback * @param the type of exception it declares may be thrown * @see StatefulRetryOperationsInterceptor * @see RetryOperationsInterceptor * @see org.springframework.retry.listener.MethodInvocationRetryListenerSupport + * @author Marius Grama * @since 1.3 */ public abstract class MethodInvocationRetryCallback @@ -29,7 +46,6 @@ public abstract class MethodInvocationRetryCallback /** * Constructor for the class. - * * @param invocation the method invocation * @param label a unique label for statistics reporting. */ @@ -37,7 +53,8 @@ public abstract class MethodInvocationRetryCallback this.invocation = invocation; if (StringUtils.hasText(label)) { this.label = label; - } else { + } + else { this.label = invocation.getMethod().toGenericString(); } } diff --git a/src/main/java/org/springframework/retry/listener/MethodInvocationRetryListenerSupport.java b/src/main/java/org/springframework/retry/listener/MethodInvocationRetryListenerSupport.java index cbcd365..3cdba9d 100644 --- a/src/main/java/org/springframework/retry/listener/MethodInvocationRetryListenerSupport.java +++ b/src/main/java/org/springframework/retry/listener/MethodInvocationRetryListenerSupport.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 the original author or authors. + * Copyright 2006-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,6 +30,7 @@ import org.springframework.retry.interceptor.MethodInvocationRetryCallback; * NOTE that this listener performs an action only when dealing with callbacks that are * instances of {@link MethodInvocationRetryCallback}. * + * @author Marius Grama * @since 1.3 */ public class MethodInvocationRetryListenerSupport implements RetryListener { diff --git a/src/main/java/org/springframework/retry/support/RetryTemplateBuilder.java b/src/main/java/org/springframework/retry/support/RetryTemplateBuilder.java index b902c84..3e417dd 100644 --- a/src/main/java/org/springframework/retry/support/RetryTemplateBuilder.java +++ b/src/main/java/org/springframework/retry/support/RetryTemplateBuilder.java @@ -40,8 +40,7 @@ import org.springframework.util.Assert; * builder method - see it's doc. * *

- * Examples: - *

{@code
+ * Examples: 
{@code
  * RetryTemplate.builder()
  *      .maxAttempts(10)
  *      .exponentialBackoff(100, 2, 10000)
@@ -83,7 +82,6 @@ import org.springframework.util.Assert;
  *
  * @author Aleksandr Shamukov
  * @author Artem Bilan
- *
  * @since 1.3
  */
 public class RetryTemplateBuilder {
diff --git a/src/test/java/org/springframework/retry/annotation/CircuitBreakerTests.java b/src/test/java/org/springframework/retry/annotation/CircuitBreakerTests.java
index f7e2fc3..c10ad37 100644
--- a/src/test/java/org/springframework/retry/annotation/CircuitBreakerTests.java
+++ b/src/test/java/org/springframework/retry/annotation/CircuitBreakerTests.java
@@ -1,5 +1,5 @@
 /*
- * Copyright 2015-2018 the original author or authors.
+ * Copyright 2015-2019 the original author or authors.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -130,7 +130,10 @@ public class CircuitBreakerTests {
 			}
 		}
 
-		@CircuitBreaker(maxAttemptsExpression = "#{2 * ${foo:4}}", openTimeoutExpression = "#{${bar:19}000}", resetTimeoutExpression = "#{${baz:20}000}", exceptionExpression = "#{#root instanceof RuntimeExpression}")
+		@CircuitBreaker(maxAttemptsExpression = "#{2 * ${foo:4}}",
+				openTimeoutExpression = "#{${bar:19}000}",
+				resetTimeoutExpression = "#{${baz:20}000}",
+				exceptionExpression = "#{#root instanceof RuntimeExpression}")
 		public void expressionService() {
 			this.count++;
 		}
diff --git a/src/test/java/org/springframework/retry/annotation/EnableRetryTests.java b/src/test/java/org/springframework/retry/annotation/EnableRetryTests.java
index 9f78e0d..5f1af79 100644
--- a/src/test/java/org/springframework/retry/annotation/EnableRetryTests.java
+++ b/src/test/java/org/springframework/retry/annotation/EnableRetryTests.java
@@ -458,7 +458,8 @@ public class EnableRetryTests {
 
 		private int count = 0;
 
-		@Retryable(include = RuntimeException.class, exclude = IllegalStateException.class)
+		@Retryable(include = RuntimeException.class,
+				exclude = IllegalStateException.class)
 		public void service() {
 			if (count++ < 2) {
 				throw new IllegalStateException("Planned");
@@ -545,7 +546,11 @@ public class EnableRetryTests {
 			throw new RuntimeException("this cannot be retried");
 		}
 
-		@Retryable(exceptionExpression = "#{@exceptionChecker.${retryMethod}(#root)}", maxAttemptsExpression = "#{@integerFiveBean}", backoff = @Backoff(delayExpression = "#{${one}}", maxDelayExpression = "#{${five}}", multiplierExpression = "#{${onePointOne}}"))
+		@Retryable(exceptionExpression = "#{@exceptionChecker.${retryMethod}(#root)}",
+				maxAttemptsExpression = "#{@integerFiveBean}",
+				backoff = @Backoff(delayExpression = "#{${one}}",
+						maxDelayExpression = "#{${five}}",
+						multiplierExpression = "#{${onePointOne}}"))
 		public void service3() {
 			if (count++ < 8) {
 				throw new RuntimeException();
@@ -559,7 +564,8 @@ public class EnableRetryTests {
 			}
 		}
 
-		@Retryable(exceptionExpression = "message.contains('this can be retried')", include = RuntimeException.class)
+		@Retryable(exceptionExpression = "message.contains('this can be retried')",
+				include = RuntimeException.class)
 		public void service5() {
 			if (count++ < 11) {
 				throw new RuntimeException("this can be retried");
diff --git a/src/test/java/org/springframework/retry/annotation/EnableRetryWithBackoffTests.java b/src/test/java/org/springframework/retry/annotation/EnableRetryWithBackoffTests.java
index ea2f666..2b6d2d4 100644
--- a/src/test/java/org/springframework/retry/annotation/EnableRetryWithBackoffTests.java
+++ b/src/test/java/org/springframework/retry/annotation/EnableRetryWithBackoffTests.java
@@ -1,5 +1,5 @@
 /*
- * Copyright 2012-2013 the original author or authors.
+ * Copyright 2012-2019 the original author or authors.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -192,7 +192,8 @@ 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");
diff --git a/src/test/java/org/springframework/retry/listener/MethodInvocationRetryListenerSupportTests.java b/src/test/java/org/springframework/retry/listener/MethodInvocationRetryListenerSupportTests.java
index d13c6ae..09b0cae 100644
--- a/src/test/java/org/springframework/retry/listener/MethodInvocationRetryListenerSupportTests.java
+++ b/src/test/java/org/springframework/retry/listener/MethodInvocationRetryListenerSupportTests.java
@@ -1,5 +1,5 @@
 /*
- * Copyright 2006-2007 the original author or authors.
+ * Copyright 2006-2019 the original author or authors.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -16,17 +16,17 @@
 
 package org.springframework.retry.listener;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-import static org.mockito.Mockito.mock;
-
 import java.util.concurrent.atomic.AtomicInteger;
 import org.junit.Test;
 import org.springframework.retry.RetryCallback;
 import org.springframework.retry.RetryContext;
 import org.springframework.retry.interceptor.MethodInvocationRetryCallback;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.mockito.Mockito.mock;
+
 public class MethodInvocationRetryListenerSupportTests {
 
 	@Test