feat: shutdown graceful

dev
huangfeng 8 months ago
parent a1984a94b6
commit afc81c91f8

@ -71,6 +71,7 @@ public class IecServerService {
@PreDestroy @PreDestroy
private void stop() { private void stop() {
log.info("关闭IecServer服务.");
RealTimeDataService.iecServer = null; RealTimeDataService.iecServer = null;
iecServer.close(); iecServer.close();
} }

@ -83,11 +83,13 @@ public class RealTimeDataService {
IcdIed ied = optional.get(); IcdIed ied = optional.get();
ied.setStart(Constants.FALSE); ied.setStart(Constants.FALSE);
iedRepository.save(ied); iedRepository.save(ied);
log.info("61850停止订阅, ied=" + ied.getName() + ", ip=" + ied.getIp());
} }
} }
@PreDestroy @PreDestroy
private void stop() { private void stop() {
log.info("关闭61850订阅服务.");
Iterator<Integer> it = clientMap.keySet().iterator(); Iterator<Integer> it = clientMap.keySet().iterator();
while (it.hasNext()) { while (it.hasNext()) {
Integer key = it.next(); Integer key = it.next();

@ -15,6 +15,7 @@ import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import javax.annotation.PreDestroy;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.io.File; import java.io.File;
import java.util.Date; import java.util.Date;
@ -39,6 +40,13 @@ public class AmpliDownloadTask {
@Resource @Resource
WebSocketServer webSocketServer; WebSocketServer webSocketServer;
int shutdown = 0;
@PreDestroy
private void preDestroy() {
shutdown = 1;
}
@Scheduled(cron = "0 10 * * * ?") @Scheduled(cron = "0 10 * * * ?")
public void downloadAll() { public void downloadAll() {
List<RemoteConfig> configList = configService.listAll(); List<RemoteConfig> configList = configService.listAll();
@ -60,6 +68,9 @@ public class AmpliDownloadTask {
// 下载一个远端服务器 // 下载一个远端服务器
private void downloadServer(RemoteConfig config) throws Exception { private void downloadServer(RemoteConfig config) throws Exception {
if (shutdown == 1) {
return;
}
if (config.getActive() == null || config.getActive().intValue() == Constants.FALSE) { if (config.getActive() == null || config.getActive().intValue() == Constants.FALSE) {
return; return;
} }
@ -86,6 +97,9 @@ public class AmpliDownloadTask {
} }
private void downloadPath(String remotePath, RemoteConfig config, SFTPTool sftpTool) throws Exception { private void downloadPath(String remotePath, RemoteConfig config, SFTPTool sftpTool) throws Exception {
if (shutdown == 1) {
return;
}
String str = "abcd" + remotePath.replaceAll("/", "").replaceAll("\\\\", ""); String str = "abcd" + remotePath.replaceAll("/", "").replaceAll("\\\\", "");
str = str.substring(str.length() - 4); str = str.substring(str.length() - 4);
String localPath = folder + "/" + config.getIp() + "/" + str; String localPath = folder + "/" + config.getIp() + "/" + str;
@ -100,6 +114,9 @@ public class AmpliDownloadTask {
private void downloadFile(String remotePath, String filename, private void downloadFile(String remotePath, String filename,
String localPath, RemoteConfig config, SFTPTool sftpTool) throws Exception { String localPath, RemoteConfig config, SFTPTool sftpTool) throws Exception {
if (shutdown == 1) {
return;
}
if (StringUtils.isBlank(config.getSuffix()) || filename.toLowerCase().endsWith(config.getSuffix().toLowerCase())) { if (StringUtils.isBlank(config.getSuffix()) || filename.toLowerCase().endsWith(config.getSuffix().toLowerCase())) {
RemoteDownload item = new RemoteDownload(); RemoteDownload item = new RemoteDownload();
item.setConfigId(config.getId()); item.setConfigId(config.getId());

@ -9,6 +9,7 @@ import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import javax.annotation.PreDestroy;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar; import java.util.Calendar;
@ -33,6 +34,13 @@ public class Client61850Task {
@Resource @Resource
NSensorRepository sensorRepository; NSensorRepository sensorRepository;
int shutdown = 0;
@PreDestroy
private void preDestroy() {
shutdown = 1;
}
@Scheduled(cron = "0 * * * * ?") @Scheduled(cron = "0 * * * * ?")
public void collectAll() { public void collectAll() {
if (!enable) { if (!enable) {
@ -84,6 +92,9 @@ public class Client61850Task {
} }
private void collectIcdFile(IcdFile icdFile, List<Rptparamindex> rptList) { private void collectIcdFile(IcdFile icdFile, List<Rptparamindex> rptList) {
if (shutdown == 1) {
return;
}
List<IcdIed> iedList = iedRepository.findByIcdFileId(icdFile.getId()); List<IcdIed> iedList = iedRepository.findByIcdFileId(icdFile.getId());
if (!CollectionUtils.isEmpty(iedList)) { if (!CollectionUtils.isEmpty(iedList)) {
for (IcdIed ied : iedList) { for (IcdIed ied : iedList) {

@ -15,6 +15,7 @@ import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import javax.annotation.PreDestroy;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -38,6 +39,13 @@ public class I2syncTask {
@Resource @Resource
WebSocketServer webSocketServer; WebSocketServer webSocketServer;
int shutdown = 0;
@PreDestroy
private void preDestroy() {
shutdown = 1;
}
@Scheduled(initialDelay = 60 * 1000, fixedDelay = 30 * 60 * 1000) @Scheduled(initialDelay = 60 * 1000, fixedDelay = 30 * 60 * 1000)
public void syncAll() { public void syncAll() {
List<I2syncConfig> configList = i2syncService.listConfig(); List<I2syncConfig> configList = i2syncService.listConfig();
@ -63,7 +71,10 @@ public class I2syncTask {
// 同步一个类型 // 同步一个类型
private void syncOneConfig(I2syncConfig config) throws Exception { private void syncOneConfig(I2syncConfig config) throws Exception {
log.info("I2syncTask.syncOneConfig " + config.getTypeName()); if (shutdown == 1) {
return;
}
log.info("I2syncTask 同步一个类型 " + config.getTypeName());
List<I2syncField> fieldList = i2syncService.listFieldConfig(config.getTableName()); List<I2syncField> fieldList = i2syncService.listFieldConfig(config.getTableName());
if (CollectionUtils.isEmpty(fieldList)) { if (CollectionUtils.isEmpty(fieldList)) {
log.info("该类型未配置同步字段."); log.info("该类型未配置同步字段.");
@ -89,6 +100,9 @@ public class I2syncTask {
// 同步一个装置 // 同步一个装置
private void syncOneSensor(NSensor sensor, I2syncConfig config, private void syncOneSensor(NSensor sensor, I2syncConfig config,
List<I2syncField> fieldList, List<ModevTypePoint> points) throws Exception { List<I2syncField> fieldList, List<ModevTypePoint> points) throws Exception {
if (shutdown == 1) {
return;
}
I2syncRecord record; I2syncRecord record;
List<I2syncRecord> recordList = recordRepository.findByEqmid(sensor.getDevId()); List<I2syncRecord> recordList = recordRepository.findByEqmid(sensor.getDevId());
if (CollectionUtils.isEmpty(recordList)) { if (CollectionUtils.isEmpty(recordList)) {

@ -15,6 +15,7 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled; import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.PreDestroy;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.*; import java.util.*;
@ -32,6 +33,13 @@ public class RuleCheckTask {
@Resource @Resource
WebSocketServer webSocketServer; WebSocketServer webSocketServer;
int shutdown = 0;
@PreDestroy
private void preDestroy() {
shutdown = 1;
}
@Scheduled(initialDelay = 60 * 1000, fixedDelay = 3 * 60 * 1000) @Scheduled(initialDelay = 60 * 1000, fixedDelay = 3 * 60 * 1000)
private void checkAll() { private void checkAll() {
try { try {
@ -49,6 +57,9 @@ public class RuleCheckTask {
} }
private void ruleCheck(WarnRule rule) { private void ruleCheck(WarnRule rule) {
if (shutdown == 1) {
return;
}
try { try {
NSensor sensor = rule.getNSensor(); NSensor sensor = rule.getNSensor();
ModevTypePoint typePoint = rule.getTypePoint(); ModevTypePoint typePoint = rule.getTypePoint();
@ -68,6 +79,9 @@ public class RuleCheckTask {
} }
private void sendWarning(WarnRule rule, TriggerModel model) throws Exception { private void sendWarning(WarnRule rule, TriggerModel model) throws Exception {
if (shutdown == 1) {
return;
}
NSensor sensor = rule.getNSensor(); NSensor sensor = rule.getNSensor();
ModevTypePoint typePoint = rule.getTypePoint(); ModevTypePoint typePoint = rule.getTypePoint();
Warning warning = Warning.builder() Warning warning = Warning.builder()

@ -2,6 +2,7 @@ server:
port: 8099 port: 8099
servlet: servlet:
context-path: / context-path: /
shutdown: graceful
spring: spring:
jackson: jackson:

@ -2,6 +2,7 @@ server:
port: 8099 port: 8099
servlet: servlet:
context-path: / context-path: /
shutdown: graceful
spring: spring:
jackson: jackson:

Loading…
Cancel
Save