feat: 3.2.0
1. 优化启动类,避免重复加载
This commit is contained in:
parent
1f1a60d836
commit
9465234369
@ -7,6 +7,7 @@ import com.aizuda.easy.retry.common.core.constant.SystemConstants;
|
||||
import com.aizuda.easy.retry.common.core.context.SpringContext;
|
||||
import com.aizuda.easy.retry.common.core.util.EasyRetryVersion;
|
||||
import com.aizuda.easy.retry.common.log.EasyRetryLog;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.slf4j.helpers.MessageFormatter;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
@ -22,19 +23,24 @@ import java.util.List;
|
||||
* @date : 2021-11-19 19:00
|
||||
*/
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class EasyRetryStartListener implements ApplicationRunner {
|
||||
|
||||
@Autowired
|
||||
private List<Lifecycle> lifecycleList;
|
||||
private final List<Lifecycle> lifecycleList;
|
||||
private volatile boolean isStarted = false;
|
||||
|
||||
@Override
|
||||
public void run(ApplicationArguments args) throws Exception {
|
||||
System.out.println(MessageFormatter.format(SystemConstants.LOGO, EasyRetryVersion.getVersion()).getMessage());
|
||||
if (isStarted) {
|
||||
EasyRetryLog.LOCAL.info("Easy-Retry client already started v{}", EasyRetryVersion.getVersion());
|
||||
return;
|
||||
}
|
||||
|
||||
System.out.println(MessageFormatter.format(SystemConstants.LOGO, EasyRetryVersion.getVersion()).getMessage());
|
||||
EasyRetryLog.LOCAL.info("Easy-Retry client is preparing to start... v{}", EasyRetryVersion.getVersion());
|
||||
SpringContext.CONTEXT.publishEvent(new EasyRetryStartingEvent());
|
||||
lifecycleList.forEach(Lifecycle::start);
|
||||
SpringContext.CONTEXT.publishEvent(new EasyRetryStartedEvent());
|
||||
isStarted = true;
|
||||
EasyRetryLog.LOCAL.info("Easy-Retry client started successfully v{}", EasyRetryVersion.getVersion());
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,54 @@
|
||||
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.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 org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @author xiaowoniu
|
||||
* @date 2024-03-20 22:56:53
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public abstract class AbstractLogReport implements Lifecycle, LogReport {
|
||||
@Autowired
|
||||
private EasyRetryProperties easyRetryProperties;
|
||||
private SlidingWindow<? super LogTaskDTO> slidingWindow;
|
||||
@Override
|
||||
public void report(LogContentDTO logContentDTO) {
|
||||
slidingWindow.add(buildLogTaskDTO(logContentDTO));
|
||||
}
|
||||
|
||||
protected abstract LogTaskDTO buildLogTaskDTO(LogContentDTO logContentDTO);
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
|
||||
EasyRetryProperties.LogSlidingWindowConfig logSlidingWindow = easyRetryProperties.getLogSlidingWindow();
|
||||
|
||||
slidingWindow = SlidingWindow
|
||||
.Builder
|
||||
.<LogTaskDTO>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");
|
||||
}
|
||||
}
|
@ -24,7 +24,7 @@ import java.util.Objects;
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class AsyncReportLog implements Lifecycle, Report {
|
||||
public class AsyncReportLog implements Lifecycle {
|
||||
|
||||
@Autowired
|
||||
private EasyRetryProperties easyRetryProperties;
|
||||
@ -85,14 +85,4 @@ public class AsyncReportLog implements Lifecycle, Report {
|
||||
logTaskDTO.setFieldList(logContentDTO.getFieldList());
|
||||
return logTaskDTO;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supports(boolean async) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean report(String scene, String targetClassName, Object[] args) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,13 @@
|
||||
package com.aizuda.easy.retry.client.common.report;
|
||||
|
||||
import com.aizuda.easy.retry.common.log.dto.LogContentDTO;
|
||||
|
||||
/**
|
||||
* @author xiaowoniu
|
||||
* @date 2024-03-20 22:56:53
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public interface LogReport {
|
||||
|
||||
void report(LogContentDTO logContentDTO);
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
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.common.core.model.JobContext;
|
||||
import com.aizuda.easy.retry.common.log.dto.LogContentDTO;
|
||||
import com.aizuda.easy.retry.server.model.dto.LogTaskDTO;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author xiaowoniu
|
||||
* @date 2024-03-20 23:25:24
|
||||
* @since 3.2.0
|
||||
*/
|
||||
//@Component
|
||||
public class RetryLogReport extends AbstractLogReport {
|
||||
@Override
|
||||
protected LogTaskDTO buildLogTaskDTO(LogContentDTO logContentDTO) {
|
||||
// JobContext 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;
|
||||
}
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
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.common.core.model.JobContext;
|
||||
import com.aizuda.easy.retry.common.log.dto.LogContentDTO;
|
||||
import com.aizuda.easy.retry.server.model.dto.LogTaskDTO;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author xiaowoniu
|
||||
* @date 2024-03-20 23:25:24
|
||||
* @since 3.2.0
|
||||
*/
|
||||
//@Component
|
||||
public class JobLogReport extends AbstractLogReport {
|
||||
@Override
|
||||
protected LogTaskDTO buildLogTaskDTO(LogContentDTO logContentDTO) {
|
||||
JobContext 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;
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
package com.aizuda.easy.retry.server.model.dto;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* @author xiaowoniu
|
||||
* @date 2024-03-20 23:08:26
|
||||
* @since 3.2.0
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
public class JobLogTaskDTO extends LogTaskDTO {
|
||||
|
||||
/**
|
||||
* 任务信息id
|
||||
*/
|
||||
private Long jobId;
|
||||
|
||||
/**
|
||||
* 任务实例id
|
||||
*/
|
||||
private Long taskBatchId;
|
||||
|
||||
/**
|
||||
* 调度任务id
|
||||
*/
|
||||
private Long taskId;
|
||||
}
|
@ -16,11 +16,6 @@ import java.util.List;
|
||||
@Data
|
||||
public class LogTaskDTO implements Serializable {
|
||||
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 命名空间
|
||||
*/
|
||||
@ -34,16 +29,19 @@ public class LogTaskDTO implements Serializable {
|
||||
/**
|
||||
* 任务信息id
|
||||
*/
|
||||
@Deprecated
|
||||
private Long jobId;
|
||||
|
||||
/**
|
||||
* 任务实例id
|
||||
*/
|
||||
@Deprecated
|
||||
private Long taskBatchId;
|
||||
|
||||
/**
|
||||
* 调度任务id
|
||||
*/
|
||||
@Deprecated
|
||||
private Long taskId;
|
||||
|
||||
/**
|
||||
|
@ -0,0 +1,15 @@
|
||||
package com.aizuda.easy.retry.server.model.dto;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* @author xiaowoniu
|
||||
* @date 2024-03-20 23:08:26
|
||||
* @since 3.2.0
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
public class RetryLogTaskDTO extends LogTaskDTO {
|
||||
|
||||
}
|
@ -27,7 +27,7 @@ public class EasyRetryServerApplication {
|
||||
return args -> {
|
||||
// 最长自旋10秒,保证nettyHttpServer启动完成
|
||||
int waitCount = 0;
|
||||
while (!nettyHttpServer.isStarted() || waitCount > 100) {
|
||||
while (!nettyHttpServer.isStarted() && waitCount < 100) {
|
||||
log.info("--------> easy-retry netty server is staring....");
|
||||
TimeUnit.MILLISECONDS.sleep(100);
|
||||
waitCount++;
|
||||
|
@ -4,6 +4,7 @@ import com.aizuda.easy.retry.common.core.constant.SystemConstants;
|
||||
import com.aizuda.easy.retry.common.log.EasyRetryLog;
|
||||
import com.aizuda.easy.retry.common.core.util.EasyRetryVersion;
|
||||
import com.aizuda.easy.retry.server.common.Lifecycle;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.slf4j.helpers.MessageFormatter;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -20,17 +21,23 @@ import java.util.List;
|
||||
* @date : 2021-11-19 19:00
|
||||
*/
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
public class StartListener implements ApplicationListener<ContextRefreshedEvent> {
|
||||
|
||||
@Autowired
|
||||
private List<Lifecycle> lifecycleList;
|
||||
private final List<Lifecycle> lifecycleList;
|
||||
private volatile boolean isStarted = false;
|
||||
|
||||
@Override
|
||||
public void onApplicationEvent(ContextRefreshedEvent event) {
|
||||
if (isStarted) {
|
||||
EasyRetryLog.LOCAL.info("Easy-Retry server already started v{}", EasyRetryVersion.getVersion());
|
||||
return;
|
||||
}
|
||||
|
||||
System.out.println(MessageFormatter.format(SystemConstants.LOGO, EasyRetryVersion.getVersion()).getMessage());
|
||||
EasyRetryLog.LOCAL.info("easy-retry-server v{} starting...", EasyRetryVersion.getVersion());
|
||||
EasyRetryLog.LOCAL.info("Easy-Retry server is preparing to start... v{}", EasyRetryVersion.getVersion());
|
||||
lifecycleList.forEach(Lifecycle::start);
|
||||
EasyRetryLog.LOCAL.info("easy-retry-server v{} start completed", EasyRetryVersion.getVersion());
|
||||
EasyRetryLog.LOCAL.info("Easy-Retry server started successfully v{}", EasyRetryVersion.getVersion());
|
||||
isStarted = true;
|
||||
}
|
||||
}
|
||||
|
@ -37,6 +37,11 @@ public class NettyHttpServer implements Runnable, Lifecycle {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
// 防止重复启动
|
||||
if (started) {
|
||||
return;
|
||||
}
|
||||
|
||||
EventLoopGroup bossGroup = new NioEventLoopGroup();
|
||||
EventLoopGroup workerGroup = new NioEventLoopGroup();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user