Skip to content

Commit 97ca28f

Browse files
committed
GH-188: Expose @CircuitBreaker(recover) attribute
Fixes: #188 Issue link: #188 All the logic to determine a recover method is there. We are just missing the `CircuitBreaker(recover)` attribute with an `@AliasFor(annotation = Retryable.class)`
1 parent 993526c commit 97ca28f

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

src/main/java/org/springframework/retry/annotation/CircuitBreaker.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,4 +190,13 @@
190190
*/
191191
boolean throwLastExceptionOnExhausted() default false;
192192

193+
/**
194+
* Name of method in this class to use for recover. Method had to be marked with
195+
* {@link Recover} annotation.
196+
* @return the name of recover method
197+
* @since 2.0.9
198+
*/
199+
@AliasFor(annotation = Retryable.class)
200+
String recover() default "";
201+
193202
}

src/test/java/org/springframework/retry/stats/CircuitBreakerInterceptorStatisticsTests.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2023 the original author or authors.
2+
* Copyright 2006-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -34,6 +34,7 @@
3434

3535
/**
3636
* @author Dave Syer
37+
* @author Artem Bilan
3738
*
3839
*/
3940
public class CircuitBreakerInterceptorStatisticsTests {
@@ -106,7 +107,7 @@ protected static class Service {
106107

107108
private RetryContext status;
108109

109-
@CircuitBreaker(label = "test", maxAttempts = 1)
110+
@CircuitBreaker(label = "test", maxAttempts = 1, recover = "recover")
110111
public Object service(String input) throws Exception {
111112
this.status = RetrySynchronizationManager.getContext();
112113
Integer attempts = (Integer) status.getAttribute("attempts");
@@ -122,11 +123,16 @@ public Object service(String input) throws Exception {
122123
}
123124

124125
@Recover
125-
public Object recover() {
126+
public Object recover(String input) {
126127
this.status.setAttribute(RECOVERED, true);
127128
return RECOVERED;
128129
}
129130

131+
@Recover
132+
public Object anotherRecover(Object input) {
133+
return null;
134+
}
135+
130136
public boolean isOpen() {
131137
return this.status != null && this.status.getAttribute("open") == Boolean.TRUE;
132138
}

0 commit comments

Comments
 (0)