feat(1.0.0): retry模块类命名优化
This commit is contained in:
parent
2c8a158be4
commit
850d2cab36
@ -1,12 +1,8 @@
|
||||
package com.aizuda.snailjob.client.starter;
|
||||
|
||||
import com.aizuda.snailjob.client.core.annotation.Retryable;
|
||||
import com.aizuda.snailjob.client.core.intercepter.SnailJobInterceptor;
|
||||
import com.aizuda.snailjob.client.core.intercepter.SnailJobPointcutAdvisor;
|
||||
import com.aizuda.snailjob.client.core.strategy.RetryStrategy;
|
||||
import com.aizuda.snailjob.client.core.annotation.Retryable;
|
||||
import com.aizuda.snailjob.client.core.intercepter.SnailJobInterceptor;
|
||||
import com.aizuda.snailjob.client.core.intercepter.SnailJobPointcutAdvisor;
|
||||
import com.aizuda.snailjob.client.core.intercepter.SnailRetryInterceptor;
|
||||
import com.aizuda.snailjob.client.core.intercepter.SnailRetryPointcutAdvisor;
|
||||
import com.aizuda.snailjob.client.core.strategy.RetryStrategy;
|
||||
import org.aopalliance.intercept.MethodInterceptor;
|
||||
import org.springframework.aop.Advisor;
|
||||
@ -26,14 +22,14 @@ public class SnailJobClientRetryCoreAutoConfiguration {
|
||||
@Bean
|
||||
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
|
||||
public Advisor snailJobPointcutAdvisor(MethodInterceptor snailJobInterceptor) {
|
||||
return new SnailJobPointcutAdvisor(snailJobInterceptor);
|
||||
return new SnailRetryPointcutAdvisor(snailJobInterceptor);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
|
||||
public MethodInterceptor snailJobInterceptor(StandardEnvironment standardEnvironment,
|
||||
@Lazy RetryStrategy localRetryStrategies) {
|
||||
return new SnailJobInterceptor(standardEnvironment, localRetryStrategies);
|
||||
return new SnailRetryInterceptor(standardEnvironment, localRetryStrategies);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -10,9 +10,9 @@ import com.aizuda.snailjob.client.core.RetryArgSerializer;
|
||||
import com.aizuda.snailjob.client.common.cache.GroupVersionCache;
|
||||
import com.aizuda.snailjob.client.core.cache.RetryerInfoCache;
|
||||
import com.aizuda.snailjob.client.core.callback.RetryCompleteCallback;
|
||||
import com.aizuda.snailjob.client.core.exception.SnailJobClientException;
|
||||
import com.aizuda.snailjob.client.core.exception.SnailRetryClientException;
|
||||
import com.aizuda.snailjob.client.core.intercepter.RetrySiteSnapshot;
|
||||
import com.aizuda.snailjob.client.core.loader.SnailJobSpiLoader;
|
||||
import com.aizuda.snailjob.client.core.loader.SnailRetrySpiLoader;
|
||||
import com.aizuda.snailjob.client.core.log.RetryLogMeta;
|
||||
import com.aizuda.snailjob.client.core.retryer.RetryerInfo;
|
||||
import com.aizuda.snailjob.client.core.retryer.RetryerResultContext;
|
||||
@ -31,17 +31,6 @@ import com.aizuda.snailjob.common.core.model.Result;
|
||||
import com.aizuda.snailjob.common.core.util.JsonUtil;
|
||||
import com.aizuda.snailjob.common.log.enums.LogTypeEnum;
|
||||
import com.aizuda.snailjob.server.model.dto.ConfigDTO;
|
||||
import com.aizuda.snailjob.client.common.log.support.SnailJobLogManager;
|
||||
import com.aizuda.snailjob.client.common.rpc.client.RequestMethod;
|
||||
import com.aizuda.snailjob.client.core.cache.RetryerInfoCache;
|
||||
import com.aizuda.snailjob.client.core.callback.RetryCompleteCallback;
|
||||
import com.aizuda.snailjob.client.core.exception.SnailJobClientException;
|
||||
import com.aizuda.snailjob.client.core.intercepter.RetrySiteSnapshot;
|
||||
import com.aizuda.snailjob.client.core.log.RetryLogMeta;
|
||||
import com.aizuda.snailjob.client.core.retryer.RetryerInfo;
|
||||
import com.aizuda.snailjob.client.core.retryer.RetryerResultContext;
|
||||
import com.aizuda.snailjob.client.core.serializer.JacksonSerializer;
|
||||
import com.aizuda.snailjob.client.core.strategy.RetryStrategy;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import jakarta.validation.ConstraintViolation;
|
||||
import jakarta.validation.Validation;
|
||||
@ -64,7 +53,7 @@ import java.util.Set;
|
||||
* @date : 2022-03-09 16:33
|
||||
*/
|
||||
@SnailEndPoint
|
||||
public class RetryEndPoint {
|
||||
public class SnailRetryEndPoint {
|
||||
|
||||
@Autowired
|
||||
@Qualifier("remoteRetryStrategies")
|
||||
@ -86,11 +75,11 @@ public class RetryEndPoint {
|
||||
RetryerInfo retryerInfo = RetryerInfoCache.get(executeReqDto.getScene(), executeReqDto.getExecutorName());
|
||||
if (Objects.isNull(retryerInfo)) {
|
||||
SnailJobLog.REMOTE.error("场景:[{}]配置不存在, 请检查您的场景和执行器是否存在", executeReqDto.getScene());
|
||||
throw new SnailJobClientException("场景:[{}]配置不存在, 请检查您的场景和执行器是否存在",
|
||||
throw new SnailRetryClientException("场景:[{}]配置不存在, 请检查您的场景和执行器是否存在",
|
||||
executeReqDto.getScene());
|
||||
}
|
||||
|
||||
RetryArgSerializer retryArgSerializer = SnailJobSpiLoader.loadRetryArgSerializer();
|
||||
RetryArgSerializer retryArgSerializer = SnailRetrySpiLoader.loadRetryArgSerializer();
|
||||
|
||||
Object[] deSerialize;
|
||||
try {
|
||||
@ -98,7 +87,7 @@ public class RetryEndPoint {
|
||||
retryerInfo.getExecutor().getClass(), retryerInfo.getMethod());
|
||||
} catch (JsonProcessingException e) {
|
||||
SnailJobLog.REMOTE.error("参数解析异常", e);
|
||||
throw new SnailJobClientException("参数解析异常", e);
|
||||
throw new SnailRetryClientException("参数解析异常", e);
|
||||
}
|
||||
|
||||
DispatchRetryResultDTO executeRespDto = new DispatchRetryResultDTO();
|
||||
@ -194,7 +183,7 @@ public class RetryEndPoint {
|
||||
return new Result(0, "回调失败");
|
||||
}
|
||||
|
||||
RetryArgSerializer retryArgSerializer = SnailJobSpiLoader.loadRetryArgSerializer();
|
||||
RetryArgSerializer retryArgSerializer = SnailRetrySpiLoader.loadRetryArgSerializer();
|
||||
|
||||
deSerialize = (Object[]) retryArgSerializer.deSerialize(callbackDTO.getArgsStr(),
|
||||
retryerInfo.getExecutor().getClass(), retryerInfo.getMethod());
|
||||
@ -237,10 +226,10 @@ public class RetryEndPoint {
|
||||
Object[].class);
|
||||
break;
|
||||
default:
|
||||
throw new SnailJobClientException("回调状态异常");
|
||||
throw new SnailRetryClientException("回调状态异常");
|
||||
}
|
||||
|
||||
Assert.notNull(method, () -> new SnailJobClientException("no such method"));
|
||||
Assert.notNull(method, () -> new SnailRetryClientException("no such method"));
|
||||
ReflectionUtils.invokeMethod(method, retryCompleteCallback, retryerInfo.getScene(),
|
||||
retryerInfo.getExecutorClassName(), deSerialize);
|
||||
return new Result(1, "回调成功");
|
||||
@ -273,7 +262,7 @@ public class RetryEndPoint {
|
||||
deSerialize);
|
||||
break;
|
||||
default:
|
||||
throw new SnailJobClientException("回调状态异常");
|
||||
throw new SnailRetryClientException("回调状态异常");
|
||||
}
|
||||
|
||||
return new Result(1, "回调成功");
|
||||
@ -302,7 +291,7 @@ public class RetryEndPoint {
|
||||
|
||||
RetryerInfo retryerInfo = RetryerInfoCache.get(scene, executorName);
|
||||
Assert.notNull(retryerInfo,
|
||||
() -> new SnailJobClientException("重试信息不存在 scene:[{}] executorName:[{}]", scene, executorName));
|
||||
() -> new SnailRetryClientException("重试信息不存在 scene:[{}] executorName:[{}]", scene, executorName));
|
||||
|
||||
Method executorMethod = retryerInfo.getMethod();
|
||||
|
||||
@ -313,7 +302,7 @@ public class RetryEndPoint {
|
||||
deSerialize = (Object[]) retryArgSerializer.deSerialize(argsStr, retryerInfo.getExecutor().getClass(),
|
||||
retryerInfo.getMethod());
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new SnailJobClientException("参数解析异常", e);
|
||||
throw new SnailRetryClientException("参数解析异常", e);
|
||||
}
|
||||
|
||||
String idempotentId;
|
||||
@ -326,7 +315,7 @@ public class RetryEndPoint {
|
||||
idempotentId = (String) ReflectionUtils.invokeMethod(method, generate, idempotentIdContext);
|
||||
} catch (Exception exception) {
|
||||
SnailJobLog.LOCAL.error("幂等id生成异常:{},{}", scene, argsStr, exception);
|
||||
throw new SnailJobClientException("idempotentId生成异常:{},{}", scene, argsStr);
|
||||
throw new SnailRetryClientException("idempotentId生成异常:{},{}", scene, argsStr);
|
||||
}
|
||||
|
||||
return new Result<>(idempotentId);
|
@ -8,7 +8,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||
* @date : 2022-03-04 16:55
|
||||
*/
|
||||
@Slf4j
|
||||
public class SimpleSnailJobListener implements SnailJobListener {
|
||||
public class SimpleSnailRetryListener implements SnailJobListener {
|
||||
|
||||
@Override
|
||||
public void beforeRetry(String sceneName, String executorClassName, Object[] params) {
|
@ -1,38 +0,0 @@
|
||||
package com.aizuda.snailjob.client.core.exception;
|
||||
|
||||
import com.aizuda.snailjob.common.core.exception.BaseSnailJobException;
|
||||
|
||||
/**
|
||||
* @author: opensnail
|
||||
* @date : 2022-03-03 14:49
|
||||
*/
|
||||
public class SnailJobClientException extends BaseSnailJobException {
|
||||
|
||||
public SnailJobClientException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public SnailJobClientException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public SnailJobClientException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
public SnailJobClientException(String message, Object... arguments) {
|
||||
super(message, arguments);
|
||||
}
|
||||
|
||||
public SnailJobClientException(String message, Object[] arguments, Throwable cause) {
|
||||
super(message, arguments, cause);
|
||||
}
|
||||
|
||||
public SnailJobClientException(String message, Object argument, Throwable cause) {
|
||||
super(message, argument, cause);
|
||||
}
|
||||
|
||||
public SnailJobClientException(String message, Object argument) {
|
||||
super(message, argument);
|
||||
}
|
||||
}
|
@ -1,38 +0,0 @@
|
||||
package com.aizuda.snailjob.client.core.exception;
|
||||
|
||||
import com.aizuda.snailjob.common.core.exception.BaseSnailJobException;
|
||||
|
||||
/**
|
||||
* @author: opensnail
|
||||
* @date : 2022-03-03 14:49
|
||||
*/
|
||||
public class SnailJobClientTimeOutException extends BaseSnailJobException {
|
||||
|
||||
public SnailJobClientTimeOutException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public SnailJobClientTimeOutException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public SnailJobClientTimeOutException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
public SnailJobClientTimeOutException(String message, Object... arguments) {
|
||||
super(message, arguments);
|
||||
}
|
||||
|
||||
public SnailJobClientTimeOutException(String message, Object[] arguments, Throwable cause) {
|
||||
super(message, arguments, cause);
|
||||
}
|
||||
|
||||
public SnailJobClientTimeOutException(String message, Object argument, Throwable cause) {
|
||||
super(message, argument, cause);
|
||||
}
|
||||
|
||||
public SnailJobClientTimeOutException(String message, Object argument) {
|
||||
super(message, argument);
|
||||
}
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
package com.aizuda.snailjob.client.core.exception;
|
||||
|
||||
import com.aizuda.snailjob.common.core.exception.BaseSnailJobException;
|
||||
|
||||
/**
|
||||
* @author: opensnail
|
||||
* @date : 2022-03-03 14:49
|
||||
*/
|
||||
public class SnailRetryClientException extends BaseSnailJobException {
|
||||
|
||||
public SnailRetryClientException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public SnailRetryClientException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public SnailRetryClientException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
public SnailRetryClientException(String message, Object... arguments) {
|
||||
super(message, arguments);
|
||||
}
|
||||
|
||||
public SnailRetryClientException(String message, Object[] arguments, Throwable cause) {
|
||||
super(message, arguments, cause);
|
||||
}
|
||||
|
||||
public SnailRetryClientException(String message, Object argument, Throwable cause) {
|
||||
super(message, argument, cause);
|
||||
}
|
||||
|
||||
public SnailRetryClientException(String message, Object argument) {
|
||||
super(message, argument);
|
||||
}
|
||||
}
|
@ -3,9 +3,8 @@ package com.aizuda.snailjob.client.core.executor;
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import com.aizuda.snailjob.client.core.RetryExecutorParameter;
|
||||
import com.aizuda.snailjob.client.core.cache.RetryerInfoCache;
|
||||
import com.aizuda.snailjob.client.core.exception.SnailJobClientException;
|
||||
import com.aizuda.snailjob.client.core.exception.SnailRetryClientException;
|
||||
import com.aizuda.snailjob.common.log.SnailJobLog;
|
||||
import com.aizuda.snailjob.client.core.exception.SnailJobClientException;
|
||||
import com.github.rholder.retry.RetryException;
|
||||
import com.github.rholder.retry.RetryListener;
|
||||
import com.github.rholder.retry.Retryer;
|
||||
@ -29,7 +28,7 @@ public class GuavaRetryExecutor extends AbstractRetryExecutor<WaitStrategy, Stop
|
||||
|
||||
public GuavaRetryExecutor(String sceneName, String executorClassName) {
|
||||
retryerInfo = RetryerInfoCache.get(sceneName, executorClassName);
|
||||
Assert.notNull(retryerInfo, () -> new SnailJobClientException("retryerInfo is null sceneName:[{}] executorClassName:[{}]", sceneName, executorClassName));
|
||||
Assert.notNull(retryerInfo, () -> new SnailRetryClientException("retryerInfo is null sceneName:[{}] executorClassName:[{}]", sceneName, executorClassName));
|
||||
}
|
||||
|
||||
public GuavaRetryExecutor() {
|
||||
|
@ -1,8 +1,8 @@
|
||||
package com.aizuda.snailjob.client.core.intercepter;
|
||||
|
||||
import com.aizuda.snailjob.client.core.RetrySiteSnapshotContext;
|
||||
import com.aizuda.snailjob.client.core.exception.SnailJobClientException;
|
||||
import com.aizuda.snailjob.client.core.loader.SnailJobSpiLoader;
|
||||
import com.aizuda.snailjob.client.core.exception.SnailRetryClientException;
|
||||
import com.aizuda.snailjob.client.core.loader.SnailRetrySpiLoader;
|
||||
import com.aizuda.snailjob.common.core.constant.SystemConstants;
|
||||
import com.aizuda.snailjob.common.core.model.SnailJobHeaders;
|
||||
import lombok.AllArgsConstructor;
|
||||
@ -24,33 +24,33 @@ public class RetrySiteSnapshot {
|
||||
/**
|
||||
* 重试阶段,1-内存重试阶段,2-服务端重试阶段
|
||||
*/
|
||||
private static final RetrySiteSnapshotContext<Integer> RETRY_STAGE = SnailJobSpiLoader.loadRetrySiteSnapshotContext();
|
||||
private static final RetrySiteSnapshotContext<Integer> RETRY_STAGE = SnailRetrySpiLoader.loadRetrySiteSnapshotContext();
|
||||
|
||||
/**
|
||||
* 标记重试方法入口
|
||||
*/
|
||||
private static final RetrySiteSnapshotContext<Deque<MethodEntranceMeta>> RETRY_CLASS_METHOD_ENTRANCE = SnailJobSpiLoader.loadRetrySiteSnapshotContext();
|
||||
private static final RetrySiteSnapshotContext<Deque<MethodEntranceMeta>> RETRY_CLASS_METHOD_ENTRANCE = SnailRetrySpiLoader.loadRetrySiteSnapshotContext();
|
||||
|
||||
/**
|
||||
* 重试状态
|
||||
*/
|
||||
private static final RetrySiteSnapshotContext<Integer> RETRY_STATUS = SnailJobSpiLoader.loadRetrySiteSnapshotContext();
|
||||
private static final RetrySiteSnapshotContext<Integer> RETRY_STATUS = SnailRetrySpiLoader.loadRetrySiteSnapshotContext();
|
||||
|
||||
/**
|
||||
* 重试请求头
|
||||
*/
|
||||
private static final RetrySiteSnapshotContext<SnailJobHeaders> RETRY_HEADER = SnailJobSpiLoader.loadRetrySiteSnapshotContext();
|
||||
private static final RetrySiteSnapshotContext<SnailJobHeaders> RETRY_HEADER = SnailRetrySpiLoader.loadRetrySiteSnapshotContext();
|
||||
|
||||
/**
|
||||
* 状态码
|
||||
*/
|
||||
private static final RetrySiteSnapshotContext<String> RETRY_STATUS_CODE = SnailJobSpiLoader.loadRetrySiteSnapshotContext();
|
||||
private static final RetrySiteSnapshotContext<String> RETRY_STATUS_CODE = SnailRetrySpiLoader.loadRetrySiteSnapshotContext();
|
||||
|
||||
/**
|
||||
* 进入方法入口时间标记
|
||||
*/
|
||||
private static final RetrySiteSnapshotContext<Long> ENTRY_METHOD_TIME = SnailJobSpiLoader.loadRetrySiteSnapshotContext();
|
||||
private static final RetrySiteSnapshotContext<Integer> ATTEMPT_NUMBER = SnailJobSpiLoader.loadRetrySiteSnapshotContext();
|
||||
private static final RetrySiteSnapshotContext<Long> ENTRY_METHOD_TIME = SnailRetrySpiLoader.loadRetrySiteSnapshotContext();
|
||||
private static final RetrySiteSnapshotContext<Integer> ATTEMPT_NUMBER = SnailRetrySpiLoader.loadRetrySiteSnapshotContext();
|
||||
|
||||
public static Integer getAttemptNumber() {
|
||||
return ATTEMPT_NUMBER.get();
|
||||
@ -256,7 +256,7 @@ public class RetrySiteSnapshot {
|
||||
}
|
||||
}
|
||||
|
||||
throw new SnailJobClientException("unsupported stage");
|
||||
throw new SnailRetryClientException("unsupported stage");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
package com.aizuda.snailjob.client.core.intercepter;
|
||||
|
||||
import com.aizuda.snailjob.client.core.intercepter.RetrySiteSnapshot.EnumStage;
|
||||
import com.aizuda.snailjob.common.core.constant.SystemConstants;
|
||||
import com.aizuda.snailjob.common.log.SnailJobLog;
|
||||
import com.aizuda.snailjob.common.core.model.SnailJobHeaders;
|
||||
@ -26,7 +25,7 @@ import java.util.Objects;
|
||||
@Aspect
|
||||
@Component
|
||||
@Slf4j
|
||||
public class HeaderAspect {
|
||||
public class SnailRetryHeaderAspect {
|
||||
|
||||
public void before() {
|
||||
if (skip()) {
|
||||
@ -86,7 +85,7 @@ public class HeaderAspect {
|
||||
return;
|
||||
}
|
||||
|
||||
// 服务端重试的在com.aizuda.snailjob.client.core.client.RetryEndPoint.dispatch 中进行清除threadLocal
|
||||
// 服务端重试的在com.aizuda.snailjob.client.core.client.SnailRetryEndPoint.dispatch 中进行清除threadLocal
|
||||
if (Objects.nonNull(RetrySiteSnapshot.getStage()) && RetrySiteSnapshot.EnumStage.REMOTE.getStage() == RetrySiteSnapshot.getStage()) {
|
||||
return;
|
||||
}
|
@ -7,7 +7,6 @@ import com.aizuda.snailjob.client.core.annotation.Propagation;
|
||||
import com.aizuda.snailjob.client.core.annotation.Retryable;
|
||||
import com.aizuda.snailjob.client.common.cache.GroupVersionCache;
|
||||
import com.aizuda.snailjob.client.core.cache.RetryerInfoCache;
|
||||
import com.aizuda.snailjob.client.core.intercepter.RetrySiteSnapshot.EnumStage;
|
||||
import com.aizuda.snailjob.client.core.retryer.RetryerInfo;
|
||||
import com.aizuda.snailjob.client.core.retryer.RetryerResultContext;
|
||||
import com.aizuda.snailjob.client.core.strategy.RetryStrategy;
|
||||
@ -45,7 +44,7 @@ import java.util.UUID;
|
||||
* @date 2023-08-23
|
||||
*/
|
||||
@Slf4j
|
||||
public class SnailJobInterceptor implements MethodInterceptor, AfterAdvice, Serializable, Ordered {
|
||||
public class SnailRetryInterceptor implements MethodInterceptor, AfterAdvice, Serializable, Ordered {
|
||||
|
||||
private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
private static String retryErrorMoreThresholdTextMessageFormatter =
|
||||
@ -59,7 +58,7 @@ public class SnailJobInterceptor implements MethodInterceptor, AfterAdvice, Seri
|
||||
private final StandardEnvironment standardEnvironment;
|
||||
private final RetryStrategy retryStrategy;
|
||||
|
||||
public SnailJobInterceptor(StandardEnvironment standardEnvironment,
|
||||
public SnailRetryInterceptor(StandardEnvironment standardEnvironment,
|
||||
RetryStrategy localRetryStrategies) {
|
||||
this.standardEnvironment = standardEnvironment;
|
||||
this.retryStrategy = localRetryStrategies;
|
@ -29,13 +29,13 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
||||
*/
|
||||
//@Configuration
|
||||
@Slf4j
|
||||
public class SnailJobPointcutAdvisor extends AbstractPointcutAdvisor implements IntroductionAdvisor, BeanFactoryAware, InitializingBean {
|
||||
public class SnailRetryPointcutAdvisor extends AbstractPointcutAdvisor implements IntroductionAdvisor, BeanFactoryAware, InitializingBean {
|
||||
private Advice advice;
|
||||
private Pointcut pointcut;
|
||||
private BeanFactory beanFactory;
|
||||
private MethodInterceptor snailJobInterceptor;
|
||||
|
||||
public SnailJobPointcutAdvisor(MethodInterceptor methodInterceptor) {
|
||||
public SnailRetryPointcutAdvisor(MethodInterceptor methodInterceptor) {
|
||||
this.snailJobInterceptor = methodInterceptor;
|
||||
}
|
||||
|
||||
@ -77,7 +77,7 @@ public class SnailJobPointcutAdvisor extends AbstractPointcutAdvisor implements
|
||||
}
|
||||
|
||||
protected Pointcut buildPointcut() {
|
||||
return new SnailJobAnnotationMethodPointcut(Retryable.class);
|
||||
return new SnailRetryAnnotationMethodPointcut(Retryable.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -85,13 +85,13 @@ public class SnailJobPointcutAdvisor extends AbstractPointcutAdvisor implements
|
||||
return pointcut;
|
||||
}
|
||||
|
||||
private static final class SnailJobAnnotationMethodPointcut extends StaticMethodMatcherPointcut {
|
||||
private static final class SnailRetryAnnotationMethodPointcut extends StaticMethodMatcherPointcut {
|
||||
|
||||
private final MethodMatcher methodResolver;
|
||||
|
||||
SnailJobAnnotationMethodPointcut(Class<? extends Annotation> annotationType) {
|
||||
SnailRetryAnnotationMethodPointcut(Class<? extends Annotation> annotationType) {
|
||||
this.methodResolver = new AnnotationMethodMatcher(annotationType, true);
|
||||
setClassFilter(new SnailJobAnnotationClassOrMethodFilter(annotationType));
|
||||
setClassFilter(new SnailRetryAnnotationClassOrMethodFilter(annotationType));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -104,20 +104,20 @@ public class SnailJobPointcutAdvisor extends AbstractPointcutAdvisor implements
|
||||
if (this == other) {
|
||||
return true;
|
||||
}
|
||||
if (!(other instanceof SnailJobAnnotationMethodPointcut)) {
|
||||
if (!(other instanceof SnailRetryAnnotationMethodPointcut)) {
|
||||
return false;
|
||||
}
|
||||
SnailJobAnnotationMethodPointcut otherAdvisor = (SnailJobAnnotationMethodPointcut) other;
|
||||
SnailRetryAnnotationMethodPointcut otherAdvisor = (SnailRetryAnnotationMethodPointcut) other;
|
||||
return ObjectUtils.nullSafeEquals(this.methodResolver, otherAdvisor.methodResolver);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static final class SnailJobAnnotationClassOrMethodFilter extends AnnotationClassFilter {
|
||||
private static final class SnailRetryAnnotationClassOrMethodFilter extends AnnotationClassFilter {
|
||||
|
||||
private final AnnotationMethodsResolver methodResolver;
|
||||
|
||||
SnailJobAnnotationClassOrMethodFilter(Class<? extends Annotation> annotationType) {
|
||||
SnailRetryAnnotationClassOrMethodFilter(Class<? extends Annotation> annotationType) {
|
||||
super(annotationType, true);
|
||||
this.methodResolver = new AnnotationMethodsResolver(annotationType);
|
||||
}
|
@ -2,7 +2,7 @@ package com.aizuda.snailjob.client.core.intercepter;
|
||||
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import com.aizuda.snailjob.client.core.RetrySiteSnapshotContext;
|
||||
import com.aizuda.snailjob.client.core.exception.SnailJobClientException;
|
||||
import com.aizuda.snailjob.client.core.exception.SnailRetryClientException;
|
||||
|
||||
/**
|
||||
* ThreadLocal实现类
|
||||
@ -16,7 +16,7 @@ public class ThreadLockRetrySiteSnapshotContext<T> implements RetrySiteSnapshotC
|
||||
private final ThreadLocal<T> threadLocal;
|
||||
|
||||
public ThreadLockRetrySiteSnapshotContext(ThreadLocal<T> threadLocal) {
|
||||
Assert.notNull(threadLocal, ()-> new SnailJobClientException("thread local can not be null"));
|
||||
Assert.notNull(threadLocal, ()-> new SnailRetryClientException("thread local can not be null"));
|
||||
this.threadLocal = threadLocal;
|
||||
}
|
||||
|
||||
|
@ -5,17 +5,12 @@ import com.aizuda.snailjob.client.core.expression.ExpressionInvocationHandler;
|
||||
import com.aizuda.snailjob.common.core.expression.ExpressionEngine;
|
||||
import com.aizuda.snailjob.client.core.RetryArgSerializer;
|
||||
import com.aizuda.snailjob.client.core.event.SnailJobListener;
|
||||
import com.aizuda.snailjob.client.core.event.SimpleSnailJobListener;
|
||||
import com.aizuda.snailjob.client.core.event.SimpleSnailRetryListener;
|
||||
import com.aizuda.snailjob.client.core.RetrySiteSnapshotContext;
|
||||
import com.aizuda.snailjob.common.core.expression.ExpressionFactory;
|
||||
import com.aizuda.snailjob.common.core.expression.strategy.SpELExpressionEngine;
|
||||
import com.aizuda.snailjob.client.core.intercepter.ThreadLockRetrySiteSnapshotContext;
|
||||
import com.aizuda.snailjob.client.core.serializer.JacksonSerializer;
|
||||
import com.aizuda.snailjob.client.core.event.SimpleSnailJobListener;
|
||||
import com.aizuda.snailjob.client.core.event.SnailJobListener;
|
||||
import com.aizuda.snailjob.client.core.expression.ExpressionInvocationHandler;
|
||||
import com.aizuda.snailjob.client.core.intercepter.ThreadLockRetrySiteSnapshotContext;
|
||||
import com.aizuda.snailjob.client.core.serializer.JacksonSerializer;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.util.Collections;
|
||||
@ -29,9 +24,9 @@ import java.util.Optional;
|
||||
* @date : 2023-08-07 18:05
|
||||
* @since 2.2.0
|
||||
*/
|
||||
public class SnailJobSpiLoader {
|
||||
public class SnailRetrySpiLoader {
|
||||
|
||||
private SnailJobSpiLoader() {}
|
||||
private SnailRetrySpiLoader() {}
|
||||
|
||||
/**
|
||||
* 加载参数序列化SPI类
|
||||
@ -47,12 +42,12 @@ public class SnailJobSpiLoader {
|
||||
* 加载重试监听器SPI类
|
||||
* 执行顺序按照文件中定义的实现类的先后顺序
|
||||
*
|
||||
* @return {@link SimpleSnailJobListener} 默认序列化类为SimpleSnailJobListener
|
||||
* @return {@link SimpleSnailRetryListener} 默认序列化类为SimpleSnailJobListener
|
||||
*/
|
||||
public static List<SnailJobListener> loadSnailJobListener() {
|
||||
List<SnailJobListener> snailJobListeners = ServiceLoaderUtil.loadList(SnailJobListener.class);
|
||||
if (CollectionUtils.isEmpty(snailJobListeners)) {
|
||||
return Collections.singletonList(new SimpleSnailJobListener());
|
||||
return Collections.singletonList(new SimpleSnailRetryListener());
|
||||
}
|
||||
|
||||
return snailJobListeners;
|
@ -1,13 +1,11 @@
|
||||
package com.aizuda.snailjob.client.core.plugin;
|
||||
|
||||
import com.aizuda.snailjob.client.core.exception.SnailJobClientException;
|
||||
import com.aizuda.snailjob.client.core.exception.SnailRetryClientException;
|
||||
import com.aizuda.snailjob.client.core.intercepter.RetrySiteSnapshot;
|
||||
import com.aizuda.snailjob.common.core.constant.SystemConstants;
|
||||
import com.aizuda.snailjob.common.log.SnailJobLog;
|
||||
import com.aizuda.snailjob.common.core.model.SnailJobHeaders;
|
||||
import com.aizuda.snailjob.common.core.util.JsonUtil;
|
||||
import com.aizuda.snailjob.client.core.exception.SnailJobClientException;
|
||||
import com.aizuda.snailjob.client.core.intercepter.RetrySiteSnapshot;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.util.HashMap;
|
||||
@ -48,7 +46,7 @@ public class RequestHeaderPlugins {
|
||||
// 重新刷新进入时间
|
||||
RetrySiteSnapshot.setEntryMethodTime(System.currentTimeMillis());
|
||||
} else {
|
||||
throw new SnailJobClientException("调用链超时, 不在继续调用后面请求");
|
||||
throw new SnailRetryClientException("调用链超时, 不在继续调用后面请求");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3,9 +3,7 @@ package com.aizuda.snailjob.client.core.register;
|
||||
import com.aizuda.snailjob.client.common.Lifecycle;
|
||||
import com.aizuda.snailjob.client.core.Scanner;
|
||||
import com.aizuda.snailjob.client.core.cache.RetryerInfoCache;
|
||||
import com.aizuda.snailjob.client.core.exception.SnailJobClientException;
|
||||
import com.aizuda.snailjob.client.core.retryer.RetryerInfo;
|
||||
import com.aizuda.snailjob.client.core.exception.SnailJobClientException;
|
||||
import com.aizuda.snailjob.client.core.exception.SnailRetryClientException;
|
||||
import com.aizuda.snailjob.client.core.retryer.RetryerInfo;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
@ -26,7 +24,7 @@ public class RetryableRegistrar implements Lifecycle {
|
||||
public void registerRetryHandler(RetryerInfo retryerInfo) {
|
||||
|
||||
if (Objects.nonNull(RetryerInfoCache.get(retryerInfo.getScene(), retryerInfo.getExecutorClassName()))) {
|
||||
throw new SnailJobClientException("类:[{}]中已经存在场景:[{}]", retryerInfo.getExecutorClassName(), retryerInfo.getScene());
|
||||
throw new SnailRetryClientException("类:[{}]中已经存在场景:[{}]", retryerInfo.getExecutorClassName(), retryerInfo.getScene());
|
||||
}
|
||||
|
||||
RetryerInfoCache.put(retryerInfo);
|
||||
|
@ -3,19 +3,17 @@ package com.aizuda.snailjob.client.core.report;
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import com.aizuda.snailjob.client.core.Report;
|
||||
import com.aizuda.snailjob.client.common.config.SnailJobProperties;
|
||||
import com.aizuda.snailjob.client.core.exception.SnailJobClientException;
|
||||
import com.aizuda.snailjob.client.core.exception.SnailRetryClientException;
|
||||
import com.aizuda.snailjob.common.core.expression.ExpressionEngine;
|
||||
import com.aizuda.snailjob.client.core.IdempotentIdGenerate;
|
||||
import com.aizuda.snailjob.client.core.RetryArgSerializer;
|
||||
import com.aizuda.snailjob.client.core.cache.RetryerInfoCache;
|
||||
import com.aizuda.snailjob.client.core.intercepter.RetrySiteSnapshot;
|
||||
import com.aizuda.snailjob.client.core.loader.SnailJobSpiLoader;
|
||||
import com.aizuda.snailjob.client.core.loader.SnailRetrySpiLoader;
|
||||
import com.aizuda.snailjob.client.core.retryer.RetryerInfo;
|
||||
import com.aizuda.snailjob.common.log.SnailJobLog;
|
||||
import com.aizuda.snailjob.common.core.model.IdempotentIdContext;
|
||||
import com.aizuda.snailjob.server.model.dto.RetryTaskDTO;
|
||||
import com.aizuda.snailjob.client.core.exception.SnailJobClientException;
|
||||
import com.aizuda.snailjob.client.core.intercepter.RetrySiteSnapshot;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
|
||||
@ -34,7 +32,7 @@ public abstract class AbstractReport implements Report {
|
||||
@Override
|
||||
public boolean report(String scene, final String targetClassName, final Object[] params) {
|
||||
RetryerInfo retryerInfo = RetryerInfoCache.get(scene, targetClassName);
|
||||
Assert.notNull(retryerInfo, () -> new SnailJobClientException("retryerInfo is null"));
|
||||
Assert.notNull(retryerInfo, () -> new SnailRetryClientException("retryerInfo is null"));
|
||||
|
||||
if (RetrySiteSnapshot.getStage().equals(RetrySiteSnapshot.EnumStage.REMOTE.getStage()) && !retryerInfo.isForceReport()) {
|
||||
SnailJobLog.LOCAL.info("Successfully reported, no need to repeat reporting. scene:[{}] targetClassName:[{}] args:[{}]",
|
||||
@ -69,10 +67,10 @@ public abstract class AbstractReport implements Report {
|
||||
idempotentId = (String) ReflectionUtils.invokeMethod(method, generate, idempotentIdContext);
|
||||
} catch (Exception exception) {
|
||||
SnailJobLog.LOCAL.error("幂等id生成异常:{},{}", scene, args, exception);
|
||||
throw new SnailJobClientException("idempotentId生成异常:{},{}", scene, args);
|
||||
throw new SnailRetryClientException("idempotentId生成异常:{},{}", scene, args);
|
||||
}
|
||||
|
||||
RetryArgSerializer retryArgSerializer = SnailJobSpiLoader.loadRetryArgSerializer();
|
||||
RetryArgSerializer retryArgSerializer = SnailRetrySpiLoader.loadRetryArgSerializer();
|
||||
|
||||
String serialize = retryArgSerializer.serialize(args);
|
||||
retryTaskDTO.setIdempotentId(idempotentId);
|
||||
@ -82,7 +80,7 @@ public abstract class AbstractReport implements Report {
|
||||
retryTaskDTO.setSceneName(scene);
|
||||
|
||||
String expression = retryerInfo.getBizNo();
|
||||
ExpressionEngine expressionEngine = SnailJobSpiLoader.loadExpressionEngine();
|
||||
ExpressionEngine expressionEngine = SnailRetrySpiLoader.loadExpressionEngine();
|
||||
retryTaskDTO.setBizNo((String) expressionEngine.eval(expression, args, executorMethod));
|
||||
return retryTaskDTO;
|
||||
}
|
||||
|
@ -8,8 +8,7 @@ import com.aizuda.snailjob.client.core.RetryExecutorParameter;
|
||||
import com.aizuda.snailjob.client.core.event.SnailJobListener;
|
||||
import com.aizuda.snailjob.client.core.executor.GuavaRetryExecutor;
|
||||
import com.aizuda.snailjob.client.core.intercepter.RetrySiteSnapshot;
|
||||
import com.aizuda.snailjob.client.core.intercepter.RetrySiteSnapshot.EnumStatus;
|
||||
import com.aizuda.snailjob.client.core.loader.SnailJobSpiLoader;
|
||||
import com.aizuda.snailjob.client.core.loader.SnailRetrySpiLoader;
|
||||
import com.aizuda.snailjob.client.core.retryer.RetryerInfo;
|
||||
import com.aizuda.snailjob.client.core.retryer.RetryerResultContext;
|
||||
import com.aizuda.snailjob.common.core.alarm.Alarm;
|
||||
@ -20,10 +19,6 @@ import com.aizuda.snailjob.common.log.SnailJobLog;
|
||||
import com.aizuda.snailjob.common.core.util.EnvironmentUtils;
|
||||
import com.aizuda.snailjob.common.core.util.NetUtil;
|
||||
import com.aizuda.snailjob.server.model.dto.ConfigDTO;
|
||||
import com.aizuda.snailjob.client.core.executor.GuavaRetryExecutor;
|
||||
import com.aizuda.snailjob.client.core.intercepter.RetrySiteSnapshot;
|
||||
import com.aizuda.snailjob.client.core.retryer.RetryerInfo;
|
||||
import com.aizuda.snailjob.client.core.retryer.RetryerResultContext;
|
||||
import com.github.rholder.retry.Retryer;
|
||||
import com.github.rholder.retry.StopStrategy;
|
||||
import com.github.rholder.retry.WaitStrategy;
|
||||
@ -53,7 +48,7 @@ public abstract class AbstractRetryStrategies implements RetryStrategy {
|
||||
"> 异常:{} \n"
|
||||
;
|
||||
|
||||
private final List<SnailJobListener> snailJobListeners = SnailJobSpiLoader.loadSnailJobListener();
|
||||
private final List<SnailJobListener> snailJobListeners = SnailRetrySpiLoader.loadSnailJobListener();
|
||||
|
||||
@Autowired
|
||||
private SnailJobAlarmFactory snailJobAlarmFactory;
|
||||
|
@ -2,14 +2,13 @@ package com.aizuda.snailjob.client.core.strategy;
|
||||
|
||||
import com.aizuda.snailjob.client.core.RetryExecutor;
|
||||
import com.aizuda.snailjob.client.core.RetryExecutorParameter;
|
||||
import com.aizuda.snailjob.client.core.exception.SnailJobClientException;
|
||||
import com.aizuda.snailjob.client.core.exception.SnailRetryClientException;
|
||||
import com.aizuda.snailjob.client.core.intercepter.RetrySiteSnapshot;
|
||||
import com.aizuda.snailjob.client.core.retryer.RetryType;
|
||||
import com.aizuda.snailjob.client.core.retryer.RetryerInfo;
|
||||
import com.aizuda.snailjob.client.core.retryer.RetryerResultContext;
|
||||
import com.aizuda.snailjob.common.core.enums.RetryResultStatusEnum;
|
||||
import com.aizuda.snailjob.common.log.SnailJobLog;
|
||||
import com.aizuda.snailjob.client.core.intercepter.RetrySiteSnapshot;
|
||||
import com.github.rholder.retry.Attempt;
|
||||
import com.github.rholder.retry.RetryListener;
|
||||
import com.github.rholder.retry.StopStrategies;
|
||||
@ -128,7 +127,7 @@ public class LocalRetryStrategies extends AbstractRetryStrategies {
|
||||
RetrySiteSnapshot.setStage(RetrySiteSnapshot.EnumStage.REMOTE.getStage());
|
||||
return () -> null;
|
||||
default:
|
||||
throw new SnailJobClientException("异常重试模式 [{}]", retryType.name());
|
||||
throw new SnailRetryClientException("异常重试模式 [{}]", retryType.name());
|
||||
}
|
||||
|
||||
}
|
||||
@ -164,7 +163,7 @@ public class LocalRetryStrategies extends AbstractRetryStrategies {
|
||||
SnailJobLog.LOCAL.error("[{}] 上报服务端执行失败,第[{}]次重试", retryerInfo.getScene(), attempt.getAttemptNumber());
|
||||
break;
|
||||
default:
|
||||
throw new SnailJobClientException("异常重试模式 [{}]", retryType.name());
|
||||
throw new SnailRetryClientException("异常重试模式 [{}]", retryType.name());
|
||||
|
||||
}
|
||||
} else {
|
||||
@ -178,7 +177,7 @@ public class LocalRetryStrategies extends AbstractRetryStrategies {
|
||||
SnailJobLog.LOCAL.info("[{}] 上报服务端执行成功.", retryerInfo.getScene());
|
||||
break;
|
||||
default:
|
||||
throw new SnailJobClientException("异常重试模式 [{}]", retryType.name());
|
||||
throw new SnailRetryClientException("异常重试模式 [{}]", retryType.name());
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user