Repository navigation
Releases: cmccarthyIrl/RetryAspect
Release list
RetryAspect v1.0.5
RetryAspect 1.0.5
🎯 Overview
Maintenance release with critical bug fixes, enhanced validation, comprehensive test coverage, and dependency updates.
🐛 Bug Fixes
InterruptedException Handling
- Fixed improper handling of thread interruption during retry delays
- Added proper interrupt status restoration and descriptive error messages
- Prevents silent failures when threads are interrupted
Validation Improvements
- Fixed crash when
maxAttemptsset to 0 or negative values - Added validation for empty
includearray in@Retryable - Added validation for negative delay values
- All validation failures now throw clear
IllegalArgumentExceptionmessages
Retry Logic Enhancements
- Fixed potential integer overflow in exponential backoff calculation
- Removed redundant null check for improved code maintainability
- Clarified
maxAttemptssemantics in documentation (total attempts = initial + retries)
📦 Dependencies
Security Updates
- JUnit: 4.13.1 → 4.13.2 (fixes CVE-2020-15250)
New Dependencies
- Mockito Core 3.12.4 for enhanced testing capabilities
Build Tools
- maven-javadoc-plugin: 2.9.1 → 3.7.0
- central-publishing-maven-plugin: 0.5.0 → 0.4.0
📚 Documentation
README Updates
- Updated version references throughout
- Fixed repository URLs
- Corrected license reference
- Added validation requirements
- Added idempotency warnings
Code Documentation
- Enhanced Javadoc comments
- Improved inline documentation
- Added validation requirement notes
🔧 Build & Deployment
- Configured GPG signing for Maven Central requirements
- Automated deployment pipeline with token authentication
- Published to Maven Central repository
⬆️ Upgrade
Update your pom.xml:
<dependency>
<groupId>io.github.cmccarthyirl</groupId>
<artifactId>retryaspect</artifactId>
<version>1.0.5</version>
</dependency>No breaking changes - fully backward compatible with 1.0.4
🔗 Links
RetryAspect v1.0.4
Updated the README.md
- added how to for maven dependencies and plugin requirements
RetryAspect v1.0.0
RetryAspect Class
This RetryAspect class is an implementation of the retry mechanism in Java using Aspect-Oriented Programming (AOP). It allows methods annotated with @Retryable to be executed multiple times in case of failure, with configurable retry attempts and backoff delay.
Features
- Retry Mechanism: Automatically retries a method execution if it fails, based on the configuration provided by the
@Retryableannotation. - Configurable Attempts and Delay: Allows configuration of the maximum number of retry attempts and the delay between retries.
- Exception Handling: Only retries for specified exceptions, providing fine-grained control over which failures should trigger a retry.
Usage
To use the RetryAspect class, follow these steps:
1. Annotate Methods with @Retryable
Annotate the methods you want to be retryable with the @Retryable annotation.
import com.cmccarthy.annotations.Retryable;
public class MyService {
@Retryable(maxAttempts = 3, backoff = @Backoff(delay = 1000), include = {RuntimeException.class})
public void performTask() {
// Method implementation
}
}2. Configure the @Retryable Annotation
The @Retryable annotation allows you to configure the retry behavior for a method. It has the following attributes:
- maxAttempts: The maximum number of retry attempts (default is 3).
- backoff: Specifies the backoff policy, including the delay between retries.
- include: The exceptions that should trigger a retry.
@Retryable(maxAttempts = 5, backoff = @Backoff(delay = 2000), include = {IOException.class})
public void unreliableMethod() {
// Method implementation
}In this example, the unreliableMethod will be retried up to 5 times with a delay of 2000 milliseconds between retries, but only if an IOException is thrown.
Class Details RetryAspect Class
The RetryAspect class contains the AOP logic for handling retries.
@Aspect
public class RetryAspect {
@Pointcut("@annotation(retryable) && execution(* *(..))")
public void retryableMethods(Retryable retryable) {
}
@Around(value = "retryableMethods(retryable)", argNames = "joinPoint,retryable")
public Object retryMethod(ProceedingJoinPoint joinPoint, Retryable retryable) throws Throwable {
int maxAttempts = retryable.maxAttempts();
long delay = retryable.backoff().delay();
int attempts = 0;
Throwable lastException = null;
while (attempts < maxAttempts) {
try {
return joinPoint.proceed();
} catch (Throwable ex) {
lastException = ex;
if (!isExceptionIncluded(ex, retryable.include())) {
throw ex;
}
attempts++;
if (attempts < maxAttempts) {
Thread.sleep(delay);
}
}
}
throw lastException != null ? lastException : new RuntimeException("Retry failed after max attempts");
}
private boolean isExceptionIncluded(Throwable ex, Class<? extends Throwable>[] includedClasses) {
for (Class<? extends Throwable> includedClass : includedClasses) {
if (includedClass.isInstance(ex)) {
return true;
}
}
return false;
}
}Methods
- retryableMethods: Pointcut definition for methods annotated with
@Retryable. - retryMethod: Around advice that handles the retry logic.
- isExceptionIncluded: Helper method to check if an exception is included in the list of retryable exceptions.
Dependencies
Ensure that you have the necessary dependencies for AspectJ in your project
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.9.7</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.9.7</version>
</dependency>
</dependencies>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.15.0</version>
</plugin>
</plugins>
Contribute
Contributions are welcome! Here's how you can get started!!
License
This project is licensed under the MIT License - see the LICENSE file for details.
Full Changelog: https://github.com/cmccarthyIrl/RetryAspect/commits/retry-aspect-1.0.0
Full Changelog: https://github.com/cmccarthyIrl/RetryAspect/commits/RetryAspect-v1.0.0
RetryAspect v1.0.1
RetryAspect
This RetryAspect class is an implementation of the retry mechanism in Java using Aspect-Oriented Programming (AOP). It allows methods annotated with @Retryable to be executed multiple times in case of failure, with configurable retry attempts and backoff delay.
Features
- Retry Mechanism: Automatically retries a method execution if it fails, based on the configuration provided by the
@Retryableannotation. - Configurable Attempts and Delay: Allows configuration of the maximum number of retry attempts and the delay between retries.
- Exception Handling: Only retries for specified exceptions, providing fine-grained control over which failures should trigger a retry.
Usage
To use the RetryAspect class, follow these steps:
1. Annotate Methods with @Retryable
Annotate the methods you want to be retryable with the @Retryable annotation.
public class MyService {
@Retryable(maxAttempts = 3, backoff = @Backoff(delay = 1000), include = {RuntimeException.class})
public void performTask() {
// Method implementation
}
}2. Configure the @Retryable Annotation
The @Retryable annotation allows you to configure the retry behavior for a method. It has the following attributes:
- maxAttempts: The maximum number of retry attempts (default is 3).
- backoff: Specifies the backoff policy, including the delay between retries.
- include: The exceptions that should trigger a retry.
@Retryable(maxAttempts = 5, backoff = @Backoff(delay = 2000), include = {IOException.class})
public void unreliableMethod() {
// Method implementation
}In this example, the unreliableMethod will be retried up to 5 times with a delay of 2000 milliseconds between retries, but only if an IOException is thrown.
Dependencies
Add the following dependency to you POM file
<dependency>
<groupId>io.github.cmccarthyirl</groupId>
<artifactId>retryaspect</artifactId>
<version>1.0.1</version>
</dependency>Contribute
Contributions are welcome! Here's how you can get started!!
License
This project is licensed under the MIT License - see the LICENSE file for details.