diff --git a/easy-retry-client/easy-retry-client-common/src/main/java/com/aizuda/easy/retry/client/common/EasyRetryLogContext.java b/easy-retry-client/easy-retry-client-common/src/main/java/com/aizuda/easy/retry/client/common/EasyRetryLogContext.java new file mode 100644 index 000000000..72c9342c5 --- /dev/null +++ b/easy-retry-client/easy-retry-client-common/src/main/java/com/aizuda/easy/retry/client/common/EasyRetryLogContext.java @@ -0,0 +1,16 @@ +package com.aizuda.easy.retry.client.common; + +/** + * @author: xiaowoniu + * @date : 2024-03-22 + * @since :3.2.0 + */ +public interface EasyRetryLogContext { + + void set(T value); + + void remove(); + + T get(); + +} diff --git a/easy-retry-client/easy-retry-client-common/src/main/java/com/aizuda/easy/retry/client/common/report/LogReport.java b/easy-retry-client/easy-retry-client-common/src/main/java/com/aizuda/easy/retry/client/common/LogReport.java similarity index 82% rename from easy-retry-client/easy-retry-client-common/src/main/java/com/aizuda/easy/retry/client/common/report/LogReport.java rename to easy-retry-client/easy-retry-client-common/src/main/java/com/aizuda/easy/retry/client/common/LogReport.java index 4da6aa5d4..f9dfcffb4 100644 --- a/easy-retry-client/easy-retry-client-common/src/main/java/com/aizuda/easy/retry/client/common/report/LogReport.java +++ b/easy-retry-client/easy-retry-client-common/src/main/java/com/aizuda/easy/retry/client/common/LogReport.java @@ -1,4 +1,4 @@ -package com.aizuda.easy.retry.client.common.report; +package com.aizuda.easy.retry.client.common; import com.aizuda.easy.retry.common.log.dto.LogContentDTO; diff --git a/easy-retry-client/easy-retry-client-common/src/main/java/com/aizuda/easy/retry/client/common/appender/EasyRetryLog4j2Appender.java b/easy-retry-client/easy-retry-client-common/src/main/java/com/aizuda/easy/retry/client/common/appender/EasyRetryLog4j2Appender.java index 4ffd48dc1..14992e0bb 100644 --- a/easy-retry-client/easy-retry-client-common/src/main/java/com/aizuda/easy/retry/client/common/appender/EasyRetryLog4j2Appender.java +++ b/easy-retry-client/easy-retry-client-common/src/main/java/com/aizuda/easy/retry/client/common/appender/EasyRetryLog4j2Appender.java @@ -1,11 +1,9 @@ package com.aizuda.easy.retry.client.common.appender; -import com.aizuda.easy.retry.client.common.report.AsyncReportLog; -import com.aizuda.easy.retry.client.common.report.LogReportFactory; -import com.aizuda.easy.retry.client.common.util.ThreadLocalLogUtil; +import com.aizuda.easy.retry.client.common.log.report.LogReportFactory; +import com.aizuda.easy.retry.client.common.log.support.EasyRetryLogManager; import com.aizuda.easy.retry.common.log.dto.LogContentDTO; import com.aizuda.easy.retry.common.log.constant.LogFieldConstants; -import com.aizuda.easy.retry.common.core.context.SpringContext; import org.apache.log4j.MDC; import org.apache.logging.log4j.core.Filter; import org.apache.logging.log4j.core.Layout; @@ -34,7 +32,7 @@ public class EasyRetryLog4j2Appender extends AbstractAppender { public void append(LogEvent event) { // Not job context - if (Objects.isNull(ThreadLocalLogUtil.getContext()) || Objects.isNull(MDC.get(LogFieldConstants.MDC_REMOTE))) { + if (Objects.isNull(EasyRetryLogManager.getLogMeta()) || Objects.isNull(MDC.get(LogFieldConstants.MDC_REMOTE))) { return; } diff --git a/easy-retry-client/easy-retry-client-common/src/main/java/com/aizuda/easy/retry/client/common/appender/EasyRetryLog4jAppender.java b/easy-retry-client/easy-retry-client-common/src/main/java/com/aizuda/easy/retry/client/common/appender/EasyRetryLog4jAppender.java index 8988c3561..2f8b504eb 100644 --- a/easy-retry-client/easy-retry-client-common/src/main/java/com/aizuda/easy/retry/client/common/appender/EasyRetryLog4jAppender.java +++ b/easy-retry-client/easy-retry-client-common/src/main/java/com/aizuda/easy/retry/client/common/appender/EasyRetryLog4jAppender.java @@ -1,11 +1,9 @@ package com.aizuda.easy.retry.client.common.appender; -import com.aizuda.easy.retry.client.common.report.AsyncReportLog; -import com.aizuda.easy.retry.client.common.report.LogReportFactory; -import com.aizuda.easy.retry.client.common.util.ThreadLocalLogUtil; +import com.aizuda.easy.retry.client.common.log.report.LogReportFactory; +import com.aizuda.easy.retry.client.common.log.support.EasyRetryLogManager; import com.aizuda.easy.retry.common.log.dto.LogContentDTO; import com.aizuda.easy.retry.common.log.constant.LogFieldConstants; -import com.aizuda.easy.retry.common.core.context.SpringContext; import org.apache.log4j.AppenderSkeleton; import org.apache.log4j.MDC; import org.apache.log4j.spi.LoggingEvent; @@ -30,7 +28,7 @@ public class EasyRetryLog4jAppender extends AppenderSkeleton { protected void append(LoggingEvent event) { // Not job context - if (Objects.isNull(ThreadLocalLogUtil.getContext()) || Objects.isNull(MDC.get(LogFieldConstants.MDC_REMOTE))) { + if (Objects.isNull(EasyRetryLogManager.getLogMeta()) || Objects.isNull(MDC.get(LogFieldConstants.MDC_REMOTE))) { return; } diff --git a/easy-retry-client/easy-retry-client-common/src/main/java/com/aizuda/easy/retry/client/common/appender/EasyRetryLogbackAppender.java b/easy-retry-client/easy-retry-client-common/src/main/java/com/aizuda/easy/retry/client/common/appender/EasyRetryLogbackAppender.java index bb7b5e80c..35ac3e670 100644 --- a/easy-retry-client/easy-retry-client-common/src/main/java/com/aizuda/easy/retry/client/common/appender/EasyRetryLogbackAppender.java +++ b/easy-retry-client/easy-retry-client-common/src/main/java/com/aizuda/easy/retry/client/common/appender/EasyRetryLogbackAppender.java @@ -6,12 +6,10 @@ import ch.qos.logback.classic.spi.StackTraceElementProxy; import ch.qos.logback.classic.spi.ThrowableProxyUtil; import ch.qos.logback.core.CoreConstants; import ch.qos.logback.core.UnsynchronizedAppenderBase; -import com.aizuda.easy.retry.client.common.report.AsyncReportLog; -import com.aizuda.easy.retry.client.common.report.LogReportFactory; -import com.aizuda.easy.retry.client.common.util.ThreadLocalLogUtil; +import com.aizuda.easy.retry.client.common.log.report.LogReportFactory; +import com.aizuda.easy.retry.client.common.log.support.EasyRetryLogManager; import com.aizuda.easy.retry.common.log.dto.LogContentDTO; import com.aizuda.easy.retry.common.log.constant.LogFieldConstants; -import com.aizuda.easy.retry.common.core.context.SpringContext; import org.slf4j.MDC; import java.util.Objects; @@ -34,7 +32,7 @@ public class EasyRetryLogbackAppender extends UnsynchronizedAppenderBase { // Not job context if (!(eventObject instanceof LoggingEvent) - || Objects.isNull(ThreadLocalLogUtil.getContext()) + || Objects.isNull(EasyRetryLogManager.getLogMeta()) || Objects.isNull(MDC.get(LogFieldConstants.MDC_REMOTE))) { return; } diff --git a/easy-retry-client/easy-retry-client-common/src/main/java/com/aizuda/easy/retry/client/common/log/context/ThreadLocalLogContext.java b/easy-retry-client/easy-retry-client-common/src/main/java/com/aizuda/easy/retry/client/common/log/context/ThreadLocalLogContext.java new file mode 100644 index 000000000..c8a2d0f96 --- /dev/null +++ b/easy-retry-client/easy-retry-client-common/src/main/java/com/aizuda/easy/retry/client/common/log/context/ThreadLocalLogContext.java @@ -0,0 +1,37 @@ +package com.aizuda.easy.retry.client.common.log.context; + +import cn.hutool.core.lang.Assert; +import com.aizuda.easy.retry.client.common.EasyRetryLogContext; +import com.aizuda.easy.retry.client.common.exception.EasyRetryClientException; + +/** + * ThreadLocal实现类 + * + * @author: xiaowoniu + * @date : 2023-08-09 16:34 + * @since 3.2.0 + */ +public class ThreadLocalLogContext implements EasyRetryLogContext { + + private final ThreadLocal threadLocal; + + public ThreadLocalLogContext(ThreadLocal threadLocal) { + Assert.notNull(threadLocal, ()-> new EasyRetryClientException("thread local can not be null")); + this.threadLocal = threadLocal; + } + + @Override + public void set(T value) { + threadLocal.set(value); + } + + @Override + public void remove() { + threadLocal.remove(); + } + + @Override + public T get() { + return threadLocal.get(); + } +} diff --git a/easy-retry-client/easy-retry-client-common/src/main/java/com/aizuda/easy/retry/client/common/report/AbstractLogReport.java b/easy-retry-client/easy-retry-client-common/src/main/java/com/aizuda/easy/retry/client/common/log/report/AbstractLogReport.java similarity index 95% rename from easy-retry-client/easy-retry-client-common/src/main/java/com/aizuda/easy/retry/client/common/report/AbstractLogReport.java rename to easy-retry-client/easy-retry-client-common/src/main/java/com/aizuda/easy/retry/client/common/log/report/AbstractLogReport.java index 9e4069047..79cf368dd 100644 --- a/easy-retry-client/easy-retry-client-common/src/main/java/com/aizuda/easy/retry/client/common/report/AbstractLogReport.java +++ b/easy-retry-client/easy-retry-client-common/src/main/java/com/aizuda/easy/retry/client/common/log/report/AbstractLogReport.java @@ -1,6 +1,7 @@ -package com.aizuda.easy.retry.client.common.report; +package com.aizuda.easy.retry.client.common.log.report; import com.aizuda.easy.retry.client.common.Lifecycle; +import com.aizuda.easy.retry.client.common.LogReport; import com.aizuda.easy.retry.client.common.config.EasyRetryProperties; import com.aizuda.easy.retry.client.common.window.SlidingWindow; import com.aizuda.easy.retry.common.core.window.Listener; diff --git a/easy-retry-client/easy-retry-client-common/src/main/java/com/aizuda/easy/retry/client/common/report/LogMeta.java b/easy-retry-client/easy-retry-client-common/src/main/java/com/aizuda/easy/retry/client/common/log/report/LogMeta.java similarity index 81% rename from easy-retry-client/easy-retry-client-common/src/main/java/com/aizuda/easy/retry/client/common/report/LogMeta.java rename to easy-retry-client/easy-retry-client-common/src/main/java/com/aizuda/easy/retry/client/common/log/report/LogMeta.java index a9b6227f8..8921170d2 100644 --- a/easy-retry-client/easy-retry-client-common/src/main/java/com/aizuda/easy/retry/client/common/report/LogMeta.java +++ b/easy-retry-client/easy-retry-client-common/src/main/java/com/aizuda/easy/retry/client/common/log/report/LogMeta.java @@ -1,4 +1,4 @@ -package com.aizuda.easy.retry.client.common.report; +package com.aizuda.easy.retry.client.common.log.report; import lombok.Data; diff --git a/easy-retry-client/easy-retry-client-common/src/main/java/com/aizuda/easy/retry/client/common/report/LogReportFactory.java b/easy-retry-client/easy-retry-client-common/src/main/java/com/aizuda/easy/retry/client/common/log/report/LogReportFactory.java similarity index 50% rename from easy-retry-client/easy-retry-client-common/src/main/java/com/aizuda/easy/retry/client/common/report/LogReportFactory.java rename to easy-retry-client/easy-retry-client-common/src/main/java/com/aizuda/easy/retry/client/common/log/report/LogReportFactory.java index 01ca05db7..f01ebf603 100644 --- a/easy-retry-client/easy-retry-client-common/src/main/java/com/aizuda/easy/retry/client/common/report/LogReportFactory.java +++ b/easy-retry-client/easy-retry-client-common/src/main/java/com/aizuda/easy/retry/client/common/log/report/LogReportFactory.java @@ -1,5 +1,6 @@ -package com.aizuda.easy.retry.client.common.report; +package com.aizuda.easy.retry.client.common.log.report; +import com.aizuda.easy.retry.client.common.LogReport; import com.google.common.collect.Lists; import java.util.List; @@ -11,15 +12,17 @@ import java.util.List; */ public final class LogReportFactory { - private static final List reports = Lists.newArrayList(); + private static final List REPORTS = Lists.newArrayList(); + private LogReportFactory() { + } - static void add(LogReport logReport) { - reports.add(logReport); + static void add(LogReport logReport) { + REPORTS.add(logReport); } public static LogReport get() { - for (final LogReport report : reports) { + for (final LogReport report : REPORTS) { if (report.supports()) { return report; } diff --git a/easy-retry-client/easy-retry-client-common/src/main/java/com/aizuda/easy/retry/client/common/report/ReportLogListener.java b/easy-retry-client/easy-retry-client-common/src/main/java/com/aizuda/easy/retry/client/common/log/report/ReportLogListener.java similarity index 94% rename from easy-retry-client/easy-retry-client-common/src/main/java/com/aizuda/easy/retry/client/common/report/ReportLogListener.java rename to easy-retry-client/easy-retry-client-common/src/main/java/com/aizuda/easy/retry/client/common/log/report/ReportLogListener.java index d3ebeb5f6..0bdb6ff7b 100644 --- a/easy-retry-client/easy-retry-client-common/src/main/java/com/aizuda/easy/retry/client/common/report/ReportLogListener.java +++ b/easy-retry-client/easy-retry-client-common/src/main/java/com/aizuda/easy/retry/client/common/log/report/ReportLogListener.java @@ -1,4 +1,4 @@ -package com.aizuda.easy.retry.client.common.report; +package com.aizuda.easy.retry.client.common.log.report; import com.aizuda.easy.retry.client.common.client.NettyClient; import com.aizuda.easy.retry.client.common.proxy.RequestBuilder; diff --git a/easy-retry-client/easy-retry-client-common/src/main/java/com/aizuda/easy/retry/client/common/log/support/EasyRetryLogManager.java b/easy-retry-client/easy-retry-client-common/src/main/java/com/aizuda/easy/retry/client/common/log/support/EasyRetryLogManager.java new file mode 100644 index 000000000..438a3cf71 --- /dev/null +++ b/easy-retry-client/easy-retry-client-common/src/main/java/com/aizuda/easy/retry/client/common/log/support/EasyRetryLogManager.java @@ -0,0 +1,62 @@ +package com.aizuda.easy.retry.client.common.log.support; + +import cn.hutool.core.util.ServiceLoaderUtil; +import com.aizuda.easy.retry.client.common.EasyRetryLogContext; +import com.aizuda.easy.retry.client.common.log.context.ThreadLocalLogContext; +import com.aizuda.easy.retry.client.common.log.report.LogMeta; +import com.aizuda.easy.retry.common.log.enums.LogTypeEnum; + +import java.util.Optional; + +/** + * @author wodeyangzipingpingwuqi· + * @date 2023-12-29 + * @since 1.0.0 + */ +public final class EasyRetryLogManager { + + private static final EasyRetryLogContext LOG_TYPE = easyRetryLogContextLoader(); + private static final EasyRetryLogContext LOG_META = easyRetryLogContextLoader(); + + private static EasyRetryLogContext easyRetryLogContextLoader() { + return Optional.ofNullable(ServiceLoaderUtil.loadFirst(EasyRetryLogContext.class)).orElse(new ThreadLocalLogContext(new ThreadLocal<>())); + } + + private EasyRetryLogManager() { + } + + public static void initLogInfo(LogMeta logMeta, LogTypeEnum logType) { + setLogMeta(logMeta); + setLogType(logType); + } + + public static void setLogMeta(LogMeta logMeta) { + LOG_META.set(logMeta); + } + + public static LogMeta getLogMeta() { + return LOG_META.get(); + } + + public static void removeLogMeta() { + LOG_META.remove(); + } + + public static void removeAll() { + removeLogMeta(); + removeLogType(); + } + + public static void setLogType (LogTypeEnum logType) { + LOG_TYPE.set(logType); + } + + public static LogTypeEnum getLogType () { + return LOG_TYPE.get(); + } + + public static void removeLogType () { + LOG_TYPE.remove(); + } + +} diff --git a/easy-retry-client/easy-retry-client-common/src/main/java/com/aizuda/easy/retry/client/common/report/AsyncReportLog.java b/easy-retry-client/easy-retry-client-common/src/main/java/com/aizuda/easy/retry/client/common/report/AsyncReportLog.java deleted file mode 100644 index bea137905..000000000 --- a/easy-retry-client/easy-retry-client-common/src/main/java/com/aizuda/easy/retry/client/common/report/AsyncReportLog.java +++ /dev/null @@ -1,87 +0,0 @@ -package com.aizuda.easy.retry.client.common.report; - -import com.aizuda.easy.retry.client.common.Lifecycle; -import com.aizuda.easy.retry.client.common.config.EasyRetryProperties; -import com.aizuda.easy.retry.client.common.util.ThreadLocalLogUtil; -import com.aizuda.easy.retry.client.common.window.SlidingWindow; -import com.aizuda.easy.retry.common.log.EasyRetryLog; -import com.aizuda.easy.retry.common.log.dto.LogContentDTO; -import com.aizuda.easy.retry.server.model.dto.LogTaskDTO; -import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -import java.util.Objects; - -/** - * 异步上报日志数据 - * - * @author wodeyangzipingpingwuqi - * @date 2023-12-27 - * @since 2.6.0 - */ -//@Component -@Slf4j -@Deprecated -public class AsyncReportLog implements Lifecycle { - - @Autowired - private EasyRetryProperties easyRetryProperties; - - private SlidingWindow slidingWindow; - - /** - * 异步上报到服务端, 若当前处于远程重试阶段不会进行执行上报 - */ - public Boolean syncReportLog(LogContentDTO logContent) { - -// LogTaskDTO logTaskDTO = buildLogTaskDTO(logContent); -// slidingWindow.add(logTaskDTO); - return Boolean.TRUE; - } - - @Override - public void start() { - - EasyRetryProperties.LogSlidingWindowConfig logSlidingWindow = easyRetryProperties.getLogSlidingWindow(); - - slidingWindow = SlidingWindow - .Builder - .newBuilder() - .withTotalThreshold(logSlidingWindow.getTotalThreshold()) - .withWindowTotalThreshold(logSlidingWindow.getWindowTotalThreshold()) - .withDuration(logSlidingWindow.getDuration(), logSlidingWindow.getChronoUnit()) - .withListener(new ReportLogListener()) - .build(); - - slidingWindow.start(); - } - - @Override - public void close() { - EasyRetryLog.LOCAL.info("AsyncReport Log about to shutdown"); - if (Objects.nonNull(slidingWindow)) { - slidingWindow.end(); - } - EasyRetryLog.LOCAL.info("AsyncReport Log has been shutdown"); - } - -// /** -// * 构建上报任务对象 -// * -// * @return logContent 上报服务端对象 -// */ -// protected LogTaskDTO buildLogTaskDTO(LogContentDTO logContentDTO) { -// LogMeta context = ThreadLocalLogUtil.getContext(); -// -// LogTaskDTO logTaskDTO = new LogTaskDTO(); -// logTaskDTO.setJobId(context.getJobId()); -// logTaskDTO.setTaskId(context.getTaskId()); -// logTaskDTO.setTaskBatchId(context.getTaskBatchId()); -// logTaskDTO.setRealTime(logContentDTO.getTimeStamp()); -// logTaskDTO.setNamespaceId(context.getNamespaceId()); -// logTaskDTO.setGroupName(context.getGroupName()); -// logTaskDTO.setFieldList(logContentDTO.getFieldList()); -// return logTaskDTO; -// } -} diff --git a/easy-retry-client/easy-retry-client-common/src/main/java/com/aizuda/easy/retry/client/common/util/ThreadLocalLogUtil.java b/easy-retry-client/easy-retry-client-common/src/main/java/com/aizuda/easy/retry/client/common/util/ThreadLocalLogUtil.java deleted file mode 100644 index 93a17e706..000000000 --- a/easy-retry-client/easy-retry-client-common/src/main/java/com/aizuda/easy/retry/client/common/util/ThreadLocalLogUtil.java +++ /dev/null @@ -1,51 +0,0 @@ -package com.aizuda.easy.retry.client.common.util; - - -import com.aizuda.easy.retry.client.common.report.LogMeta; -import com.aizuda.easy.retry.common.log.enums.LogTypeEnum; - -/** - * @author wodeyangzipingpingwuqi· - * @date 2023-12-29 - * @since 1.0.0 - */ -public class ThreadLocalLogUtil { - private static final ThreadLocal LOG_TYPE = new ThreadLocal<>(); - private static final ThreadLocal JOB_CONTEXT_LOCAL = new ThreadLocal<>(); - - public static void initLogInfo(LogMeta logMeta, LogTypeEnum logType) { - setContext(logMeta); - setLogType(logType); - } - - public static void setContext(LogMeta logMeta) { - JOB_CONTEXT_LOCAL.set(logMeta); - } - - public static LogMeta getContext() { - return JOB_CONTEXT_LOCAL.get(); - } - - public static void removeContext() { - JOB_CONTEXT_LOCAL.remove(); - } - - public static void removeAll() { - JOB_CONTEXT_LOCAL.remove(); - LOG_TYPE.remove(); - } - - public static void setLogType (LogTypeEnum logType) { - LOG_TYPE.set(logType); - } - - public static LogTypeEnum getLogType () { - return LOG_TYPE.get(); - } - - public static void removeLogType () { - LOG_TYPE.remove(); - } - - -} diff --git a/easy-retry-client/easy-retry-client-common/src/main/java/com/aizuda/easy/retry/client/common/Report.java b/easy-retry-client/easy-retry-client-core/src/main/java/com/aizuda/easy/retry/client/core/Report.java similarity index 83% rename from easy-retry-client/easy-retry-client-common/src/main/java/com/aizuda/easy/retry/client/common/Report.java rename to easy-retry-client/easy-retry-client-core/src/main/java/com/aizuda/easy/retry/client/core/Report.java index b7b0578f2..27377db2b 100644 --- a/easy-retry-client/easy-retry-client-common/src/main/java/com/aizuda/easy/retry/client/common/Report.java +++ b/easy-retry-client/easy-retry-client-core/src/main/java/com/aizuda/easy/retry/client/core/Report.java @@ -1,4 +1,4 @@ -package com.aizuda.easy.retry.client.common; +package com.aizuda.easy.retry.client.core; /** * @author www.byteblogs.com diff --git a/easy-retry-client/easy-retry-client-core/src/main/java/com/aizuda/easy/retry/client/core/client/RetryEndPoint.java b/easy-retry-client/easy-retry-client-core/src/main/java/com/aizuda/easy/retry/client/core/client/RetryEndPoint.java index 05d2956a5..63cf681ca 100644 --- a/easy-retry-client/easy-retry-client-core/src/main/java/com/aizuda/easy/retry/client/core/client/RetryEndPoint.java +++ b/easy-retry-client/easy-retry-client-core/src/main/java/com/aizuda/easy/retry/client/core/client/RetryEndPoint.java @@ -1,7 +1,7 @@ package com.aizuda.easy.retry.client.core.client; import cn.hutool.core.lang.Assert; -import com.aizuda.easy.retry.client.common.util.ThreadLocalLogUtil; +import com.aizuda.easy.retry.client.common.log.support.EasyRetryLogManager; import com.aizuda.easy.retry.client.core.IdempotentIdGenerate; import com.aizuda.easy.retry.client.core.RetryArgSerializer; import com.aizuda.easy.retry.client.common.cache.GroupVersionCache; @@ -92,7 +92,7 @@ public class RetryEndPoint { retryLogMeta.setGroupName(executeReqDto.getGroupName()); retryLogMeta.setNamespaceId(executeReqDto.getNamespaceId()); retryLogMeta.setUniqueId(executeReqDto.getUniqueId()); - ThreadLocalLogUtil.initLogInfo(retryLogMeta, LogTypeEnum.RETRY); + EasyRetryLogManager.initLogInfo(retryLogMeta, LogTypeEnum.RETRY); RetryerResultContext retryerResultContext = retryStrategy.openRetry(executeReqDto.getScene(), executeReqDto.getExecutorName(), deSerialize); @@ -125,7 +125,7 @@ public class RetryEndPoint { } finally { RetrySiteSnapshot.removeAll(); - ThreadLocalLogUtil.removeAll(); + EasyRetryLogManager.removeAll(); } return new Result<>(executeRespDto); @@ -152,7 +152,7 @@ public class RetryEndPoint { retryLogMeta.setGroupName(callbackDTO.getGroup()); retryLogMeta.setNamespaceId(callbackDTO.getNamespaceId()); retryLogMeta.setUniqueId(callbackDTO.getUniqueId()); - ThreadLocalLogUtil.initLogInfo(retryLogMeta, LogTypeEnum.RETRY); + EasyRetryLogManager.initLogInfo(retryLogMeta, LogTypeEnum.RETRY); retryerInfo = RetryerInfoCache.get(callbackDTO.getScene(), callbackDTO.getExecutorName()); if (Objects.isNull(retryerInfo)) { @@ -174,7 +174,7 @@ public class RetryEndPoint { // 若不是SpringBean 则直接反射以普通类调用 return doCallbackForOrdinaryClass(callbackDTO, retryerInfo, deSerialize); } finally { - ThreadLocalLogUtil.removeAll(); + EasyRetryLogManager.removeAll(); } } diff --git a/easy-retry-client/easy-retry-client-core/src/main/java/com/aizuda/easy/retry/client/core/log/RetryLogMeta.java b/easy-retry-client/easy-retry-client-core/src/main/java/com/aizuda/easy/retry/client/core/log/RetryLogMeta.java index 6a82f4f47..401e5baab 100644 --- a/easy-retry-client/easy-retry-client-core/src/main/java/com/aizuda/easy/retry/client/core/log/RetryLogMeta.java +++ b/easy-retry-client/easy-retry-client-core/src/main/java/com/aizuda/easy/retry/client/core/log/RetryLogMeta.java @@ -1,6 +1,6 @@ package com.aizuda.easy.retry.client.core.log; -import com.aizuda.easy.retry.client.common.report.LogMeta; +import com.aizuda.easy.retry.client.common.log.report.LogMeta; import lombok.Data; import lombok.EqualsAndHashCode; diff --git a/easy-retry-client/easy-retry-client-core/src/main/java/com/aizuda/easy/retry/client/core/log/RetryLogReport.java b/easy-retry-client/easy-retry-client-core/src/main/java/com/aizuda/easy/retry/client/core/log/RetryLogReport.java index ad13a8b12..ca9031fff 100644 --- a/easy-retry-client/easy-retry-client-core/src/main/java/com/aizuda/easy/retry/client/core/log/RetryLogReport.java +++ b/easy-retry-client/easy-retry-client-core/src/main/java/com/aizuda/easy/retry/client/core/log/RetryLogReport.java @@ -1,7 +1,7 @@ package com.aizuda.easy.retry.client.core.log; -import com.aizuda.easy.retry.client.common.report.AbstractLogReport; -import com.aizuda.easy.retry.client.common.util.ThreadLocalLogUtil; +import com.aizuda.easy.retry.client.common.log.report.AbstractLogReport; +import com.aizuda.easy.retry.client.common.log.support.EasyRetryLogManager; import com.aizuda.easy.retry.common.log.dto.LogContentDTO; import com.aizuda.easy.retry.common.log.enums.LogTypeEnum; import com.aizuda.easy.retry.server.model.dto.RetryLogTaskDTO; @@ -16,7 +16,7 @@ import org.springframework.stereotype.Component; public class RetryLogReport extends AbstractLogReport { @Override protected RetryLogTaskDTO buildLogTaskDTO(LogContentDTO logContentDTO) { - RetryLogMeta context = (RetryLogMeta) ThreadLocalLogUtil.getContext(); + RetryLogMeta context = (RetryLogMeta) EasyRetryLogManager.getLogMeta(); RetryLogTaskDTO logTaskDTO = new RetryLogTaskDTO(); logTaskDTO.setLogType(LogTypeEnum.RETRY.name()); logTaskDTO.setUniqueId(context.getUniqueId()); @@ -29,6 +29,6 @@ public class RetryLogReport extends AbstractLogReport { @Override public boolean supports() { - return LogTypeEnum.RETRY == ThreadLocalLogUtil.getLogType(); + return LogTypeEnum.RETRY == EasyRetryLogManager.getLogType(); } } diff --git a/easy-retry-client/easy-retry-client-core/src/main/java/com/aizuda/easy/retry/client/core/report/AbstractReport.java b/easy-retry-client/easy-retry-client-core/src/main/java/com/aizuda/easy/retry/client/core/report/AbstractReport.java index d29521246..abf5acccf 100644 --- a/easy-retry-client/easy-retry-client-core/src/main/java/com/aizuda/easy/retry/client/core/report/AbstractReport.java +++ b/easy-retry-client/easy-retry-client-core/src/main/java/com/aizuda/easy/retry/client/core/report/AbstractReport.java @@ -1,7 +1,7 @@ package com.aizuda.easy.retry.client.core.report; import cn.hutool.core.lang.Assert; -import com.aizuda.easy.retry.client.common.Report; +import com.aizuda.easy.retry.client.core.Report; import com.aizuda.easy.retry.client.common.config.EasyRetryProperties; import com.aizuda.easy.retry.common.core.expression.ExpressionEngine; import com.aizuda.easy.retry.client.core.IdempotentIdGenerate; diff --git a/easy-retry-client/easy-retry-client-core/src/main/java/com/aizuda/easy/retry/client/core/strategy/AbstractRetryStrategies.java b/easy-retry-client/easy-retry-client-core/src/main/java/com/aizuda/easy/retry/client/core/strategy/AbstractRetryStrategies.java index d4361bab1..100848025 100644 --- a/easy-retry-client/easy-retry-client-core/src/main/java/com/aizuda/easy/retry/client/core/strategy/AbstractRetryStrategies.java +++ b/easy-retry-client/easy-retry-client-core/src/main/java/com/aizuda/easy/retry/client/core/strategy/AbstractRetryStrategies.java @@ -1,6 +1,6 @@ package com.aizuda.easy.retry.client.core.strategy; -import com.aizuda.easy.retry.client.common.Report; +import com.aizuda.easy.retry.client.core.Report; import com.aizuda.easy.retry.client.common.cache.GroupVersionCache; import com.aizuda.easy.retry.client.common.config.EasyRetryProperties; import com.aizuda.easy.retry.client.core.RetryExecutor; diff --git a/easy-retry-client/easy-retry-client-job-core/src/main/java/com/aizuda/easy/retry/client/job/core/client/JobEndPoint.java b/easy-retry-client/easy-retry-client-job-core/src/main/java/com/aizuda/easy/retry/client/job/core/client/JobEndPoint.java index 30f02b14e..24db79f44 100644 --- a/easy-retry-client/easy-retry-client-job-core/src/main/java/com/aizuda/easy/retry/client/job/core/client/JobEndPoint.java +++ b/easy-retry-client/easy-retry-client-job-core/src/main/java/com/aizuda/easy/retry/client/job/core/client/JobEndPoint.java @@ -1,6 +1,6 @@ package com.aizuda.easy.retry.client.job.core.client; -import com.aizuda.easy.retry.client.common.util.ThreadLocalLogUtil; +import com.aizuda.easy.retry.client.common.log.support.EasyRetryLogManager; import com.aizuda.easy.retry.client.job.core.IJobExecutor; import com.aizuda.easy.retry.client.job.core.cache.JobExecutorInfoCache; import com.aizuda.easy.retry.client.job.core.cache.ThreadPoolCache; @@ -71,7 +71,7 @@ public class JobEndPoint { EasyRetryLog.REMOTE.error("客户端发生非预期异常. taskBatchId:[{}]", dispatchJob.getTaskBatchId()); throw e; } finally { - ThreadLocalLogUtil.removeContext(); + EasyRetryLogManager.removeLogMeta(); } return new Result<>(Boolean.TRUE); @@ -84,7 +84,7 @@ public class JobEndPoint { logMeta.setGroupName(jobContext.getGroupName()); logMeta.setJobId(jobContext.getJobId()); logMeta.setTaskBatchId(jobContext.getTaskBatchId()); - ThreadLocalLogUtil.initLogInfo(logMeta, LogTypeEnum.JOB); + EasyRetryLogManager.initLogInfo(logMeta, LogTypeEnum.JOB); } diff --git a/easy-retry-client/easy-retry-client-job-core/src/main/java/com/aizuda/easy/retry/client/job/core/executor/AbstractJobExecutor.java b/easy-retry-client/easy-retry-client-job-core/src/main/java/com/aizuda/easy/retry/client/job/core/executor/AbstractJobExecutor.java index 78f9f8fb1..452b22606 100644 --- a/easy-retry-client/easy-retry-client-job-core/src/main/java/com/aizuda/easy/retry/client/job/core/executor/AbstractJobExecutor.java +++ b/easy-retry-client/easy-retry-client-job-core/src/main/java/com/aizuda/easy/retry/client/job/core/executor/AbstractJobExecutor.java @@ -1,6 +1,6 @@ package com.aizuda.easy.retry.client.job.core.executor; -import com.aizuda.easy.retry.client.common.util.ThreadLocalLogUtil; +import com.aizuda.easy.retry.client.common.log.support.EasyRetryLogManager; import com.aizuda.easy.retry.client.job.core.IJobExecutor; import com.aizuda.easy.retry.client.job.core.cache.FutureCache; import com.aizuda.easy.retry.client.job.core.cache.ThreadPoolCache; @@ -56,7 +56,7 @@ public abstract class AbstractJobExecutor implements IJobExecutor { initLogContext(jobContext); return doJobExecute(jobArgs); } finally { - ThreadLocalLogUtil.removeContext(); + EasyRetryLogManager.removeLogMeta(); } }); @@ -72,7 +72,7 @@ public abstract class AbstractJobExecutor implements IJobExecutor { logMeta.setGroupName(jobContext.getGroupName()); logMeta.setJobId(jobContext.getJobId()); logMeta.setTaskBatchId(jobContext.getTaskBatchId()); - ThreadLocalLogUtil.initLogInfo(logMeta, LogTypeEnum.JOB); + EasyRetryLogManager.initLogInfo(logMeta, LogTypeEnum.JOB); } private static JobArgs buildJobArgs(JobContext jobContext) { diff --git a/easy-retry-client/easy-retry-client-job-core/src/main/java/com/aizuda/easy/retry/client/job/core/executor/JobExecutorFutureCallback.java b/easy-retry-client/easy-retry-client-job-core/src/main/java/com/aizuda/easy/retry/client/job/core/executor/JobExecutorFutureCallback.java index 6c809a27c..1f4c1cbe1 100644 --- a/easy-retry-client/easy-retry-client-job-core/src/main/java/com/aizuda/easy/retry/client/job/core/executor/JobExecutorFutureCallback.java +++ b/easy-retry-client/easy-retry-client-job-core/src/main/java/com/aizuda/easy/retry/client/job/core/executor/JobExecutorFutureCallback.java @@ -1,7 +1,7 @@ package com.aizuda.easy.retry.client.job.core.executor; import com.aizuda.easy.retry.client.common.proxy.RequestBuilder; -import com.aizuda.easy.retry.client.common.util.ThreadLocalLogUtil; +import com.aizuda.easy.retry.client.common.log.support.EasyRetryLogManager; import com.aizuda.easy.retry.client.job.core.cache.ThreadPoolCache; import com.aizuda.easy.retry.client.job.core.client.JobNettyClient; import com.aizuda.easy.retry.client.job.core.log.JobLogMeta; @@ -65,7 +65,7 @@ public class JobExecutorFutureCallback implements FutureCallback } catch (Exception e) { EasyRetryLog.REMOTE.error("执行结果上报异常.[{}]", jobContext.getTaskId(), e); } finally { - ThreadLocalLogUtil.removeContext(); + EasyRetryLogManager.removeLogMeta(); stopThreadPool(); } } @@ -93,7 +93,7 @@ public class JobExecutorFutureCallback implements FutureCallback } catch (Exception e) { EasyRetryLog.REMOTE.error("执行结果上报异常.[{}]", jobContext.getTaskId(), e); } finally { - ThreadLocalLogUtil.removeContext(); + EasyRetryLogManager.removeLogMeta(); stopThreadPool(); } } @@ -105,7 +105,7 @@ public class JobExecutorFutureCallback implements FutureCallback logMeta.setGroupName(jobContext.getGroupName()); logMeta.setJobId(jobContext.getJobId()); logMeta.setTaskBatchId(jobContext.getTaskBatchId()); - ThreadLocalLogUtil.initLogInfo(logMeta, LogTypeEnum.JOB); + EasyRetryLogManager.initLogInfo(logMeta, LogTypeEnum.JOB); } private void stopThreadPool() { diff --git a/easy-retry-client/easy-retry-client-job-core/src/main/java/com/aizuda/easy/retry/client/job/core/log/JobLogMeta.java b/easy-retry-client/easy-retry-client-job-core/src/main/java/com/aizuda/easy/retry/client/job/core/log/JobLogMeta.java index 715fcb857..d9dc73595 100644 --- a/easy-retry-client/easy-retry-client-job-core/src/main/java/com/aizuda/easy/retry/client/job/core/log/JobLogMeta.java +++ b/easy-retry-client/easy-retry-client-job-core/src/main/java/com/aizuda/easy/retry/client/job/core/log/JobLogMeta.java @@ -1,6 +1,6 @@ package com.aizuda.easy.retry.client.job.core.log; -import com.aizuda.easy.retry.client.common.report.LogMeta; +import com.aizuda.easy.retry.client.common.log.report.LogMeta; import lombok.Data; import lombok.EqualsAndHashCode; diff --git a/easy-retry-client/easy-retry-client-job-core/src/main/java/com/aizuda/easy/retry/client/job/core/log/JobLogReport.java b/easy-retry-client/easy-retry-client-job-core/src/main/java/com/aizuda/easy/retry/client/job/core/log/JobLogReport.java index 22214c447..f6d827ae2 100644 --- a/easy-retry-client/easy-retry-client-job-core/src/main/java/com/aizuda/easy/retry/client/job/core/log/JobLogReport.java +++ b/easy-retry-client/easy-retry-client-job-core/src/main/java/com/aizuda/easy/retry/client/job/core/log/JobLogReport.java @@ -1,7 +1,7 @@ package com.aizuda.easy.retry.client.job.core.log; -import com.aizuda.easy.retry.client.common.report.AbstractLogReport; -import com.aizuda.easy.retry.client.common.util.ThreadLocalLogUtil; +import com.aizuda.easy.retry.client.common.log.report.AbstractLogReport; +import com.aizuda.easy.retry.client.common.log.support.EasyRetryLogManager; import com.aizuda.easy.retry.common.log.dto.LogContentDTO; import com.aizuda.easy.retry.common.log.enums.LogTypeEnum; import com.aizuda.easy.retry.server.model.dto.JobLogTaskDTO; @@ -17,12 +17,12 @@ public class JobLogReport extends AbstractLogReport { @Override public boolean supports () { - return LogTypeEnum.JOB == ThreadLocalLogUtil.getLogType(); + return LogTypeEnum.JOB == EasyRetryLogManager.getLogType(); } @Override protected JobLogTaskDTO buildLogTaskDTO(LogContentDTO logContentDTO) { - JobLogMeta context = (JobLogMeta) ThreadLocalLogUtil.getContext(); + JobLogMeta context = (JobLogMeta) EasyRetryLogManager.getLogMeta(); JobLogTaskDTO logTaskDTO = new JobLogTaskDTO(); logTaskDTO.setJobId(context.getJobId()); logTaskDTO.setLogType(LogTypeEnum.JOB.name());