refactor(ft546): register shuttle runtimes from configuration
This commit is contained in:
@@ -12,6 +12,8 @@ import com.ruoyi.device.ssj.domain.DeviceSsj;
|
||||
import com.ruoyi.device.ssj.service.IDeviceSsjService;
|
||||
import com.ruoyi.device.tsj.domain.DeviceTsj;
|
||||
import com.ruoyi.device.tsj.service.IDeviceTsjService;
|
||||
import com.ruoyi.project.ft546.device.Ft546DeviceRuntimeRegistry;
|
||||
import com.ruoyi.project.ft546.device.shuttle.Ft546SrgvRuntimeFactory;
|
||||
import com.ruoyi.schedule.plcRead.cdz.PlcCdzRead;
|
||||
import com.ruoyi.schedule.plcRead.ddj.PlcDdjRead;
|
||||
import com.ruoyi.schedule.plcRead.srgv.PlcSrgvRead;
|
||||
@@ -30,6 +32,7 @@ import org.springframework.stereotype.Component;
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
@Component
|
||||
@@ -39,9 +42,9 @@ public class ScheduleThread {
|
||||
public CustomThread<PlcSsjRead> plcSsjReadCustomThread;
|
||||
public CustomThread<PlcTsjRead> plcTsjReadCustomThread;
|
||||
public CustomThread<PlcCdzRead> plcCdzReadCustomThread;
|
||||
public CustomThread<PlcSrgvRead> plcSrgvReadCustomThread1;
|
||||
public CustomThread<PlcSrgvRead> plcSrgvReadCustomThread2;
|
||||
public CustomThread<PlcSrgvRead> plcSrgvReadCustomThread3;
|
||||
public final Map<String, CustomThread<PlcSrgvRead>>
|
||||
plcSrgvReadCustomThreads =
|
||||
new ConcurrentHashMap<String, CustomThread<PlcSrgvRead>>();
|
||||
|
||||
|
||||
public CustomThread<MonitoringThread> monitoringCustomThread;
|
||||
@@ -58,6 +61,10 @@ public class ScheduleThread {
|
||||
private IDeviceTsjService deviceTsjService;
|
||||
@Autowired
|
||||
private IDeviceCdzService deviceCdzService;
|
||||
@Autowired
|
||||
private Ft546DeviceRuntimeRegistry deviceRuntimeRegistry;
|
||||
@Autowired
|
||||
private Ft546SrgvRuntimeFactory srgvRuntimeFactory;
|
||||
|
||||
private boolean isRun = false;
|
||||
private boolean isRun2 = false;
|
||||
@@ -128,25 +135,14 @@ public class ScheduleThread {
|
||||
ConcurrentHashMap<String, DeviceSrgv> srgvList = new ConcurrentHashMap<>();
|
||||
List<DeviceSrgv> srgvs=deviceSrgvService.selectDeviceSrgvList(new DeviceSrgv());
|
||||
for(DeviceSrgv srgv:srgvs){
|
||||
srgvList.put(srgv.getDeviceId().toString(),srgv);
|
||||
switch (srgv.getDeviceId()){
|
||||
case 1:
|
||||
PlcSrgvRead plcSrgvRead1=new PlcSrgvRead(srgv,new PlcConnectInfo(srgv.getIp(),srgv.getPort()));
|
||||
Thread plcSrgvReadThread1 = new Thread((plcSrgvRead1));
|
||||
plcSrgvReadCustomThread1=new CustomThread<PlcSrgvRead>(plcSrgvReadThread1,plcSrgvRead1);
|
||||
break;
|
||||
case 2:
|
||||
PlcSrgvRead plcSrgvRead2=new PlcSrgvRead(srgv,new PlcConnectInfo(srgv.getIp(),srgv.getPort()));
|
||||
Thread plcSrgvReadThread2 = new Thread((plcSrgvRead2));
|
||||
plcSrgvReadCustomThread2=new CustomThread<PlcSrgvRead>(plcSrgvReadThread2,plcSrgvRead2);
|
||||
break;
|
||||
case 3:
|
||||
PlcSrgvRead plcSrgvRead3=new PlcSrgvRead(srgv,new PlcConnectInfo(srgv.getIp(),srgv.getPort()));
|
||||
Thread plcSrgvReadThread3 = new Thread((plcSrgvRead3));
|
||||
plcSrgvReadCustomThread3=new CustomThread<PlcSrgvRead>(plcSrgvReadThread3,plcSrgvRead3);
|
||||
break;
|
||||
}
|
||||
|
||||
String deviceId = srgv.getDeviceId().toString();
|
||||
srgvList.put(deviceId,srgv);
|
||||
PlcSrgvRead plcSrgvRead = srgvRuntimeFactory.create(srgv);
|
||||
deviceRuntimeRegistry.register(deviceId, plcSrgvRead);
|
||||
Thread plcSrgvReadThread = new Thread(plcSrgvRead);
|
||||
plcSrgvReadCustomThreads.put(deviceId,
|
||||
new CustomThread<PlcSrgvRead>(plcSrgvReadThread,
|
||||
plcSrgvRead));
|
||||
}
|
||||
PlcSrgvRead.deviceSrgvMap=srgvList;
|
||||
|
||||
@@ -177,9 +173,10 @@ public class ScheduleThread {
|
||||
*/
|
||||
public void startAllThread() {
|
||||
plcSsjReadCustomThread.getThread().start();
|
||||
plcSrgvReadCustomThread1.getThread().start();
|
||||
plcSrgvReadCustomThread2.getThread().start();
|
||||
plcSrgvReadCustomThread3.getThread().start();
|
||||
for (CustomThread<PlcSrgvRead> reader
|
||||
: plcSrgvReadCustomThreads.values()) {
|
||||
reader.getThread().start();
|
||||
}
|
||||
plcTsjReadCustomThread.getThread().start();
|
||||
plcCdzReadCustomThread.getThread().start();
|
||||
|
||||
@@ -205,6 +202,12 @@ public class ScheduleThread {
|
||||
*/
|
||||
public void stopAllThread() {
|
||||
plcSsjReadCustomThread.runnable.isRun = false;
|
||||
for (CustomThread<PlcSrgvRead> reader
|
||||
: plcSrgvReadCustomThreads.values()) {
|
||||
reader.runnable.isRun = false;
|
||||
}
|
||||
plcSrgvReadCustomThreads.clear();
|
||||
deviceRuntimeRegistry.clear();
|
||||
// plcDdj1ReadCustomThread.runnable.isRun = false;
|
||||
/* plcDdj2ReadCustomThread.runnable.isRun = false;
|
||||
plcDdj3ReadCustomThread.runnable.isRun = false;
|
||||
|
||||
Reference in New Issue
Block a user