代码优化

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

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