Browse Source

Rename Retryable.run() to Retryable.execute()

See gh-34716
pull/35030/head
Sam Brannen 6 months ago
parent
commit
8f3ca49bc4
  1. 6
      spring-core/src/main/java/org/springframework/core/retry/RetryTemplate.java
  2. 2
      spring-core/src/main/java/org/springframework/core/retry/Retryable.java
  3. 6
      spring-core/src/test/java/org/springframework/core/retry/RetryTemplateTests.java

6
spring-core/src/main/java/org/springframework/core/retry/RetryTemplate.java

@ -32,7 +32,7 @@ import org.springframework.util.backoff.BackOffExecution;
import org.springframework.util.backoff.FixedBackOff; import org.springframework.util.backoff.FixedBackOff;
/** /**
* A basic implementation of {@link RetryOperations} that invokes and potentially * A basic implementation of {@link RetryOperations} that executes and potentially
* retries a {@link Retryable} operation based on a configured {@link RetryPolicy} * retries a {@link Retryable} operation based on a configured {@link RetryPolicy}
* and {@link BackOff} policy. * and {@link BackOff} policy.
* *
@ -147,7 +147,7 @@ public class RetryTemplate implements RetryOperations {
// Initial attempt // Initial attempt
try { try {
logger.debug(() -> "Preparing to execute retryable operation '%s'".formatted(retryableName)); logger.debug(() -> "Preparing to execute retryable operation '%s'".formatted(retryableName));
R result = retryable.run(); R result = retryable.execute();
logger.debug(() -> "Retryable operation '%s' completed successfully".formatted(retryableName)); logger.debug(() -> "Retryable operation '%s' completed successfully".formatted(retryableName));
return result; return result;
} }
@ -165,7 +165,7 @@ public class RetryTemplate implements RetryOperations {
logger.debug(() -> "Preparing to retry operation '%s'".formatted(retryableName)); logger.debug(() -> "Preparing to retry operation '%s'".formatted(retryableName));
try { try {
this.retryListener.beforeRetry(retryExecution); this.retryListener.beforeRetry(retryExecution);
R result = retryable.run(); R result = retryable.execute();
this.retryListener.onRetrySuccess(retryExecution, result); this.retryListener.onRetrySuccess(retryExecution, result);
logger.debug(() -> "Retryable operation '%s' completed successfully after retry" logger.debug(() -> "Retryable operation '%s' completed successfully after retry"
.formatted(retryableName)); .formatted(retryableName));

2
spring-core/src/main/java/org/springframework/core/retry/Retryable.java

@ -36,7 +36,7 @@ public interface Retryable<R> {
* @return the result of the operation * @return the result of the operation
* @throws Throwable if an error occurs during the execution of the operation * @throws Throwable if an error occurs during the execution of the operation
*/ */
R run() throws Throwable; R execute() throws Throwable;
/** /**
* A unique, logical name for this retryable operation, used to distinguish * A unique, logical name for this retryable operation, used to distinguish

6
spring-core/src/test/java/org/springframework/core/retry/RetryTemplateTests.java

@ -44,7 +44,7 @@ class RetryTemplateTests {
int failure; int failure;
@Override @Override
public String run() throws Exception { public String execute() throws Exception {
if (failure++ < 2) { if (failure++ < 2) {
throw new Exception("Error while invoking greeting service"); throw new Exception("Error while invoking greeting service");
} }
@ -68,7 +68,7 @@ class RetryTemplateTests {
Retryable<String> retryable = new Retryable<>() { Retryable<String> retryable = new Retryable<>() {
@Override @Override
public String run() throws Exception { public String execute() throws Exception {
throw exception; throw exception;
} }
@ -100,7 +100,7 @@ class RetryTemplateTests {
Retryable<String> retryable = new Retryable<>() { Retryable<String> retryable = new Retryable<>() {
@Override @Override
public String run() throws TechnicalException { public String execute() throws TechnicalException {
throw technicalException; throw technicalException;
} }

Loading…
Cancel
Save