What is Sisyphus
sisyphus combines the advantages of spring-retry and gauva-retrying, and is also very flexible to use.
Why choose this name
I think the retry is very similar to Sisyphus.
Repeating it over and over again may be in vain, but I never get tired of it.
One must imagine the happiness of Sisyphus. -Camus
other reasons
I have seen the relevant framework of java retry
Although I think there are many shortcomings. But there is no urge to reinvent the wheel, which is futile.
Of course, I also looked at the interface design of Netty and the interface design of Hibernate-Validator during this period, and found it very clever.
I thought that by combining these things, I could write a pretty good framework, so I wrote it.
At least, sisyphus is happy.
About the version
This time the framework version adopted a more conservative approach, using 0.0.X
.
There are two reasons:
(1) I think the early stage is out of the experimental stage. The code is not mature, and the self-test is not sufficient. So it is not suitable for production.
(2) In this way, it can be iterated quickly, and the version features will not be able to be iterated for a long time in pursuit of better.
Version features
I used 5 versions and realized the main features:
(1) Declarative call based on fluent interface
(2) Annotation-based proxy realization
(3) Spring integration realization
(4) Implementation of custom annotations
Unfinished work
- More convenient tools.
- Use documentation
- Test code
Feel
Ideas are easy to generate, but it takes a long time to make it into a stable framework.
Why choose sisyphus
As developers, we generally choose more well-known frameworks.
Such as guava-retrying spring-retry.
Or simply write one yourself.
Why not guava-retrying/spring-retry
java retry this article, I have listed common implementations
As well as the above two frameworks, the shortcomings are also described.
guava-retrying advantages and disadvantages
advantage
- Flexible to use
- fluent elegant writing
- Provide enough implementation
shortcoming
- There is no default annotation-based implementation
- The retry strategy design is not friendly
spring-retry
advantage
- Simple to use
shortcoming
- Single retry condition
- Single retry waiting strategy
- Cannot customize annotations
Why not write one yourself
Personal feelings
As a developer, I usually tell the truth and see the retry.
I will definitely be lazy to write a for loop, and it will be over after a few retries.
Because time does not allow.
If you are more diligent, you can choose spring-retry/guava-retrying. If you are familiar with their advantages and disadvantages.
If you desire to create
All sisyphus implementations are based on interfaces.
You can fully implement your own implementation, and basically everything can be replaced.
Of course, some common strategies are implemented, and the basic framework of the project has detailed annotations, which can also be helpful as a reference.
sisyphus do more things
netty inspiration
Refer to the design of netty to ensure the consistency of interface implementation.
And sisyphus has done more to ensure consistency between interfaces and annotations.
Use the guide class to ensure the convenience of use and the flexibility of later expansion.
hibernate-validator
The author of hibernate-validator is one of the few developers I know who is great for java annotation applications. (Although little is known)
Custom annotations are learned from this framework.
With spring
Spring is basically inseparable from our code, so you can easily combine spring.
Just like you use spring-retry.
Quick start
need
jdk1.7+
maven 3.x+
Introduced by maven
sisyphus uses maven to manage jars,
<plugin>
<groupId>com.github.houbb</groupId>
<artifactId>sisyphus-core</artifactId>
<version>0.0.6</version>
</plugin>
coding
As an introductory case, we first introduce some simple and flexible declarative programming
public void helloTest() {
Retryer.<String>newInstance()
.callable(new Callable<String>() {
@Override
public String call() throws Exception {
System.out.println("called...");
throw new RuntimeException();
}
}).retryCall();
}
Code introduction
Retryer.<String>newInstance()
Create an instance of the boot class, String is callable, which is the return value type of the method to be retried.
callable()
specifies the method implementation to be retried.
retryCall()
triggers a retry call.
Log information
called...
called...
called...
And some abnormal information.
Equivalent configuration
The above configuration actually has many default values, as follows:
/**
* 默认配置测试
*/
@Test(expected = RuntimeException.class)
public void defaultConfigTest() {
Retryer.<String>newInstance()
.maxAttempt(3)
.listen(RetryListens.noListen())
.recover(Recovers.noRecover())
.condition(RetryConditions.hasExceptionCause())
.retryWaitContext(RetryWaiter.<String>retryWait(NoRetryWait.class).context())
.callable(new Callable<String>() {
@Override
public String call() throws Exception {
System.out.println("called...");
throw new RuntimeException();
}
}).retryCall();
}
These default values are all configurable.
For example, when will the retry be triggered? How many retry? How often will a retry be triggered? These will be explained in detail in the following chapters.
summary
This article briefly introduces the reason for the design of the retry framework and how to use it.
java retry framework sisyphus open source address
I hope this article is helpful to you. If you like it, please like, collect and forward a wave.
I am an old horse, and I look forward to seeing you again next time.
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。