Repository: alibaba/easy-retry
Branch: main
Commit: 86b831c436bc
Files: 140
Total size: 152.9 KB
Directory structure:
gitextract_y0h1aiip/
├── .editorconfig
├── .github/
│ └── workflows/
│ └── maven.yml
├── .gitignore
├── LICENSE
├── README.md
├── config/
│ └── intellij-java-google-style.xml
├── easy-retry-common/
│ ├── pom.xml
│ └── src/
│ └── main/
│ └── java/
│ └── com/
│ └── alibaba/
│ └── easyretry/
│ └── common/
│ ├── AbstractResultPredicate.java
│ ├── AbstractRetrySyncExecutor.java
│ ├── EasyRetryPredicate.java
│ ├── Invocation.java
│ ├── RetryConfiguration.java
│ ├── RetryContainer.java
│ ├── RetryContext.java
│ ├── RetryExecutor.java
│ ├── RetryIdentify.java
│ ├── RetryLifecycle.java
│ ├── RetrySyncExecutor.java
│ ├── SCallable.java
│ ├── SimpleMethodInvocation.java
│ ├── access/
│ │ ├── RetrySerializerAccess.java
│ │ ├── RetryStrategyAccess.java
│ │ └── RetryTaskAccess.java
│ ├── constant/
│ │ ├── enums/
│ │ │ ├── HandleResultEnum.java
│ │ │ ├── RetryTaskStatusEnum.java
│ │ │ └── RetryTypeEnum.java
│ │ └── package-info.java
│ ├── entity/
│ │ └── RetryTask.java
│ ├── event/
│ │ ├── RetryEvent.java
│ │ ├── RetryEventMulticaster.java
│ │ ├── RetryListener.java
│ │ ├── before/
│ │ │ ├── AfterSaveBeforeRetryEvent.java
│ │ │ ├── BeforeRetryEvent.java
│ │ │ └── PrepSaveBeforeRetryEvent.java
│ │ └── on/
│ │ ├── FailureOnRetryEvent.java
│ │ ├── OnRetryEvent.java
│ │ ├── StopOnRetryEvent.java
│ │ └── SuccessOnRetryEvent.java
│ ├── filter/
│ │ ├── AbstractRetryFilter.java
│ │ ├── RetryFilter.java
│ │ ├── RetryFilterDiscover.java
│ │ ├── RetryFilterInvocation.java
│ │ ├── RetryFilterInvocationHandler.java
│ │ ├── RetryFilterRegister.java
│ │ ├── RetryFilterRegisterHandler.java
│ │ └── RetryFilterResponse.java
│ ├── processor/
│ │ ├── AsyncPersistenceProcessor.java
│ │ ├── RetryProcessor.java
│ │ └── SyncProcessor.java
│ ├── resolve/
│ │ └── ExecutorSolver.java
│ ├── retryer/
│ │ ├── Retryer.java
│ │ └── RetryerInfo.java
│ ├── serializer/
│ │ ├── ArgDeSerializerInfo.java
│ │ ├── ArgSerializerInfo.java
│ │ ├── EasyRetrySerializer.java
│ │ ├── ResultPredicateSerializer.java
│ │ └── RetryArgSerializer.java
│ └── strategy/
│ ├── RetryStrategy.java
│ ├── StopStrategy.java
│ └── WaitStrategy.java
├── easy-retry-core/
│ ├── pom.xml
│ └── src/
│ ├── main/
│ │ └── java/
│ │ └── com/
│ │ └── alibaba/
│ │ └── easyretry/
│ │ └── core/
│ │ ├── DegradeAbleRetryExecutor.java
│ │ ├── PersistenceRetryExecutor.java
│ │ ├── PersistenceRetryer.java
│ │ ├── PersistenceRetryerBuilder.java
│ │ ├── RetryerBuilder.java
│ │ ├── SyncRetryer.java
│ │ ├── SyncRetryerBuilder.java
│ │ ├── access/
│ │ │ ├── DefaultRetrySerializerAccess.java
│ │ │ └── MemoryRetryTaskAccess.java
│ │ ├── container/
│ │ │ └── SimpleRetryContainer.java
│ │ ├── context/
│ │ │ └── MaxAttemptsPersistenceRetryContext.java
│ │ ├── degrade/
│ │ │ └── EasyRetryDegradeHelper.java
│ │ ├── event/
│ │ │ └── SimpleRetryEventMulticaster.java
│ │ ├── filter/
│ │ │ ├── DefaultRetryFilterInvocationHandler.java
│ │ │ ├── DefaultRetryFilterRegisterHandler.java
│ │ │ ├── IdentifyRetryFilter.java
│ │ │ ├── MethodExcuteRetryFilter.java
│ │ │ ├── NOOPRetryFilter.java
│ │ │ ├── SPIRetryFilterDiscover.java
│ │ │ └── SimpleRetryFilterRegister.java
│ │ ├── process/
│ │ │ ├── async/
│ │ │ │ ├── AbstractAsyncPersistenceProcessor.java
│ │ │ │ ├── before/
│ │ │ │ │ ├── AbstractAsyncPersistenceBeforeRetryProcessor.java
│ │ │ │ │ ├── ExceptionPersistenceAsyncBeforeRetryProcessor.java
│ │ │ │ │ └── ResultAsynPersistenceBeforeRetryProcessor.java
│ │ │ │ └── on/
│ │ │ │ ├── AbstractAsyncPersistenceOnRetryProcessor.java
│ │ │ │ ├── ExceptionPersistenceAsynOnRetryProcessor.java
│ │ │ │ └── ResultAsynPersistenceOnRetryProcessor.java
│ │ │ └── package-info.java
│ │ ├── serializer/
│ │ │ ├── FastJsonRetryArgSerializer.java
│ │ │ ├── HessianResultPredicateSerializer.java
│ │ │ └── HessianRetryArgSerializer.java
│ │ ├── strategy/
│ │ │ └── DefaultRetryStrategy.java
│ │ └── utils/
│ │ ├── HessianSerializerUtils.java
│ │ ├── LogUtils.java
│ │ └── PrintUtils.java
│ └── test/
│ └── java/
│ └── com/
│ └── alibaba/
│ └── easyretry/
│ └── core/
│ └── utils/
│ └── TestClass.java
├── easy-retry-extensions/
│ ├── easy-retry-guava-extension/
│ │ ├── pom.xml
│ │ └── src/
│ │ └── main/
│ │ └── java/
│ │ └── com/
│ │ └── alibaba/
│ │ └── easyretry/
│ │ └── extension/
│ │ └── guava/
│ │ ├── GuavaRetrySyncExecutor.java
│ │ └── package-info.java
│ ├── easy-retry-mybatis-extension/
│ │ ├── pom.xml
│ │ └── src/
│ │ ├── main/
│ │ │ ├── java/
│ │ │ │ └── com/
│ │ │ │ └── alibaba/
│ │ │ │ └── easyretry/
│ │ │ │ └── extension/
│ │ │ │ └── mybatis/
│ │ │ │ ├── access/
│ │ │ │ │ └── MybatisRetryTaskAccess.java
│ │ │ │ ├── common/
│ │ │ │ │ └── utils/
│ │ │ │ │ └── HostUtils.java
│ │ │ │ ├── dao/
│ │ │ │ │ ├── BaseDAOSupport.java
│ │ │ │ │ ├── RetryTaskDAO.java
│ │ │ │ │ └── RetryTaskDAOImpl.java
│ │ │ │ ├── po/
│ │ │ │ │ └── RetryTaskPO.java
│ │ │ │ └── query/
│ │ │ │ └── RetryTaskQuery.java
│ │ │ └── resources/
│ │ │ └── dal/
│ │ │ └── easyretry/
│ │ │ ├── easy-mybatis-config.xml
│ │ │ └── mapper/
│ │ │ └── easy-retry-task-mapper.xml
│ │ └── test/
│ │ ├── java/
│ │ │ └── com/
│ │ │ └── alibaba/
│ │ │ └── easyretry/
│ │ │ └── extension/
│ │ │ └── mybatis/
│ │ │ ├── DbConfig.java
│ │ │ ├── MyBatisConfig.java
│ │ │ ├── access/
│ │ │ │ └── MybatisRetryTaskAccessTest.java
│ │ │ ├── common/
│ │ │ │ └── utils/
│ │ │ │ └── HostUtilsTest.java
│ │ │ └── dao/
│ │ │ └── RetryTaskDAOImplTest.java
│ │ └── resources/
│ │ ├── logback.xml
│ │ └── task.sql
│ ├── easy-retry-spring-extension/
│ │ ├── pom.xml
│ │ └── src/
│ │ └── main/
│ │ └── java/
│ │ └── com/
│ │ └── alibaba/
│ │ └── easyretry/
│ │ └── extension/
│ │ └── spring/
│ │ ├── RetryListenerInitialize.java
│ │ ├── SPELParamPredicate.java
│ │ ├── SPELResultPredicate.java
│ │ ├── SpringEventApplicationListener.java
│ │ ├── SpringRetryFilterDiscover.java
│ │ └── aop/
│ │ ├── EasyRetryable.java
│ │ └── RetryInterceptor.java
│ └── pom.xml
├── easy-retry-starters/
│ ├── easy-retry-memory-starter/
│ │ ├── pom.xml
│ │ └── src/
│ │ └── main/
│ │ ├── java/
│ │ │ └── com/
│ │ │ └── alibaba/
│ │ │ └── easyretry/
│ │ │ └── memory/
│ │ │ ├── MemoryAutoConfiguration.java
│ │ │ └── config/
│ │ │ └── EasyRetryMemoryCompatibleProperties.java
│ │ └── resources/
│ │ └── META-INF/
│ │ ├── additional-spring-configuration-metadata.json
│ │ └── spring.factories
│ ├── easy-retry-mybatis-starter/
│ │ ├── pom.xml
│ │ └── src/
│ │ └── main/
│ │ ├── java/
│ │ │ └── com/
│ │ │ └── alibaba/
│ │ │ └── easyretry/
│ │ │ └── mybatis/
│ │ │ ├── MybatisAutoConfiguration.java
│ │ │ └── conifg/
│ │ │ └── EasyRetryMybatisProperties.java
│ │ └── resources/
│ │ └── META-INF/
│ │ ├── additional-spring-configuration-metadata.json
│ │ └── spring.factories
│ ├── easy-retry-starter-common/
│ │ ├── pom.xml
│ │ └── src/
│ │ └── main/
│ │ └── java/
│ │ └── com/
│ │ └── alibaba/
│ │ └── easyretry/
│ │ └── starter/
│ │ └── common/
│ │ └── CommonAutoConfiguration.java
│ └── pom.xml
└── pom.xml
================================================
FILE CONTENTS
================================================
================================================
FILE: .editorconfig
================================================
root = true
[*]
charset = utf-8
[*.java]
indent_style = tab
indent_size = 4
end_of_line = lf
trim_trailing_whitespace = true
insert_final_newline = true
[*.{json, yml, xml}]
indent_style = tab
indent_size = 4
[*.md]
insert_final_newline = false
trim_trailing_whitespace = false
[*.properties]
ij_properties_align_group_field_declarations = false
ij_properties_keep_blank_lines = false
ij_properties_key_value_delimiter = equals
ij_properties_spaces_around_key_value_delimiter = false
================================================
FILE: .github/workflows/maven.yml
================================================
# This workflow will build a Java project with Maven
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven
name: Java CI with Maven
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up JDK 1.8
uses: actions/setup-java@v1
with:
java-version: 1.8
- name: Build with Maven
run: mvn -B package --file pom.xml
================================================
FILE: .gitignore
================================================
# Compiled class file
*.class
*.classpath
*.factorypath
# Log file
*.log
# BlueJ files
*.ctxt
# Mobile Tools for Java (J2ME)
.mtj.tmp/
# Package Files #
*.jar
*.war
*.ear
*.zip
*.tar.gz
*.rar
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
# IDE Files #
*.iml
.idea
.idea/
.project
.settings
target
.DS_Store
# temp ignore
*.cache
*.diff
*.patch
*.tmp
# Maven ignore
.flattened-pom.xml
================================================
FILE: LICENSE
================================================
MIT License
Copyright (c) 2021 Alibaba
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
================================================
FILE: README.md
================================================
# Easy-Retry
一种存储介质可扩展的持久化重试方案

### Getting started
#### Memory Retry
1. 增加pom依赖
```xml
com.alibaba
easy-retry-memory-starter
${last-version}
```
2. 在application.properties增加配置
`spring.easyretry.memory.enabled = true`
3. 在需要重试的方法上增加`@EasyRetryable`注解
```java
public class MemoryUserService {
@EasyRetryable
public User getUserById(Long userId){
return new User();
}
}
```
#### Mybatis Retry
1. 增加pom依赖
```xml
com.alibaba
easy-retry-mybatis-starter
${last-version}
```
2. 在application.properties增加配置
`spring.easyretry.mybatis.enabled = true`
3. 声明`javax.sql.DataSource`的`Bean`实例,参考下面例子(以`druid`连接池为例)
```
@Bean(name = "easyRetryMybatisDataSource", initMethod = "init", destroyMethod = "close")
public DataSource easyRetryMybatisDataSource() {
DruidDataSource tds = new DruidDataSource();
tds.setUrl("");
tds.setUsername("");
tds.setPassword("");
...
return tds;
}
```
4. 新增持久化表
```
CREATE TABLE `easy_retry_task` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键',
`gmt_create` datetime NOT NULL COMMENT '创建时间',
`gmt_modified` datetime NOT NULL COMMENT '修改时间',
`sharding` varchar(64) DEFAULT NULL COMMENT '数据库分片字段',
`biz_id` varchar(64) DEFAULT NULL COMMENT '业务id',
`executor_name` varchar(512) NOT NULL COMMENT '执行名称',
`executor_method_name` varchar(512) NOT NULL COMMENT '执行方法名称',
`retry_status` tinyint(4) NOT NULL COMMENT '重试状态',
`args_str` varchar(7168) DEFAULT NULL COMMENT '执行方法参数',
`ext_attrs` varchar(3000) DEFAULT NULL COMMENT '扩展字段',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8 COMMENT='easy_retry_task'
;
```
5. 在需要重试的方法上增加@EasyRetryable注解
```java
public class MybatisUserService {
@EasyRetryable
public User getUserById(Long userId){
return new User();
}
}
```
### Built With
• JDK1.8
• Spring Framework5+
• Spring Boot2.4+
• Maven3.0
================================================
FILE: config/intellij-java-google-style.xml
================================================
.*:id
http://schemas.android.com/apk/res/android
.*:.*Style
http://schemas.android.com/apk/res/android
BY_NAME
.*:layout_width
http://schemas.android.com/apk/res/android
.*:layout_height
http://schemas.android.com/apk/res/android
.*:layout_weight
http://schemas.android.com/apk/res/android
.*:layout_margin
http://schemas.android.com/apk/res/android
.*:layout_marginTop
http://schemas.android.com/apk/res/android
.*:layout_marginBottom
http://schemas.android.com/apk/res/android
.*:layout_marginStart
http://schemas.android.com/apk/res/android
.*:layout_marginEnd
http://schemas.android.com/apk/res/android
.*:layout_marginLeft
http://schemas.android.com/apk/res/android
.*:layout_marginRight
http://schemas.android.com/apk/res/android
.*:layout_.*
http://schemas.android.com/apk/res/android
BY_NAME
.*:padding
http://schemas.android.com/apk/res/android
.*:paddingTop
http://schemas.android.com/apk/res/android
.*:paddingBottom
http://schemas.android.com/apk/res/android
.*:paddingStart
http://schemas.android.com/apk/res/android
.*:paddingEnd
http://schemas.android.com/apk/res/android
.*:paddingLeft
http://schemas.android.com/apk/res/android
.*:paddingRight
http://schemas.android.com/apk/res/android
.*
http://schemas.android.com/apk/res/android
BY_NAME
.*
http://schemas.android.com/apk/res-auto
BY_NAME
.*
http://schemas.android.com/tools
BY_NAME
================================================
FILE: easy-retry-common/pom.xml
================================================
4.0.0
com.alibaba
easy-retry
${revision}
../pom.xml
easy-retry-common
easy-retry-common
easy-retry-common
org.projectlombok
lombok
org.apache.commons
commons-lang3
com.google.guava
guava
org.slf4j
slf4j-api
================================================
FILE: easy-retry-common/src/main/java/com/alibaba/easyretry/common/AbstractResultPredicate.java
================================================
package com.alibaba.easyretry.common;
/**
* @author Created by wuhao on 2021/3/26.
*/
public abstract class AbstractResultPredicate implements EasyRetryPredicate {
@Override
public abstract Boolean apply(T result);
}
================================================
FILE: easy-retry-common/src/main/java/com/alibaba/easyretry/common/AbstractRetrySyncExecutor.java
================================================
package com.alibaba.easyretry.common;
import com.alibaba.easyretry.common.retryer.RetryerInfo;
/**
* @author zhangchi20
* Created on 2023-07-17
*/
public abstract class AbstractRetrySyncExecutor implements RetrySyncExecutor {
private RetryerInfo retryerInfo;
@Override
public void setRetryerInfo(RetryerInfo retryerInfo) {
this.retryerInfo = retryerInfo;
}
public RetryerInfo getRetryerInfo() {
return retryerInfo;
}
@Override
public abstract V call(SCallable callable) throws Throwable;
}
================================================
FILE: easy-retry-common/src/main/java/com/alibaba/easyretry/common/EasyRetryPredicate.java
================================================
package com.alibaba.easyretry.common;
import java.io.Serializable;
/**
* @author Created by wuhao on 2021/3/18.
*/
public interface EasyRetryPredicate extends Serializable {
R apply(T result);
}
================================================
FILE: easy-retry-common/src/main/java/com/alibaba/easyretry/common/Invocation.java
================================================
package com.alibaba.easyretry.common;
/**
* @author Created by wuhao on 2021/3/29.
*/
public interface Invocation {
Object invoke() throws Throwable;
}
================================================
FILE: easy-retry-common/src/main/java/com/alibaba/easyretry/common/RetryConfiguration.java
================================================
package com.alibaba.easyretry.common;
import com.alibaba.easyretry.common.access.RetrySerializerAccess;
import com.alibaba.easyretry.common.access.RetryStrategyAccess;
import com.alibaba.easyretry.common.access.RetryTaskAccess;
import com.alibaba.easyretry.common.event.RetryEventMulticaster;
import com.alibaba.easyretry.common.resolve.ExecutorSolver;
import com.alibaba.easyretry.common.serializer.ResultPredicateSerializer;
/**
* @author Created by wuhao on 2020/11/5.
*/
public interface RetryConfiguration {
RetryTaskAccess getRetryTaskAccess();
RetrySerializerAccess getRetrySerializerAccess();
RetryStrategyAccess getRetryStrategyAccess();
ExecutorSolver getExecutorSolver();
ResultPredicateSerializer getResultPredicateSerializer();
Integer getMaxRetryTimes();
RetryEventMulticaster getRetryEventMulticaster();
default AbstractRetrySyncExecutor getRetrySyncExecutor() {
return null;
}
}
================================================
FILE: easy-retry-common/src/main/java/com/alibaba/easyretry/common/RetryContainer.java
================================================
package com.alibaba.easyretry.common;
/**
* @author Created by wuhao on 2020/11/5.
*/
public interface RetryContainer extends RetryLifecycle {
}
================================================
FILE: easy-retry-common/src/main/java/com/alibaba/easyretry/common/RetryContext.java
================================================
package com.alibaba.easyretry.common;
public interface RetryContext extends RetryLifecycle {
void setAttribute(String key, String value);
String getAttribute(String key);
/**
* 获取唯一标识
*/
String getId();
Invocation getInvocation();
}
================================================
FILE: easy-retry-common/src/main/java/com/alibaba/easyretry/common/RetryExecutor.java
================================================
package com.alibaba.easyretry.common;
import com.alibaba.easyretry.common.constant.enums.HandleResultEnum;
/**
* @author Created by wuhao on 2021/3/2.
*/
public interface RetryExecutor {
HandleResultEnum doExecute(RetryContext context);
}
================================================
FILE: easy-retry-common/src/main/java/com/alibaba/easyretry/common/RetryIdentify.java
================================================
package com.alibaba.easyretry.common;
import java.util.Objects;
/**
* @author Created by wuhao on 2021/2/20.
*/
public class RetryIdentify {
private static final ThreadLocal RETRY_CONTEXT_THREAD_LOCAL = new ThreadLocal<>();
private static final String RETRY_FLAG = "RETRY_FLAG";
public static void start() {
RETRY_CONTEXT_THREAD_LOCAL.set(RETRY_FLAG);
}
public static void stop() {
RETRY_CONTEXT_THREAD_LOCAL.set(null);
}
public static boolean isOnRetry() {
return Objects.nonNull(RETRY_CONTEXT_THREAD_LOCAL.get());
}
}
================================================
FILE: easy-retry-common/src/main/java/com/alibaba/easyretry/common/RetryLifecycle.java
================================================
package com.alibaba.easyretry.common;
/**
* @author Created by wuhao on 2020/11/2.
*/
public interface RetryLifecycle {
void start();
void stop();
}
================================================
FILE: easy-retry-common/src/main/java/com/alibaba/easyretry/common/RetrySyncExecutor.java
================================================
package com.alibaba.easyretry.common;
import com.alibaba.easyretry.common.retryer.RetryerInfo;
/**
* @author zhangchi20
* Created on 2023-07-17
*/
public interface RetrySyncExecutor {
V call(SCallable callable) throws Throwable;
void setRetryerInfo(RetryerInfo retryerInfo);
}
================================================
FILE: easy-retry-common/src/main/java/com/alibaba/easyretry/common/SCallable.java
================================================
package com.alibaba.easyretry.common;
import java.io.Serializable;
/**
* @author Created by wuhao on 2020/11/5.
*/
@FunctionalInterface
public interface SCallable extends Serializable {
V call() throws Throwable;
}
================================================
FILE: easy-retry-common/src/main/java/com/alibaba/easyretry/common/SimpleMethodInvocation.java
================================================
package com.alibaba.easyretry.common;
import java.lang.reflect.Method;
import java.util.Arrays;
import lombok.AllArgsConstructor;
import lombok.Setter;
/**
* @author Created by wuhao on 2021/3/29.
*/
@AllArgsConstructor
public class SimpleMethodInvocation implements Invocation {
@Setter
private Object executor;
@Setter
private Method method;
@Setter
private Object[] args;
@Override
public Object invoke() throws Throwable {
return method.invoke(executor, args);
}
@Override
public String toString() {
return "[Invocation] executor is " + executor.getClass().getName() + " method is " + method
.getName() + " args is " + Arrays.toString(args);
}
}
================================================
FILE: easy-retry-common/src/main/java/com/alibaba/easyretry/common/access/RetrySerializerAccess.java
================================================
package com.alibaba.easyretry.common.access;
import com.alibaba.easyretry.common.serializer.RetryArgSerializer;
/**
* 重试信息序列化器获取 如果方法上有指定序列化器,则使用getRetrySerializer 否则使用全局序列化器getCurrentGlobalRetrySerializer
*
* @author Created by wuhao on 2020/11/6.
*/
public interface RetrySerializerAccess {
/**
* 获取全局序列化器
*/
RetryArgSerializer getCurrentGlobalRetrySerializer();
}
================================================
FILE: easy-retry-common/src/main/java/com/alibaba/easyretry/common/access/RetryStrategyAccess.java
================================================
package com.alibaba.easyretry.common.access;
import com.alibaba.easyretry.common.strategy.StopStrategy;
import com.alibaba.easyretry.common.strategy.WaitStrategy;
/**
* 重试策略获取 如果方法上有指定则用指定Strategy 否则使用Global
*
* @author Created by wuhao on 2020/11/6.
*/
public interface RetryStrategyAccess {
/**
* 获取全局重试任务停止策略
*/
StopStrategy getCurrentGlobalStopStrategy();
/**
* 获取全局等待策略
*/
WaitStrategy getCurrentGlobalWaitStrategy();
}
================================================
FILE: easy-retry-common/src/main/java/com/alibaba/easyretry/common/access/RetryTaskAccess.java
================================================
package com.alibaba.easyretry.common.access;
import java.util.List;
import com.alibaba.easyretry.common.entity.RetryTask;
/**
* 重试任务获取器
*/
public interface RetryTaskAccess {
/**
* 保存重试任务
*/
boolean saveRetryTask(RetryTask retryTask);
/**
* 更改重试任务为处理中
*/
boolean handlingRetryTask(RetryTask retryTask);
/**
* 完结重试任务
*/
boolean finishRetryTask(RetryTask retryTask);
/**
* 停止重试任务
*/
boolean stopRetryTask(RetryTask retryTask);
/**
* 批量查询重试任务
*/
List listAvailableTasks(Long lastId);
}
================================================
FILE: easy-retry-common/src/main/java/com/alibaba/easyretry/common/constant/enums/HandleResultEnum.java
================================================
package com.alibaba.easyretry.common.constant.enums;
/**
* 重试任务重试结果
*
* @author Created by wuhao on 2020/11/1.
*/
public enum HandleResultEnum {
/**
* 处理成功
*/
SUCCESS,
/**
* 处理失败
*/
FAILURE,
/**
* 等待策略返回该case还在等待队列中
*/
WAITING,
/**
* 根据停止策略该笔case停止重试
*/
STOP,
ERROR;
}
================================================
FILE: easy-retry-common/src/main/java/com/alibaba/easyretry/common/constant/enums/RetryTaskStatusEnum.java
================================================
package com.alibaba.easyretry.common.constant.enums;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import lombok.Getter;
/**
* 重试任务状态
*
* @author Created by wuhao on 2020/10/31.
*/
public enum RetryTaskStatusEnum {
/**
* 初始化状态
*/
INIT(0, "初始化"),
/**
* 任务处理中
*/
HANDLING(1, "处理中"),
/**
* 任务处理异常
*/
ERROR(2, "异常"),
/**
* 任务完结
*/
FINISH(3, "完结");
private static final Map MAP =
Stream.of(values())
.collect(Collectors.toMap(RetryTaskStatusEnum::getCode, (value) -> value));
@Getter
private int code;
@Getter
private String desc;
RetryTaskStatusEnum(int code, String desc) {
this.code = code;
this.desc = desc;
}
public static RetryTaskStatusEnum fromCode(int code) {
return MAP.get(code);
}
}
================================================
FILE: easy-retry-common/src/main/java/com/alibaba/easyretry/common/constant/enums/RetryTypeEnum.java
================================================
package com.alibaba.easyretry.common.constant.enums;
/**
* 重试种类
*
* @author Created by zhangchi on 2023-07-12
*/
public enum RetryTypeEnum {
/**
* 同步
*/
SYNC,
/**
* 异步
*/
ASYNC,
;
}
================================================
FILE: easy-retry-common/src/main/java/com/alibaba/easyretry/common/constant/package-info.java
================================================
/**
* @author Created by wuhao on 2020/11/6.
*/
package com.alibaba.easyretry.common.constant;
================================================
FILE: easy-retry-common/src/main/java/com/alibaba/easyretry/common/entity/RetryTask.java
================================================
package com.alibaba.easyretry.common.entity;
import java.util.Date;
import java.util.Map;
import com.alibaba.easyretry.common.constant.enums.RetryTaskStatusEnum;
import lombok.Data;
/**
* 重试任务实体
*
* @author wuhao
*/
@Data
public class RetryTask {
/**
* 主键id
*/
private Long id;
/**
* 业务信息
*/
private String bizId;
/**
* 执行者名称
*/
private String executorName;
/**
* 执行者方法
*/
private String executorMethodName;
/**
* 当重试失败时候执行的方法
*/
private String onFailureMethod;
/**
* 重试任务状态
*/
private RetryTaskStatusEnum status;
/**
* 任务上的扩展字段
*/
private Map extAttrs;
/**
* 重试执行者方法参数
*/
private String argsStr;
private Date gmtCreate;
private Date gmtModified;
}
================================================
FILE: easy-retry-common/src/main/java/com/alibaba/easyretry/common/event/RetryEvent.java
================================================
package com.alibaba.easyretry.common.event;
/**
* @author Created by wuhao on 2021/3/25.
*/
public interface RetryEvent {
String getName();
boolean isOnRetry();
void setAttribute(String key, String vule);
}
================================================
FILE: easy-retry-common/src/main/java/com/alibaba/easyretry/common/event/RetryEventMulticaster.java
================================================
package com.alibaba.easyretry.common.event;
/**
* @author Created by wuhao on 2021/3/26.
*/
public interface RetryEventMulticaster {
void register(RetryListener listener);
void multicast(RetryEvent retryEvent);
}
================================================
FILE: easy-retry-common/src/main/java/com/alibaba/easyretry/common/event/RetryListener.java
================================================
package com.alibaba.easyretry.common.event;
/**
* @author Created by wuhao on 2021/3/25.
*/
public interface RetryListener {
void onRetryEvent(T event);
}
================================================
FILE: easy-retry-common/src/main/java/com/alibaba/easyretry/common/event/before/AfterSaveBeforeRetryEvent.java
================================================
package com.alibaba.easyretry.common.event.before;
import com.alibaba.easyretry.common.entity.RetryTask;
/**
* @author Created by wuhao on 2021/3/25.
*/
public class AfterSaveBeforeRetryEvent extends BeforeRetryEvent {
public AfterSaveBeforeRetryEvent(RetryTask retryTask) {
super(retryTask);
}
}
================================================
FILE: easy-retry-common/src/main/java/com/alibaba/easyretry/common/event/before/BeforeRetryEvent.java
================================================
package com.alibaba.easyretry.common.event.before;
import java.util.Map;
import java.util.Objects;
import com.alibaba.easyretry.common.entity.RetryTask;
import com.alibaba.easyretry.common.event.RetryEvent;
import com.google.common.collect.Maps;
/**
* @author Created by wuhao on 2021/3/25.
*/
public abstract class BeforeRetryEvent implements RetryEvent {
private RetryTask retryTask;
public BeforeRetryEvent(RetryTask retryTask) {
this.retryTask = retryTask;
}
@Override
public boolean isOnRetry() {
return false;
}
@Override
public void setAttribute(String key, String value) {
Map extAttrs = retryTask.getExtAttrs();
if (Objects.isNull(extAttrs)) {
extAttrs = Maps.newHashMap();
}
extAttrs.put(key, value);
}
@Override
public String getName() {
return this.getClass().getSimpleName();
}
}
================================================
FILE: easy-retry-common/src/main/java/com/alibaba/easyretry/common/event/before/PrepSaveBeforeRetryEvent.java
================================================
package com.alibaba.easyretry.common.event.before;
import com.alibaba.easyretry.common.entity.RetryTask;
/**
* @author Created by wuhao on 2021/3/25.
*/
public class PrepSaveBeforeRetryEvent extends BeforeRetryEvent {
public PrepSaveBeforeRetryEvent(RetryTask retryTask) {
super(retryTask);
}
}
================================================
FILE: easy-retry-common/src/main/java/com/alibaba/easyretry/common/event/on/FailureOnRetryEvent.java
================================================
package com.alibaba.easyretry.common.event.on;
import com.alibaba.easyretry.common.RetryContext;
/**
* @author Created by wuhao on 2021/3/25.
*/
public class FailureOnRetryEvent extends OnRetryEvent {
public FailureOnRetryEvent(RetryContext retryContext) {
super(retryContext);
}
}
================================================
FILE: easy-retry-common/src/main/java/com/alibaba/easyretry/common/event/on/OnRetryEvent.java
================================================
package com.alibaba.easyretry.common.event.on;
import com.alibaba.easyretry.common.RetryContext;
import com.alibaba.easyretry.common.event.RetryEvent;
/**
* @author Created by wuhao on 2021/3/25.
*/
public abstract class OnRetryEvent implements RetryEvent {
final private RetryContext retryContext;
public OnRetryEvent(RetryContext retryContext) {
this.retryContext = retryContext;
}
@Override
public void setAttribute(String key, String value) {
retryContext.setAttribute(key, value);
}
public String getAttribute(String key) {
return retryContext.getAttribute(key);
}
@Override
public boolean isOnRetry() {
return true;
}
@Override
public String getName() {
return this.getClass().getSimpleName();
}
}
================================================
FILE: easy-retry-common/src/main/java/com/alibaba/easyretry/common/event/on/StopOnRetryEvent.java
================================================
package com.alibaba.easyretry.common.event.on;
import com.alibaba.easyretry.common.RetryContext;
/**
* @author Created by wuhao on 2021/3/25.
*/
public class StopOnRetryEvent extends OnRetryEvent {
public StopOnRetryEvent(RetryContext retryContext) {
super(retryContext);
}
}
================================================
FILE: easy-retry-common/src/main/java/com/alibaba/easyretry/common/event/on/SuccessOnRetryEvent.java
================================================
package com.alibaba.easyretry.common.event.on;
import com.alibaba.easyretry.common.RetryContext;
/**
* @author Created by wuhao on 2021/3/25.
*/
public class SuccessOnRetryEvent extends OnRetryEvent {
public SuccessOnRetryEvent(RetryContext retryContext) {
super(retryContext);
}
}
================================================
FILE: easy-retry-common/src/main/java/com/alibaba/easyretry/common/filter/AbstractRetryFilter.java
================================================
package com.alibaba.easyretry.common.filter;
/**
* @author Created by wuhao on 2021/3/22.
*/
public abstract class AbstractRetryFilter implements RetryFilter {
protected RetryFilter next;
@Override
public void setNext(RetryFilter next) {
this.next = next;
}
}
================================================
FILE: easy-retry-common/src/main/java/com/alibaba/easyretry/common/filter/RetryFilter.java
================================================
package com.alibaba.easyretry.common.filter;
import com.alibaba.easyretry.common.RetryContext;
/**
* @author Created by wuhao on 2021/3/22.
*/
public interface RetryFilter {
RetryFilterResponse doFilter(RetryContext retryContext) throws Throwable;
void setNext(RetryFilter next);
}
================================================
FILE: easy-retry-common/src/main/java/com/alibaba/easyretry/common/filter/RetryFilterDiscover.java
================================================
package com.alibaba.easyretry.common.filter;
import java.util.List;
/**
* @author Created by wuhao on 2021/4/9.
*/
public interface RetryFilterDiscover {
List discoverAll();
}
================================================
FILE: easy-retry-common/src/main/java/com/alibaba/easyretry/common/filter/RetryFilterInvocation.java
================================================
package com.alibaba.easyretry.common.filter;
import com.alibaba.easyretry.common.RetryContext;
/**
* @author Created by wuhao on 2021/4/10.
*/
public interface RetryFilterInvocation {
RetryFilterResponse invoke(RetryContext retryContext) throws Throwable;
}
================================================
FILE: easy-retry-common/src/main/java/com/alibaba/easyretry/common/filter/RetryFilterInvocationHandler.java
================================================
package com.alibaba.easyretry.common.filter;
/**
* @author Created by wuhao on 2021/3/19.
*/
public interface RetryFilterInvocationHandler {
void handle();
}
================================================
FILE: easy-retry-common/src/main/java/com/alibaba/easyretry/common/filter/RetryFilterRegister.java
================================================
package com.alibaba.easyretry.common.filter;
import java.util.List;
/**
* @author Created by wuhao on 2021/3/22.
*/
public interface RetryFilterRegister {
void register(RetryFilter retryFilter);
List export();
}
================================================
FILE: easy-retry-common/src/main/java/com/alibaba/easyretry/common/filter/RetryFilterRegisterHandler.java
================================================
package com.alibaba.easyretry.common.filter;
/**
* @author Created by wuhao on 2021/4/9.
*/
public interface RetryFilterRegisterHandler {
void handle();
}
================================================
FILE: easy-retry-common/src/main/java/com/alibaba/easyretry/common/filter/RetryFilterResponse.java
================================================
package com.alibaba.easyretry.common.filter;
import lombok.Data;
/**
* @author Created by wuhao on 2021/3/22.
*/
@Data
public class RetryFilterResponse {
private Object response;
}
================================================
FILE: easy-retry-common/src/main/java/com/alibaba/easyretry/common/processor/AsyncPersistenceProcessor.java
================================================
package com.alibaba.easyretry.common.processor;
/**
* @author Created by wuhao on 2021/3/19.
*/
public interface AsyncPersistenceProcessor extends RetryProcessor {
@Override
void process();
boolean needRetry();
R getResult() throws Throwable;
}
================================================
FILE: easy-retry-common/src/main/java/com/alibaba/easyretry/common/processor/RetryProcessor.java
================================================
package com.alibaba.easyretry.common.processor;
/**
* @author Created by wuhao on 2021/3/19.
*/
public interface RetryProcessor {
void process();
}
================================================
FILE: easy-retry-common/src/main/java/com/alibaba/easyretry/common/processor/SyncProcessor.java
================================================
package com.alibaba.easyretry.common.processor;
/**
* @author Created by zhangchi on 2023-07-12
*/
public interface SyncProcessor extends RetryProcessor {
R getResult() throws Throwable;
}
================================================
FILE: easy-retry-common/src/main/java/com/alibaba/easyretry/common/resolve/ExecutorSolver.java
================================================
package com.alibaba.easyretry.common.resolve;
/**
* @author Created by wuhao on 2020/11/8.
*/
public interface ExecutorSolver {
Object resolver(String executorName);
}
================================================
FILE: easy-retry-common/src/main/java/com/alibaba/easyretry/common/retryer/Retryer.java
================================================
package com.alibaba.easyretry.common.retryer;
import com.alibaba.easyretry.common.SCallable;
/**
* @author Created by wuhao on 2020/11/5.
*/
public interface Retryer {
V call(SCallable callable) throws Throwable;
}
================================================
FILE: easy-retry-common/src/main/java/com/alibaba/easyretry/common/retryer/RetryerInfo.java
================================================
package com.alibaba.easyretry.common.retryer;
import com.alibaba.easyretry.common.AbstractResultPredicate;
import com.alibaba.easyretry.common.RetryConfiguration;
import lombok.Data;
import lombok.experimental.Accessors;
/**
* @author Created by wuhao on 2021/3/19.
*/
@Data
@Accessors(chain = true)
public class RetryerInfo {
/**
* 执行者名称
*/
private String executorName;
/**
* 执行者方法
*/
private String executorMethodName;
private String onFailureMethod;
/**
* 业务id,外部可以自定义存储一些信息
*/
private String bizId;
private Object[] args;
private Class extends Throwable> onException;
private RetryConfiguration retryConfiguration;
private String namespace;
private boolean reThrowException;
private AbstractResultPredicate resultPredicate;
}
================================================
FILE: easy-retry-common/src/main/java/com/alibaba/easyretry/common/serializer/ArgDeSerializerInfo.java
================================================
package com.alibaba.easyretry.common.serializer;
import lombok.Data;
/**
* @author Created by wuhao on 2020/11/1.
*/
@Data
public class ArgDeSerializerInfo {
private String argsStr;
}
================================================
FILE: easy-retry-common/src/main/java/com/alibaba/easyretry/common/serializer/ArgSerializerInfo.java
================================================
package com.alibaba.easyretry.common.serializer;
import lombok.Data;
/**
* @author Created by wuhao on 2020/11/1.
*/
@Data
public class ArgSerializerInfo {
/**
* 执行者名称
*/
private String executorName;
private String executorClassName;
/**
* 执行者方法
*/
private String executorMethodName;
private Object[] args;
}
================================================
FILE: easy-retry-common/src/main/java/com/alibaba/easyretry/common/serializer/EasyRetrySerializer.java
================================================
package com.alibaba.easyretry.common.serializer;
/**
* @author Created by wuhao on 2021/3/18.
*/
public interface EasyRetrySerializer {
String serialize(T serializeInfo);
T deSerialize(String infoStr);
}
================================================
FILE: easy-retry-common/src/main/java/com/alibaba/easyretry/common/serializer/ResultPredicateSerializer.java
================================================
package com.alibaba.easyretry.common.serializer;
import com.alibaba.easyretry.common.AbstractResultPredicate;
/**
* @author Created by wuhao on 2021/3/18.
*/
public interface ResultPredicateSerializer extends EasyRetrySerializer {
}
================================================
FILE: easy-retry-common/src/main/java/com/alibaba/easyretry/common/serializer/RetryArgSerializer.java
================================================
package com.alibaba.easyretry.common.serializer;
/**
* Retry 序列化器
*/
public interface RetryArgSerializer extends EasyRetrySerializer {
}
================================================
FILE: easy-retry-common/src/main/java/com/alibaba/easyretry/common/strategy/RetryStrategy.java
================================================
package com.alibaba.easyretry.common.strategy;
import com.alibaba.easyretry.common.RetryContext;
/**
* @author Created by wuhao on 2020/11/2.
*/
public interface RetryStrategy {
void clear(RetryContext context);
}
================================================
FILE: easy-retry-common/src/main/java/com/alibaba/easyretry/common/strategy/StopStrategy.java
================================================
package com.alibaba.easyretry.common.strategy;
import com.alibaba.easyretry.common.RetryContext;
/**
* @author Created by wuhao on 2020/11/1.
*/
public interface StopStrategy extends RetryStrategy {
boolean shouldStop(RetryContext context);
}
================================================
FILE: easy-retry-common/src/main/java/com/alibaba/easyretry/common/strategy/WaitStrategy.java
================================================
package com.alibaba.easyretry.common.strategy;
import com.alibaba.easyretry.common.RetryContext;
/**
* @author Created by wuhao on 2020/11/1.
*/
public interface WaitStrategy extends RetryStrategy {
boolean shouldWait(RetryContext context);
void backOff(RetryContext context);
}
================================================
FILE: easy-retry-core/pom.xml
================================================
4.0.0
com.alibaba
easy-retry
${revision}
../pom.xml
easy-retry-core
easy-retry-core
easy-retry-core
${project.groupId}
easy-retry-common
org.apache.commons
commons-lang3
com.google.guava
guava
com.caucho
hessian
org.slf4j
slf4j-api
com.alibaba
fastjson
org.apache.commons
commons-collections4
================================================
FILE: easy-retry-core/src/main/java/com/alibaba/easyretry/core/DegradeAbleRetryExecutor.java
================================================
package com.alibaba.easyretry.core;
import com.alibaba.easyretry.common.RetryContext;
import com.alibaba.easyretry.common.RetryExecutor;
import com.alibaba.easyretry.common.constant.enums.HandleResultEnum;
import com.alibaba.easyretry.core.degrade.EasyRetryDegradeHelper;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
/**
* @author Created by gejinfeng on 2021/4/29.
*/
@Slf4j
public class DegradeAbleRetryExecutor implements RetryExecutor {
@Setter
private RetryExecutor retryExecutor;
@Setter
private EasyRetryDegradeHelper easyRetryDegradeHelper;
@Override
public HandleResultEnum doExecute(RetryContext context) {
if (easyRetryDegradeHelper.degrade(context)) {
return HandleResultEnum.STOP;
}
return retryExecutor.doExecute(context);
}
}
================================================
FILE: easy-retry-core/src/main/java/com/alibaba/easyretry/core/PersistenceRetryExecutor.java
================================================
package com.alibaba.easyretry.core;
import java.lang.reflect.InvocationTargetException;
import com.alibaba.easyretry.common.RetryConfiguration;
import com.alibaba.easyretry.common.RetryContext;
import com.alibaba.easyretry.common.RetryExecutor;
import com.alibaba.easyretry.common.access.RetryTaskAccess;
import com.alibaba.easyretry.common.constant.enums.HandleResultEnum;
import com.alibaba.easyretry.common.entity.RetryTask;
import com.alibaba.easyretry.common.event.RetryEvent;
import com.alibaba.easyretry.common.event.on.FailureOnRetryEvent;
import com.alibaba.easyretry.common.event.on.StopOnRetryEvent;
import com.alibaba.easyretry.common.event.on.SuccessOnRetryEvent;
import com.alibaba.easyretry.common.filter.RetryFilterInvocation;
import com.alibaba.easyretry.common.filter.RetryFilterResponse;
import com.alibaba.easyretry.core.context.MaxAttemptsPersistenceRetryContext;
import com.alibaba.easyretry.core.process.async.on.AbstractAsyncPersistenceOnRetryProcessor;
import com.alibaba.easyretry.core.process.async.on.ExceptionPersistenceAsynOnRetryProcessor;
import com.alibaba.easyretry.core.process.async.on.ResultAsynPersistenceOnRetryProcessor;
import com.alibaba.easyretry.core.utils.LogUtils;
import com.alibaba.easyretry.core.utils.PrintUtils;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
/**
* @author Created by wuhao on 2021/3/2.
*/
@Slf4j
public class PersistenceRetryExecutor implements RetryExecutor {
@Setter
private RetryConfiguration retryConfiguration;
@Setter
private RetryFilterInvocation retryFilterInvocation;
@Override
public HandleResultEnum doExecute(RetryContext context) {
try {
PrintUtils.monitorInfo("begin deal", context);
return handle(context);
} catch (Throwable e) {
log.error("Retry invoke failed", e);
return HandleResultEnum.ERROR;
}
}
private HandleResultEnum handle(RetryContext context) {
MaxAttemptsPersistenceRetryContext maxAttemptsPersistenceRetryContext
= (MaxAttemptsPersistenceRetryContext)context;
if (maxAttemptsPersistenceRetryContext.getWaitStrategy().shouldWait(context)) {
PrintUtils.monitorInfo("shouldWait", context);
return HandleResultEnum.WAITING;
}
PrintUtils.monitorInfo("handlingRetryTask", context);
retryConfiguration.getRetryTaskAccess()
.handlingRetryTask(maxAttemptsPersistenceRetryContext.getRetryTask());
AbstractAsyncPersistenceOnRetryProcessor