Skip to content

Commit

Permalink
GH-188: Expose @CircuitBreaker(recover) attribute
Browse files Browse the repository at this point in the history
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)`
  • Loading branch information
artembilan committed Sep 12, 2024
1 parent 993526c commit 97ca28f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -190,4 +190,13 @@
*/
boolean throwLastExceptionOnExhausted() default false;

/**
* Name of method in this class to use for recover. Method had to be marked with
* {@link Recover} annotation.
* @return the name of recover method
* @since 2.0.9
*/
@AliasFor(annotation = Retryable.class)
String recover() default "";

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2006-2023 the original author or authors.
* Copyright 2006-2024 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.
Expand Down Expand Up @@ -34,6 +34,7 @@

/**
* @author Dave Syer
* @author Artem Bilan
*
*/
public class CircuitBreakerInterceptorStatisticsTests {
Expand Down Expand Up @@ -106,7 +107,7 @@ protected static class Service {

private RetryContext status;

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

@Recover
public Object recover() {
public Object recover(String input) {
this.status.setAttribute(RECOVERED, true);
return RECOVERED;
}

@Recover
public Object anotherRecover(Object input) {
return null;
}

public boolean isOpen() {
return this.status != null && this.status.getAttribute("open") == Boolean.TRUE;
}
Expand Down

0 comments on commit 97ca28f

Please sign in to comment.