
com.alibaba.easyretry.core.RetryerBuilder Maven / Gradle / Ivy
The newest version!
package com.alibaba.easyretry.core;
import com.alibaba.easyretry.common.AbstractResultPredicate;
import com.alibaba.easyretry.common.RetryConfiguration;
import com.alibaba.easyretry.common.constant.enums.RetryTypeEnum;
import com.alibaba.easyretry.common.retryer.Retryer;
/**
* @author Created by zhangchi on 2023-07-13
*/
public class RetryerBuilder {
/**
* 执行者名称
*/
private String executorNameContext;
/**
* 执行者方法
*/
private String executorMethodNameContext;
private String onFailureMethodContext;
/**
* 业务id,外部可以自定义存储一些信息
*/
private String bizIdContext;
private Object[] argsContext;
private Class extends Throwable> onExceptionContext;
private RetryConfiguration retryConfigurationContext;
private String namespaceContext;
private boolean reThrowExceptionContext;
private AbstractResultPredicate resultPredicateContext;
public RetryerBuilder withExecutorName(String executorName) {
executorNameContext = executorName;
return this;
}
public RetryerBuilder withExecutorMethodName(String executorMethodName) {
executorMethodNameContext = executorMethodName;
return this;
}
public RetryerBuilder withBizId(String bizId) {
bizIdContext = bizId;
return this;
}
public RetryerBuilder withArgs(Object[] args) {
argsContext = args;
return this;
}
public RetryerBuilder withOnException(Class extends Throwable> onException) {
onExceptionContext = onException;
return this;
}
public RetryerBuilder withOnFailureMethod(String onFailureMethod) {
onFailureMethodContext = onFailureMethod;
return this;
}
public RetryerBuilder withReThrowException(boolean reThrowException) {
reThrowExceptionContext = reThrowException;
return this;
}
public RetryerBuilder withNamespace(String namespace) {
namespaceContext = namespace;
return this;
}
public RetryerBuilder withConfiguration(RetryConfiguration retryConfiguration) {
retryConfigurationContext = retryConfiguration;
return this;
}
public RetryerBuilder withResultPredicate(AbstractResultPredicate abstractResultPredicate) {
resultPredicateContext = abstractResultPredicate;
return this;
}
public Retryer build(RetryTypeEnum retryTypeEnum) {
if (RetryTypeEnum.SYNC == retryTypeEnum) {
return buildSyncRetryer();
} else {
return buildAsyncRetryer();
}
}
private SyncRetryer buildSyncRetryer() {
SyncRetryerBuilder builder = SyncRetryerBuilder.of(retryConfigurationContext)
.withConfiguration(retryConfigurationContext);
return builder.build();
}
private PersistenceRetryer buildAsyncRetryer() {
PersistenceRetryerBuilder builder = PersistenceRetryerBuilder.of(retryConfigurationContext)
.withExecutorName(executorNameContext)
.withExecutorMethodName(executorMethodNameContext)
.withArgs(argsContext)
.withConfiguration(retryConfigurationContext)
// .withOnFailureMethod(retryable.onFailureMethod())
// .withNamespace(namespace)
.withReThrowException(reThrowExceptionContext)
.withResultPredicate(resultPredicateContext);
return builder.build();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy