What are the ways in which Java retries the framework Sisyphus configuration
This article focuses on "what are the ways to configure Sisyphus in the Java retry framework". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Next, let the editor take you to learn "what are the ways to retry the Sisyphus configuration of the Java framework?"
1. Overview of functional configuration
For more convenient configuration, the Retryer class provides a lot of information that can be configured.
1.1 default configuration / * * default configuration Test * / public void defaultConfigTest () {Retryer.newInstance () .condition (RetryConditions.hasExceptionCause ()) .retryWaitContext (RetryWaiter.retryWait (NoRetryWait.class). Context ()) .maxAttempt (3) .recover (Recovers.noRecover ()) .callable (new Callable () {@ Override public String call () throws Exception {System.out.println ("called...") Throw new RuntimeException ();}}. RetryCall ();}
Is equivalent to the following code:
Public void helloTest () {Retryer.newInstance () .callable (new Callable () {@ Override public String call () throws Exception {System.out.println ("called..."); throw new RuntimeException ();}}) .retryCall () } 2. Method description 2.1 condition
Retry the triggered condition, you can specify multiple conditions.
The default is to throw an exception.
2.2 retryWaitContext
Retry the waiting policy, you can specify more than one.
The default is not to wait.
2.3 maxAttempt
Specify the maximum number of retries, including the first execution.
Default value: 3 times.
2.4 listen
Specifies the listening implementation of the retry. The default is no listening.
2.5 recover
When the retry is complete and the retry conditions are still met, you can specify a recovery strategy.
Restore is not done by default.
2.6 callable
The method to be retried.
2.7 retryCall
Triggers a retry execution.
3. Detailed introduction of the interface 3.1 interface and its implementation
For all interfaces, you can view the corresponding subclass instances directly.
3.2 user customization
Based on the flexibility of substitution, users can implement interfaces and define implementations that are more in line with their business.
3.3 sisyphus comments
Configuration is highly flexible, but it is not as simple and flexible as annotations for developers.
Therefore, this framework also implements annotation-based retry.
4. Specification of design
Ensure the unity of interfaces and annotations.
4.1 maven introduces ${project.groupId} sisyphus-annotation ${project.version}
Notes:
There are two main core annotations.
4.2 Retry
Used to specify the relevant configuration for the retry.
/ * retry Note * 1. The actual need can only be put on the method. * 2. If placed on an interface, do all subclasses take effect? For simplicity and clarity, this implementation is not provided. * 3. Maintain the consistency of comments and interfaces. {@ link com.github.houbb.sisyphus.api.core.Retry} interface * @ author binbin.hou * @ since 0.0.3 * / @ Documented @ Inherited @ Target (ElementType.METHOD) @ Retention (RetentionPolicy.RUNTIME) @ RetryAble (DefaultRetryAbleHandler.class) public @ interface Retry {/ * retry class implementation * @ return retry * @ since 0.0.5 * / Class