From 1da741e8519e13d8f92824bf8ef15b92800b70fc Mon Sep 17 00:00:00 2001
From: luxiaotao1123 <t1341870251@gmail.com>
Date: 星期六, 28 六月 2025 16:27:30 +0800
Subject: [PATCH] #
---
zy-acs-manager/src/main/java/com/zy/acs/manager/core/scheduler/KernelScheduler.java | 102 +++++++++++++++++++++++++++++++++++++++------------
1 files changed, 78 insertions(+), 24 deletions(-)
diff --git a/zy-acs-manager/src/main/java/com/zy/acs/manager/core/scheduler/KernelScheduler.java b/zy-acs-manager/src/main/java/com/zy/acs/manager/core/scheduler/KernelScheduler.java
index 1dfb30e..0bf08bd 100644
--- a/zy-acs-manager/src/main/java/com/zy/acs/manager/core/scheduler/KernelScheduler.java
+++ b/zy-acs-manager/src/main/java/com/zy/acs/manager/core/scheduler/KernelScheduler.java
@@ -2,24 +2,26 @@
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zy.acs.manager.core.domain.AgvTaskDto;
+import com.zy.acs.manager.core.service.MainLockWrapService;
import com.zy.acs.manager.core.service.MainService;
import com.zy.acs.manager.core.service.TrafficService;
import com.zy.acs.manager.manager.entity.Bus;
import com.zy.acs.manager.manager.entity.Segment;
import com.zy.acs.manager.manager.entity.Task;
+import com.zy.acs.manager.manager.enums.ActionStsType;
import com.zy.acs.manager.manager.enums.BusStsType;
import com.zy.acs.manager.manager.enums.SegmentStateType;
import com.zy.acs.manager.manager.enums.TaskStsType;
-import com.zy.acs.manager.manager.service.ActionService;
-import com.zy.acs.manager.manager.service.BusService;
-import com.zy.acs.manager.manager.service.SegmentService;
-import com.zy.acs.manager.manager.service.TaskService;
+import com.zy.acs.manager.manager.service.*;
import com.zy.acs.manager.system.service.ConfigService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.context.event.ApplicationReadyEvent;
+import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
+import javax.annotation.PreDestroy;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@@ -34,15 +36,26 @@
@Component
public class KernelScheduler {
+ public static int CORE_SCAN_FREQUENCY_MILLISECOND = 15;
+
private static final int LOCK_TIMEOUT = 5;
+
private final ReentrantLock lock = new ReentrantLock(Boolean.TRUE);
+ private Thread trafficCalcThread;
+
+ private Thread actionPublicThread;
+
+ @Autowired
+ private AgvService agvService;
@Autowired
private BusService busService;
@Autowired
private TaskService taskService;
@Autowired
private MainService mainService;
+ @Autowired
+ private MainLockWrapService mainLockWrapService;
@Autowired
private ActionService actionService;
@Autowired
@@ -51,19 +64,23 @@
private TrafficService trafficService;
@Autowired
private ConfigService configService;
+ @Autowired
+ private LocService locService;
+ @Autowired
+ private AgvModelService agvModelService;
- @Scheduled(cron = "0/3 * * * * ? ")
+ @Scheduled(cron = "0/1 * * * * ? ")
private void startupBus() throws InterruptedException {
- if (!configService.getVal("TaskAssignMode", Boolean.class)) { return; }
+// if (!configService.getVal("TaskAssignMode", Boolean.class)) { return; }
if (!this.lock.tryLock(LOCK_TIMEOUT, TimeUnit.SECONDS)) { return; }
- List<Bus> busList = busService.selectBySts(BusStsType.RECEIVE);
+ List<Bus> busList = busService.selectInSts(BusStsType.RECEIVE, BusStsType.PROGRESS);
for (Bus bus : busList) {
mainService.allocateTask(bus);
}
this.lock.unlock();
}
- @Scheduled(cron = "0/3 * * * * ? ")
+ @Scheduled(cron = "0/1 * * * * ? ")
private void calculateSeg() throws InterruptedException {
if (!this.lock.tryLock(LOCK_TIMEOUT, TimeUnit.SECONDS)) { return; }
List<Task> taskList = taskService.selectBySts(TaskStsType.WAITING);
@@ -81,28 +98,54 @@
}
for (AgvTaskDto dto : taskDtoList) {
- mainService.buildMajorTask(dto.getAgvId(), dto.getTaskList());
+ mainLockWrapService.buildMajorTask(dto.getAgvId(), dto.getTaskList());
}
this.lock.unlock();
}
- @Scheduled(cron = "0/1 * * * * ? ")
- private void traffic() {
- List<Segment> segments = segmentService.list(new LambdaQueryWrapper<Segment>()
- .eq(Segment::getState, SegmentStateType.WAITING.toString())
- );
- for (Segment segment : segments) {
- trafficService.trigger(segment);
- }
+ @EventListener(ApplicationReadyEvent.class)
+ public void init() {
+ try { Thread.sleep(1200); } catch (InterruptedException ignore) {}
+ // traffic calculate
+ this.trafficCalcThread = new Thread(() -> {
+ while (!Thread.currentThread().isInterrupted()) {
+ try {
+ Thread.sleep(CORE_SCAN_FREQUENCY_MILLISECOND);
+
+ List<Segment> segments = segmentService.list(new LambdaQueryWrapper<Segment>()
+ .eq(Segment::getState, SegmentStateType.WAITING.toString())
+ );
+ for (Segment segment : segments) {
+ long startTime = System.currentTimeMillis();
+ trafficService.trigger(segment);
+// log.info("traffic calculation spend {} ms", System.currentTimeMillis() - startTime);
+ }
+
+ } catch (Exception e) {
+ log.error("KernelScheduler.trafficCalcThread fail", e);
+ }
+ }
+ });
+ this.trafficCalcThread.start();
+ // public action
+ this.actionPublicThread = new Thread(() -> {
+ while (!Thread.currentThread().isInterrupted()) {
+ try {
+ Thread.sleep(CORE_SCAN_FREQUENCY_MILLISECOND);
+
+ List<String> actionGroupIds = actionService.selectGroupNo(ActionStsType.PREPARE);
+ for (String actionGroupId : actionGroupIds) {
+ mainService.publishAction(actionGroupId);
+ }
+
+ } catch (Exception e) {
+ log.error("KernelScheduler.actionPublicThread fail", e);
+ }
+ }
+ });
+ this.actionPublicThread.start();
}
- @Scheduled(cron = "0/1 * * * * ? ")
- private void publishAction(){
- List<String> actionGroupIds = actionService.selectPrepareGroup();
- for (String actionGroupId : actionGroupIds) {
- mainService.publishAction(actionGroupId);
- }
- }
// patch ----------------------------------------------------------------------------------------------
@@ -137,4 +180,15 @@
}
}
+
+ @PreDestroy
+ public void shutDown(){
+ if (this.trafficCalcThread != null) {
+ this.trafficCalcThread .interrupt();
+ }
+ if (this.actionPublicThread != null) {
+ this.actionPublicThread .interrupt();
+ }
+ }
+
}
--
Gitblit v1.9.1