https://github.com/jensborch/bel
Back-off executor library
https://github.com/jensborch/bel
cdi javaee resilience
Last synced: 5 months ago
JSON representation
Back-off executor library
- Host: GitHub
- URL: https://github.com/jensborch/bel
- Owner: jensborch
- License: mit
- Created: 2017-08-15T14:26:07.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-10-27T12:19:25.000Z (over 8 years ago)
- Last Synced: 2025-09-18T17:37:31.488Z (6 months ago)
- Topics: cdi, javaee, resilience
- Language: Java
- Size: 24.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# BEL - Minimalistic Java EE executor library with back-off
This library provides a CDI injectable resilient executor with a configurable back-off. The executor simplifies calling potentially fragile services without overloading them, as it will retry code execution based on a back-off strategy.
This library implements an [Executor](http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/Executor.html) as a simple wrapper around the Java EE [ManagedScheduledExecutorService](http://docs.oracle.com/javaee/7/api/javax/enterprise/concurrent/ManagedScheduledExecutorService.html). The Executor is a dependent CDI bean and will thus be instantiated in the same scope as the bean it is injected into.
The resilient executor will automatically start a new transaction when executing code using ManagedScheduledExecutorService, further simplifying creating resilient asynchronous code.
# Status
Module is considered beta quality.
[](https://travis-ci.org/Nykredit/bel) [](https://coveralls.io/github/Nykredit/bel?branch=master)
# Usage
Add the following Maven dependency to your project:
```xml
dk.nykredit.resilience
bel
0.9.2
```
The resilient executor implements the Executor interface and using the executor is thus similar to using Java EE ManagedScheduledExecutorService:
```java
@Inject
@Resilient(strategy = PolynomialBackoffStrategy.class)
@PolynomialBackoffStrategyConfig(delay = 1, maxDelay = 1800, retries = 100, timeUnit = TimeUnit.SECONDS)
private ResilientExecutor executor;
executor.execute(() -> {
Customer customer = repository.get(id);
StatusRepresentation status = statusConnector.get(customer.getId());
customer.setStatus(status.getStatus());
}, e -> {
LOGGER.error("Error calling service...", e);
Customer customer = repository.get(id);
customer.setStatus(Status.UNKNOWN);
});
}
```