代码优化

master
lulicheng 8 months ago
parent 5a364202ea
commit 1f34057561

@ -5,10 +5,7 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.websocket.OnClose; import javax.websocket.*;
import javax.websocket.OnMessage;
import javax.websocket.OnOpen;
import javax.websocket.Session;
import javax.websocket.server.ServerEndpoint; import javax.websocket.server.ServerEndpoint;
import java.util.concurrent.CopyOnWriteArraySet; import java.util.concurrent.CopyOnWriteArraySet;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
@ -49,21 +46,26 @@ public class SimulationWebsocket {
//发送开始仿真的信息 //发送开始仿真的信息
String result = simulationService.getPlantData(message); String result = simulationService.getPlantData(message);
if ("Simulation Started".equals(result)) { if ("Simulation Started".equals(result)) {
if (!isSimulationRunning) {
isSimulationRunning = true; isSimulationRunning = true;
log.info("【仿真开始】"); log.info("【仿真开始】");
scheduler.scheduleAtFixedRate(() -> { scheduler.scheduleAtFixedRate(() -> {
try {
if (isSimulationRunning) { if (isSimulationRunning) {
String data = simulationService.getPlantData("SimulationProgress"); String data = simulationService.getPlantData("SimulationProgress");
// 根据需要处理和发送获取到的数据 // 根据需要处理和发送获取到的数据
log.info("【仿真数据】:" + data); log.info("【仿真数据】:" + data);
sendMessage(data); sendMessage(data);
if("1".equals(data) || "1.00".equals(data)){ if ("1".equals(data) || "1.00".equals(data)) {
sendMessage("ending"); sendMessage("ending");
isSimulationRunning = false; isSimulationRunning = false;
scheduler.shutdown();
} }
} }
} catch (Exception e) {
isSimulationRunning = false;
}
}, 0, 10, TimeUnit.SECONDS); }, 0, 10, TimeUnit.SECONDS);
}
} else { } else {
sendMessage("Simulation Start Failed"); sendMessage("Simulation Start Failed");
} }

@ -25,7 +25,3 @@ plant:
socket: socket:
ip: 127.0.0.1 ip: 127.0.0.1
port: 30000 port: 30000
mybatis-plus:
configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
Loading…
Cancel
Save