Code cosmetics
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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 <T> the type of object returned by the callback
|
||||
* @param <E> 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<T, E extends Throwable>
|
||||
@@ -29,7 +46,6 @@ public abstract class MethodInvocationRetryCallback<T, E extends Throwable>
|
||||
|
||||
/**
|
||||
* 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<T, E extends Throwable>
|
||||
this.invocation = invocation;
|
||||
if (StringUtils.hasText(label)) {
|
||||
this.label = label;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
this.label = invocation.getMethod().toGenericString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -40,8 +40,7 @@ import org.springframework.util.Assert;
|
||||
* builder method - see it's doc.
|
||||
*
|
||||
* <p>
|
||||
* Examples:
|
||||
* <pre>{@code
|
||||
* Examples: <pre>{@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 {
|
||||
|
||||
@@ -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++;
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user